add and manipulate view in same event flow
Hi,
I´m bit stucked about the best practie to add views and
provide them width some data in same event flow.
Consider a StartGameEvent (with some gamedata as a payload) , which
should received by the contextviewMediator to
add a gameView on the stage and the mediator of the gameView
itselfs to provide the gameView with some data. But of course the
mediator cannot receive the event, when its just added in the same
"moment".
I see three options to handle this.
-
I can split this into 2 events for example:
AddGameToStageEvent and InitGameEvent with some gamedata.
When the gameView is added (after the AddGameToStageEvent) its mediator tells the application, that it is
added and the application fires an InitGameEvent with gamedata as payload. -
the gameView is already added on the stage from beginning and hided. GameViewMediator can receive events and can init gameView with gamedata.
-
the gamedata is placed in a model. When gameView is added to stage, its mediator is injected by this model and grabs the needed data.
Any better options? Or did I misunderstood some core concepts.
Thanks,
Martin
Comments are currently closed for this discussion. You can start a new one.
2 Posted by krasimir on 15 Oct, 2011 03:11 PM
Hello Martin,
what I'm usually do is point 3, except that I'm not injecting the model in my views. Normally I'm keeping my data into models and I'm injecting it in commands which are executed. So, once you have the data loaded you can dispatch an event, like for example ADD_GAME_VIEW. A command is mapped to this event. It adds the view to the stage and dispatch another event POPULATE_GAME_VIEW_WITH_DATA with needed data as payload. The mediator catches the populate event and pass the information to the view.
Of course that's only one of the possible solutions.
3 Posted by Martin on 15 Oct, 2011 03:51 PM
Hi krasimir,
thanks for your answer. Seems to be a good pratice.
Support Staff 4 Posted by Till Schneidereit on 16 Oct, 2011 11:24 AM
You might also want to take a look at Stray's relaxed event map, which
allows you to receive past events immediately after subscribing to
them:
https://github.com/Stray/robotlegs-utilities-RelaxedEventMap
Ondina D.F. closed this discussion on 01 Nov, 2011 04:06 PM.