So basically I was trying to do something really basic in RobotLegs and got stuck.
Wanted to dispatch an event from a view and listen to it in the mapped mediator.
The problem was that I was dispatching the event from the view before it actually got added
to the stage ie. Before the view dispatched the ADDED_TO_STAGE event.
The mediator wouldn’t catch any event because it was dispatched before the ADDED_TO_STAGE
for the view, which I think is when the onRegister() for the mediator gets executed.
Finally got it fixed. The solution was simple – Added a listener to the mediator for the ADDED_TO_STAGE event of the mediated view
and called a public function view.init(); from the handler. Dispatched the desired event from the view.init() function.
So the things to keep in mind are :
– Add mediators to views before adding the view to the context.
– Before dispatching an event from the view, make sure the view has dispatched the ADDED_TO_STAGE event.
– Listen to the ADDED_TO_STAGE event in the mediator and call an init() function on the view.
PS: This post was written essentially so that I don’t land in the same situation again 🙂