Best way to access a parent Module from a Sub Module with Marionette
I have a Marionette Module with several Sub Modules. The parent Module has
its own event aggregator that I would like to use in the sub modules to
trigger events. I know that I could use the Application's event
aggregator, but these events are specific to the Parent Module and its
Children, and not the whole Application.
I could namespace the events in the Application's event aggregator like so:
App.module("Parent.Child", function(self, App, ...) {
// somewhere in the child
App.vent.trigger("Parent:something");
});
But I'd really rather not go that route. I think the idea of having a
single event aggregator for Parent Module and its children is cleaner. I
like having a single interface from the Parent to the Application, and the
Child to the Parent ... but perhaps I'm wrong in this thinking?
I could also get to the Parent Module's event aggregator from the App
object like so:
App.module("Parent.Child", function(self, App, ...) {
// somewhere in the child...
App.Parent.vent.trigger("something");
});
But I'd rather not do that either. I think that would couple the Child
module and the App too tightly.
Any other idea's or options? Maybe these are good ideas, and I just don't
understand the benefits.
No comments:
Post a Comment