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.
I looked at http://knowledge.robotlegs.org/discussions/questions/616-dispatch-a... , but it seems I have a bit of magic lines missing to enable it or something? In the command I do this:
eventDispatcher.dispatchEvent( ... );
In the mediator (onRegister) I do this:
eventMap.mapListener( eventDispatcher, ..., doStuff
);
But I can't seem to get doStuff to fire?
Any ideas? Tnx, Ben
#1 Posted by Ondina D.F. Support staff on 20 Sep, 2013 02:25 PM
Hi Ben,
I think of race conditions, i.e. the command dispatches the event before the mediator is able to listen to it.
But you say that the mediator is already existing.
So, the question is from where are you triggering the command and when.
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.
If that's not the case, I'd need a little more info in order to help you:)
Ondina
#2 Posted by ben on 20 Sep, 2013 02:43 PM
Tnx Ondina, let me try to provide whatever I can.
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.
At a certain moment, the user clicks, which will trigger an asynchronous Command. Not very relevant, but just in case.
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..
The event the mediator is listening to, is event B in the sequence above.
The command that is attached to that same event, fires fine.
Other RL events the mediator is attached to, seem to work fine as well.
Cheers, Ben
#3 Posted by ben on 20 Sep, 2013 02:49 PM
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....
This goes wrong:
This works:
#4 Posted by Ondina D.F. Support staff on 20 Sep, 2013 03:21 PM
Glad you figured it out.
You might want to take a look at this utility:
Macro command utility for Robotlegs which provides the ability to execute batches of commands in sequential and/or parallel fashion
http://aaronhardy.com/flex/macrobot-macro-commands-for-robotlegs/
#5 Posted by ben on 20 Sep, 2013 09:25 PM
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.
Thanks for your time/help.
Ben
On 20 sep. 2013, at 17:21, Ondina D.F. <[email blocked]> wrote:
#6 Posted by Ondina D.F. Support staff on 21 Sep, 2013 12:56 PM
No problem, Ben:)
Ondina D.F. closed this discussion on 21 Sep, 2013 12:56 PM.