tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/2724-dispatched-event-from-command-but-what-tricks-do-i-need-to-think-ofRobotlegs: Discussion 2013-09-23T14:40:48Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/289258232013-09-20T12:37:07Z2013-09-20T12:37:43ZDispatched event from command, but what tricks do I need to think of?<div><p>Hi, I'm trying to dispatch an event from a Command, which is
listened to by a (stable and already existing) mediator. The thing
is, the mediator never receives it.</p>
<p>I looked at <a href=
"http://knowledge.robotlegs.org/discussions/questions/616-dispatch-an-event-from-a-command">
http://knowledge.robotlegs.org/discussions/questions/616-dispatch-a...</a>
, but it seems I have a bit of magic lines missing to enable it or
something? In the command I do this:</p>
<p><code>eventDispatcher.dispatchEvent( ... );</code></p>
<p>In the mediator (onRegister) I do this:</p>
<p><code>eventMap.mapListener( eventDispatcher, ..., doStuff
);</code></p>
<p>But I can't seem to get doStuff to fire?</p>
<p>Any ideas? Tnx, Ben</p></div>bentag:robotlegs.tenderapp.com,2009-10-18:Comment/289258232013-09-20T14:25:46Z2013-09-20T14:25:46ZDispatched event from command, but what tricks do I need to think of?<div><p>Hi Ben,</p>
<p>I think of race conditions, i.e. the command dispatches the
event before the mediator is able to listen to it.</p>
<p>But you say that the mediator is already existing.<br>
So, the question is from where are you triggering the command and
when.</p>
<p>If you're dispatching the event triggering the command from
within mediator's onRegister, then you have to make sure you've
already added a listener for the event dispatched by the
command.</p>
<ol>
<li>add event listener<br></li>
<li>dispatch event to trigger the command<br></li>
<li>dispatch event from command<br></li>
<li>mediator can react to it</li>
</ol>
<p>If that's not the case, I'd need a little more info in order to
help you:)</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/289258232013-09-20T14:43:07Z2013-09-20T14:43:07ZDispatched event from command, but what tricks do I need to think of?<div><p>Tnx Ondina, let me try to provide whatever I can.</p>
<ol>
<li>
<p>After startup, the app is in stable (idle) condition. The
mediator is then alive and through onRegister I make it listen for
the RL event.</p>
</li>
<li>
<p>At a certain moment, the user clicks, which will trigger an
asynchronous Command. Not very relevant, but just in case.</p>
</li>
<li>
<p>After that command is done, a series of events are triggered
which fire off other Commands. So command A is executed, which
fires an event which will execute Command B, etc..</p>
</li>
<li>
<p>The event the mediator is listening to, is event B in the
sequence above.</p>
</li>
<li>
<p>The command that is attached to that same event, fires fine.</p>
</li>
<li>
<p>Other RL events the mediator is attached to, seem to work fine
as well.</p>
</li>
</ol>
<p>Cheers, Ben</p></div>bentag:robotlegs.tenderapp.com,2009-10-18:Comment/289258232013-09-20T14:49:09Z2013-09-20T14:49:59ZDispatched event from command, but what tricks do I need to think of?<div><p>Argh, just after typing this and trying some random ordering of
events, it seems I can get it working if I fire this one
first....</p>
<p>This goes wrong:<br></p>
<pre>
<code>override public function execute():void
{
super.execute();
dispatch( "a random other event");
dispatch( "the event I need" );
}</code>
</pre>
<p>This works:<br></p>
<pre>
<code>override public function execute():void
{
super.execute();
dispatch( "the event I need" );
dispatch( "a random other event");
}</code>
</pre></div>bentag:robotlegs.tenderapp.com,2009-10-18:Comment/289258232013-09-20T15:21:18Z2013-09-20T15:21:18ZDispatched event from command, but what tricks do I need to think of?<div><p>Glad you figured it out.</p>
<p>You might want to take a look at this utility:</p>
<p>Macro command utility for Robotlegs which provides the ability
to execute batches of commands in sequential and/or parallel
fashion</p>
<p><a href=
"http://aaronhardy.com/flex/macrobot-macro-commands-for-robotlegs/">
http://aaronhardy.com/flex/macrobot-macro-commands-for-robotlegs/</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/289258232013-09-20T21:25:12Z2013-09-20T21:25:12ZDispatched event from command, but what tricks do I need to think of?<div><p>Jup, I am using that one. Great stuff. I'm mostly using it for
the Async part. The Sequence part looks great, but doesn't add much
value for me in this case (not sure in which case it will, only if
you need to have an atomic execution of multiple events). But I
should read into it more in the future.</p>
<p>Thanks for your time/help.</p>
<p>Ben</p>
<p>On 20 sep. 2013, at 17:21, Ondina D.F. <a href=
"mailto:tender+db24ef9e75cd8f462c8e12818737f2be29485c5dd@tenderapp.com">
tender+db24ef9e75cd8f462c8e12818737f2be29485c5dd@tenderapp.com</a>
wrote:</p></div>bentag:robotlegs.tenderapp.com,2009-10-18:Comment/289258232013-09-21T12:56:48Z2013-09-21T12:56:48ZDispatched event from command, but what tricks do I need to think of?<div><p>No problem, Ben:)</p></div>Ondina D.F.