Child view mediator isn't registered in time for certain things

kamcknig's Avatar

kamcknig

09 Dec, 2011 05:15 PM

Hi Everyone,

I have ViewA with a mediator ViewAMediator.

ViewA has two child views, ChildA, ChildB. Only the second child has a mediator, ChildBMediator.

When ViewAMediator is registered, I want ChildA to render data, so in ViewAMediator I tell ChildA to render some data, the problem is that when ChildA renders this data I want it to "auto select" one of the pieces of data, and then ChildB needs to update when that happens. But the problem is that ChildBMediator is registered AFTER ChildA has the data rendered and auto selects the first item the first time, therefore my ChildBMediator can't pick up the update and display properly. So how can I get ChildB's mediator to register soon enough? I thought at first that mediators were registered in reverse order, meaning child mediators were registered and then it goes up the chain to parents and registers them and such. But I guess not.

Sorry if that's Confusing. I can put up some pseudo code if it's not clear.

  1. 1 Posted by kamcknig on 09 Dec, 2011 05:27 PM

    kamcknig's Avatar

    So I gues basically my questions is what is a best practice for making sure all child view mediators of a parent view are registered before I do anything that affects all child views?

  2. 2 Posted by Stray on 09 Dec, 2011 05:33 PM

    Stray's Avatar

    If you map your views so that you map the deepest nested first, and the closest to the surface last (when you do mediatorMap.mapView...) you should be fine.

    Stray

  3. Support Staff 3 Posted by Ondina D.F. on 09 Dec, 2011 05:34 PM

    Ondina D.F.'s Avatar

    Hi!

    One solution would be to let ChildBMediator dispatch an event in its onRegister(). ViewAMediator would register a listener for it and let ChildA render the data in the event’s handler method.

    Or have a look at RelaxedEventMap. I'll provide the link.

    Ondina

  4. 4 Posted by kamcknig on 09 Dec, 2011 05:43 PM

    kamcknig's Avatar

    Stray, that didn't work, the parent mediator is still registered first. One thing if it matters, childB is actually an ancestor of the parent. so it's actually like what is displayed below. Where ChildC is actually the one being mediated that isn't catching the events. I just simplified it.

    So in this example, ViewA, and ChildC have mediators. So in ViewA's mediator's onRegister() I tell ChildA to update, child a updates and diispatches an event that I want ChildC's mediator to catch. But ChildC's mediator hasn't been registered yet. I have put ChildC's mediatorMap entry first in the list.

    ViewA
        -ChildA
        -ChildB
            -ChildC
    
  5. 5 Posted by kamcknig on 09 Dec, 2011 05:45 PM

    kamcknig's Avatar

    Ondina,

    I have heard of the RelaxedEventMap, but not used it, I did not see a link in your post though.

    Kyle

  6. 6 Posted by kamcknig on 09 Dec, 2011 06:03 PM

    kamcknig's Avatar

    Ondina,

    The RelaxedEventMap solution worked, thank you!

    Stray, is there anything else I might be missing? I'd rather fix it without having to... I dunno if using the relaxed map is "cheating", but if it can be done without extras then I'd like to.

  7. 7 Posted by Stray on 09 Dec, 2011 06:08 PM

    Stray's Avatar

    If you really do have a race condition then that's what I built the RelaxedEventMap for :)

  8. 8 Posted by kamcknig on 09 Dec, 2011 06:08 PM

    kamcknig's Avatar

    Then that's what I'll stick with :) Thanks!

  9. kamcknig closed this discussion on 09 Dec, 2011 06:08 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