tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/179-passing-events-between-contextsRobotlegs: Discussion 2018-10-18T16:35:18Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/31834202010-10-01T01:36:16Z2010-10-01T01:36:16Zpassing events between contexts?<div><p>hi,</p>
<p>i have a project called Wrapper that stages a Player and a Playlist. Player and Playlist are separate projects with their own contexts, etc.</p>
<p>i am looking for advice on how to let the Playlist send events that the Player captures. Eventually i was thinking about a PlayerControlService and a PlaylistControlService but for now just need to get the two projects to communicate.</p>
<p>I tried firing an event in one project and listening for it in the other but that didn't work (at least the first try :) So I'm assuming that each event bus is separate.</p>
<p>Is there a best practice for this sort of thing? I know I can use bubbling events to go up to the wrapper and back down to the desired target, but I'm trying to stick to one event bus where possible.</p>
<p>thanks,</p>
<p>gerry</p></div>Gerry Kohtag:robotlegs.tenderapp.com,2009-10-18:Comment/31834202010-10-01T19:12:20Z2010-10-01T19:12:20Zpassing events between contexts?<div><p>Hi Gerry,</p>
<p>One way is to leave the contexts as they are (with separate event buses), and pass in a third Event Dispatcher that they can talk through.</p>
<pre>
var sharedDispatcher:IEventDispatcher = new EventDispatcher();
player = new Player(sharedDispatcher);
playlist = new Playlist(sharedDispatcher);
</pre>
<p>You'd need to pass the shared event dispatcher through to each context and map it into each injector.</p>
<p>There are plenty other ways to do it - using a modular utility for example - but the approach above is probably the simplest for the job at hand.</p>
<p>Hope that helps!</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/31834202010-10-01T21:45:18Z2010-10-01T21:45:18Zpassing events between contexts?<div><p>Thanks Shaun! I will also have the opportunity to spend more time on this part soon, I would love any other suggestions that you might personally prefer.</p></div>Gerry Kohtag:robotlegs.tenderapp.com,2009-10-18:Comment/31834202010-10-03T10:58:29Z2010-10-03T10:58:29Zpassing events between contexts?<div><p>Check out the old version of robotlegs modular (on my fork at github.com/stray ) for the old-skool way of wiring contexts together - it will make obvious most of the 'gotcha' stuff.</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/31834202010-10-06T16:50:44Z2010-10-06T16:50:44Zpassing events between contexts?<div><p>thanks stray, i'll check it out now.</p></div>Gerry Kohtag:robotlegs.tenderapp.com,2009-10-18:Comment/31834202010-10-14T23:16:24Z2010-10-14T23:16:24Zpassing events between contexts?<div><p>shaun,</p>
<p>do you have any examples of mapping an additional context into an injector? i'm not sure of the syntax to do this.</p></div>Gerry Koh