tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/696-add-and-manipulate-view-in-same-event-flowRobotlegs: Discussion 2013-04-28T10:18:57Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/106407912011-10-15T14:06:04Z2011-10-15T14:06:04Zadd and manipulate view in same event flow<div><p>Hi,<br>
I´m bit stucked about the best practie to add views and
provide them width some data in same event flow.<br>
Consider a StartGameEvent (with some gamedata as a payload) , which
should received by the contextviewMediator to<br>
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".</p>
<p>I see three options to handle this.</p>
<ol>
<li>
<p>I can split this into 2 events for example:<br>
AddGameToStageEvent and InitGameEvent with some gamedata.<br>
When the gameView is added (after the AddGameToStageEvent) its
mediator tells the application, that it is<br>
added and the application fires an InitGameEvent with gamedata as
payload.</p>
</li>
<li>
<p>the gameView is already added on the stage from beginning and
hided. GameViewMediator can receive events and can init gameView
with gamedata.</p>
</li>
<li>
<p>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.</p>
</li>
</ol>
<p>Any better options? Or did I misunderstood some core
concepts.</p>
<p>Thanks,</p>
<p>Martin</p></div>Martintag:robotlegs.tenderapp.com,2009-10-18:Comment/106407912011-10-15T15:11:41Z2011-10-15T15:11:41Zadd and manipulate view in same event flow<div><p>Hello Martin,</p>
<p>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.<br>
Of course that's only one of the possible solutions.</p></div>krasimirtag:robotlegs.tenderapp.com,2009-10-18:Comment/106407912011-10-15T15:51:11Z2011-10-15T15:51:12Zadd and manipulate view in same event flow<div><p>Hi krasimir,<br>
thanks for your answer. Seems to be a good pratice.</p></div>Martintag:robotlegs.tenderapp.com,2009-10-18:Comment/106407912011-10-16T11:24:51Z2011-10-16T11:24:51Zadd and manipulate view in same event flow<div><p>You might also want to take a look at Stray's relaxed event map,
which<br>
allows you to receive past events immediately after subscribing
to<br>
them:<br>
<a href=
"https://github.com/Stray/robotlegs-utilities-RelaxedEventMap">https://github.com/Stray/robotlegs-utilities-RelaxedEventMap</a></p></div>Till Schneidereit