[question] communication between submodules
gaydenko opened this issue · comments
It seems submodules with different parents can not communicate via events as far as they have different (sub)cores and, as a result, different mediators, where last ones has own events space. Is it true?
If it is true, how to communicate between submodules belonging to different parents?
It seems submodules with different parents can not communicate via events as far as they have different (sub)cores
and, as a result, different mediators, where last ones has own events space. Is it true?
correct!
If it is true, how to communicate between submodules belonging to different parents?
you could manually re-emmit the events like that:
parentASandbox.sub.on("event", function(ev){
parentASandbox.emit("event", ev);
});
parentBSandbox.on("event", function(ev){
parentBSandbox.sub.emit("event", ev);
});
Obviously this is not a clean way. Therefore I just pushed a pipe
branch that contains a new mediator method to pipe events. Then we can could rewrite our code like this:
parentASandbox.sub.on("event").pipe(parentASandbox);
parentBSandbox.on("event").pipe(parentBSandbox.sub);
But this might be still a bit ugly. So we could add an option to the submodule plugin that does all the work for us.
Maybe like this:
core.use(scaleApp.plugins.submodule, {
inherit: true, // use all plugins from the parent's Core
pipeEvents: true //
});
What do you think? Do you have an other idea? What would be the cleanest way?
To tell the truth, I don't know that list of objections against having the only all over the world mediator :) Sandboxes still can track subscriptions of own module to clear them on destroy.
I'm playing with very simple (in terms of scaleApp, with single core and single mediator, while default sandboxes can manage children) prototype to dig in all these advantages and drawbacks.
Not a bug, closing.
Not a bug, closing.
no, its not a bug but a feature request. I'm thinking about to provide a plugin option mediator
:
core.use(scaleApp.plugins.submodule, {
mediator: myMediatorObject // or e.g. core._mediator
});
What do you think?
...or maybe just useGlobalMediator: true
?
I guess the last is simpler :)
@gaydenko both options are available now in the master branch. Have fun!