feat: use PubSub Service singleton to subscribe to any SlickEvent #1248
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
defaultComponentEventPrefix
,defaultSlickgridEventPrefix
grid options since they will not be used anymoreWith this PR, we merged the
SlickEvent
with our own PubSub Service (which uses aCustomEvent
), this makes it easier to maintain and requires less monkey patch code. The reason we use our own PubSub is because it makes it easier to communicate with Component based frameworks (used in Angular-Slickgrid, Slickgrid-React, ...). Note that this only applies to SlickGrid/DataView events since all other extensions (plugins/controls) were already using the PubSub through grid options or extension configurations. Note that you can still use SlickGrid.subscribe
on SlickEvent but please remember to.unsubscribe
each of them if you use that approach (which is not needed with a PubSub since you only have to do that once at a global level).Also note that our PubSub Service is a JS
CustomEvent
based, so all the data is only available through the.eventDetail
property of a CustomEvent. We use our PubSub to publish all events in the project, however the SlickGrid/DataView are the only events following this structure{ eventData: SlickEventData; args: any; }
, while all other extensions also publish events but the arguments are directly in the root (args
).What was the monkey patch anyway? The previous patch required to loop through all SlickGrid/DataView events (
SlickEvent
), we were then subscribing to each of them and whenever they were dispatching an event (through SlickEvent notify), we were then using our own PubSub Service to publish the event (similar to a middleware would do). As you can see, that was quite a monkey patch, the new approach simply adds an optional PubSub Service reference to the SlickEvent, allowing us to publish right away without the monkey patch or middleware.