So I have this issue with my lib Aurelia-Slickgrid which is a Custom Element and I use the Event Aggregator in a few areas of the plugin but then I had some issues where certain actions were reflected in all elements created.
To give a concrete example of my issues, I create 2 or 3 grids (that is my custom element lib) and in the plugin I have some events which basically say something like when you get a filter cleared event then do other things in the grid and some of these actions were reflected in all my grids. At first I thought I had issues with DI and Services not being transient, I didn’t even think about the Event Aggregator, then after 2 days I found that the problem originate fromr the Event Aggregator being shared in the entire app. I tried setting the Event Aggregator as Transient with
aurelia.container.registerTransient(EventAggregator); but that has no effect.
I saw this Event Aggregator doc which says
If you include the
aurelia-event-aggregatorplugin using “basicConfiguration” or “standardConfiguration” then the singleton EventAggregator’s API will be also present on the
Aureliaobject. You can also create additional instances of the EventAggregator, if needed, and “merge” them into any object.
It basically mentions about the Singleton, but doesn’t seem to say what to do for my use case (I want transient Event Aggregator in the Custom Element so that the events are only valid within each separator element).
I found this other discourse post
ea.publish(SessionCreatedEvent.Channel, new SessionCreatedEvent(params))
You don’t need the enum. If you pass an object, the constructor will be used as the key. Same result.
is that what I’m suppose to do to get a transient EA in each component? The doc isn’t clear about such use case.