0
votes

I'm working on a project with Marionette and RequireJS, and am slightly confused on one point, for which I haven't been able to find an answer. I understand from the Marionette wiki that it is desirable to create a global event aggregator in its own module, and list it as a dependency of any modules that need to use it.

My question is whether or not modules that need to listen to events raised by a given module also need to be listed as dependencies. For example, if ModuleA triggers an event that I need ModuleB to listen to, does ModuleA need to require ModuleB as a dependency? To do so seems undesirable, since the event publisher shouldn't need to be aware the various subscribers, but I realize it may be a pitfall of using AMD rather than Marionette's module system.

Any clarification would be most appreciated.

1

1 Answers

0
votes

You can create main event aggregation in App. Something like

App.channel = _.extend({}, Bacbone.Events);

All modules has referense to App, and can use this channel.

in moduleA

App.channel.trigger("someEvent", data);

in moduleB

App.channel.on("someEvent", function(data){ ... })