tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/264-onregister-for-mediator-too-lateRobotlegs: Discussion 2018-10-18T16:35:23Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/54116562011-02-17T17:29:18Z2011-02-17T17:29:18ZOnRegister for mediator too late<div><p>Hi Bert,</p>
<p>onRegister is, in fact, invoked one frame after the mediator,
and the<br>
view it mediates, is created when dealing with Flex components.
This<br>
is done on purpose to allow for full initialization of the
component.</p>
<p>In your case, you could either override the MediatorBase's<br>
<code>preRegister' method (but don't forget to call</code>super()`
if you do), or you could simply fetch the data in the onRegister
method. It seems<br>
to me like it's a safe assumption that once you're showing the<br>
Resultsview, there are some results in the model to actually show,
so<br>
querying for them might be an option. This, in turn, can be
done<br>
either by dispatching a data-request event, as Stray would
recommend<br>
with good arguments, or by injecting the model into the mediator.
The<br>
latter causes much tighter coupling between the view and the
logic<br>
layers of your app, so be careful with that.</p>
<p>cheers,<br>
till</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/54116562011-02-17T18:41:06Z2011-02-17T18:41:06ZOnRegister for mediator too late<div><p>Hi Bert,</p>
<p>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.</p>
<p>Code is on github here:</p>
<p><a href=
"https://github.com/Stray/robotlegs-utilities-RelaxedEventMap">https://github.com/Stray/robotlegs-utilities-RelaxedEventMap</a></p>
<p>It's completely unit-tested and it has pretty good
documentation. A few people are using it now and liking it :)</p>
<p>Or, as Till said, you can inject your model - with all the usual
pros and cons of coupling etc.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/54116562011-02-22T12:56:17Z2011-02-22T12:56:17ZOnRegister for mediator too late<div><p>Hi All,<br>
Thanks for your comments.<br>
For now we raised an event in the OnRegister function which fetches
our data. This works.<br>
The RelaxedEventMap looks very promising. We will look into
that.</p>
<p>Thanks,<br>
Regards,<br>
Bert</p></div>Bert Deterd