add and manipulate view in same event flow

Martin's Avatar

Martin

15 Oct, 2011 02:06 PM

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.

  1. 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.

  2. the gameView is already added on the stage from beginning and hided. GameViewMediator can receive events and can init gameView with gamedata.

  3. 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

  1. 1 Posted by krasimir on 15 Oct, 2011 03:11 PM

    krasimir's Avatar

    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.

  2. 2 Posted by Martin on 15 Oct, 2011 03:51 PM

    Martin's Avatar

    Hi krasimir,
    thanks for your answer. Seems to be a good pratice.

  3. Support Staff 3 Posted by Till Schneidere... on 16 Oct, 2011 11:24 AM

    Till Schneidereit's Avatar

    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

  4. Ondina D.F. closed this discussion on 01 Nov, 2011 04:06 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac