How to know when mediators of remapped views are all initialized?

JeffW.'s Avatar

JeffW.

24 Jul, 2013 09:03 AM

hi,

In a command I am re-mapping views to different mediators, something like this:

mediatorMap.map( IntroView).toMediator(IntroViewMediator );
mediatorMap.map( RewardView).toMediator(RewardViewMediator );
mediatorMap.map( GameOverView).toMediator(GameOverViewMediator );
If I would do this in my config class then I can call after that
context.afterInitializing(init);
and I know that then the mediators are initialized, right?

But is there a way to find out when ALL the mediators the views have been remapped to are initialized when remapping in a command later on in your application?
I don't like the idea of keeping track of each initialization per mediator and build some 'counting' system.
Maybe RL has something built in that can help me?

thanks,
Jeff

  1. Support Staff 1 Posted by creynders on 24 Jul, 2013 09:58 AM

    creynders's Avatar

    Why exactly do you want to keep track of their initialization?
    I assume you have a bunch of views on the stage, their mediators are
    unmapped and remapped and now you want to proceed to some next phase, but
    only after all of the mediators have been initialized?
    I'm not completely familiar with the entire mediator mechanism in RL2, but
    I'd think they are immediately (i.e. synchronously) instantiated and
    initialized.
    If not, I'd let all relevant mediators dispatch an event upon
    initialization, create a helper class which listens to those events and
    maintains a list of events it's interested in, once the list is empty let
    it dispatch an event which triggers the next phase.

  2. 2 Posted by JeffW. on 24 Jul, 2013 10:03 AM

    JeffW.'s Avatar

    It doesn't seem like initialization of mediators works synchronously.
    When I call a function after the remapping calls, this function gets called before all mediators are initialized. I wanted to stay away from that helper class you mention, so that's why I asked. But I guess I should do smt like that, thanks.

  3. Support Staff 3 Posted by creynders on 24 Jul, 2013 10:08 AM

    creynders's Avatar

    Yeah, it could be the system waits a tick before initialization. I know there's a bunch of magic needed to avoid destruction and reinitialization of mediators in case a view is reparented.

  4. Support Staff 4 Posted by creynders on 24 Jul, 2013 10:08 AM

    creynders's Avatar

    Maybe another solution altogether would be better; why exactly do you want to remap the views?

  5. 5 Posted by JeffW. on 24 Jul, 2013 10:13 AM

    JeffW.'s Avatar

    I'm working with two contexts and both need to be able to fulfill two roles (master and slave). If a context switches from role, I want to switch from mediator too (master or slave mediator). I could stick to one mediator and check in there which role it should have but I don't like the idea of code cluttered with if statements.

  6. 6 Posted by JeffW. on 25 Jul, 2013 05:21 PM

    JeffW.'s Avatar

    I switched to one mediator that can have two roles, because the remapping brought a lot of problems, but at least now it all works, thanks, gonna close this one!

  7. JeffW. closed this discussion on 25 Jul, 2013 05:21 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