OnRegister for mediator too late

Bert Deterd's Avatar

Bert Deterd

17 Feb, 2011 05:11 PM

Hello,

I have the following problem with Robotlegs.

I have a searchView. When I click on a button a Resultview is shown but the data in the datagrid is not shown. However the command has succesfully run and the data for the datagrid is available in the model.

The event is thrown in the command but AFTER the event has been thrown the Resultview method OnRegister is called.
So I can see why the data in the datagrid is not updated because for some reason the mediator is too late instantied.

How can I do the onregister earlier? is createmediator an option? How to use?

Well, I hope I am making some sense here.
Any help will be greatly appreciated.

Regards,
Bert

  1. Support Staff 1 Posted by Till Schneidere... on 17 Feb, 2011 05:29 PM

    Till Schneidereit's Avatar

    Hi Bert,

    onRegister is, in fact, invoked one frame after the mediator, and the
    view it mediates, is created when dealing with Flex components. This
    is done on purpose to allow for full initialization of the component.

    In your case, you could either override the MediatorBase's
    `preRegister' method (but don't forget to call `super()` if you do),
    or you could simply fetch the data in the onRegister method. It seems
    to me like it's a safe assumption that once you're showing the
    Resultsview, there are some results in the model to actually show, so
    querying for them might be an option. This, in turn, can be done
    either by dispatching a data-request event, as Stray would recommend
    with good arguments, or by injecting the model into the mediator. The
    latter causes much tighter coupling between the view and the logic
    layers of your app, so be careful with that.

    cheers,
    till

  2. 2 Posted by Stray on 17 Feb, 2011 06:41 PM

    Stray's Avatar

    Hi Bert,

    there's also a utility - the RelaxedEventMap - which is on github, which allows for 'time shifting' events - so if the event has fired in the past, the handler you're registering in onRegister will immediately be run with most recent instance of that event - it's as if your onRegister was there in time, even if it was actually a bit late.

    Code is on github here:

    https://github.com/Stray/robotlegs-utilities-RelaxedEventMap

    It's completely unit-tested and it has pretty good documentation. A few people are using it now and liking it :)

    Or, as Till said, you can inject your model - with all the usual pros and cons of coupling etc.

    Stray

  3. 3 Posted by Bert Deterd on 22 Feb, 2011 12:56 PM

    Bert Deterd's Avatar

    Hi All,
    Thanks for your comments.
    For now we raised an event in the OnRegister function which fetches our data. This works.
    The RelaxedEventMap looks very promising. We will look into that.

    Thanks,
    Regards,
    Bert

  4. Stray closed this discussion on 26 Feb, 2011 01:34 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