tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/5760-having-problems-with-context-listenersRobotlegs: Discussion 2014-07-02T07:18:47Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/331890502014-05-29T21:10:04Z2014-05-29T21:10:04ZHaving problems with context listeners<div><p>Hi Michael,</p>
<p>take a look at the RelaxedEventMap:<br>
<a href=
"https://github.com/Stray/robotlegs-utilities-RelaxedEventMap">https://github.com/Stray/robotlegs-utilities-RelaxedEventMap</a></p>
<p>Let me know if it solves your problem.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/331890502014-05-30T16:45:27Z2014-05-30T16:45:29ZHaving problems with context listeners<div><p>I am surprised I need to import some code for what seems to be a
basic need.</p>
<p>I tried to dispatch an event in startup, but that resulted in
other problems.</p>
<p>Seems like there should be some simple way to ensure all the RL
legs stuff is in place, such that I can initialize any model data I
need via issuing commands and then dispatch events so that views
can update.</p>
<p>But so far, I can either use creationcomplete or application
complete to ensure my code runs after the view's component is
functional, or dispatch an event in the RL context startup, but not
ensure both the views and the mediators are fully functional.</p>
<p>What did people do before relaxedevent map?</p></div>Michael Bauerstag:robotlegs.tenderapp.com,2009-10-18:Comment/331890502014-06-01T17:50:55Z2014-06-01T17:50:55ZHaving problems with context listeners<div><p>Hello Michael,</p>
<p>I know it seems like a basic thing (and it is), but
race-conditions happen when you use an event bus. If a listener is
attached after an event has fired, that listener can not possibly
catch that event.</p>
<p>Mediators are only created for views when those views land on
the stage - or, put another way, mediators are created lazily. In
the case of a Flex UIComponent, the onRegister hook is only called
once the UIComponent has actually initialised (even later).</p>
<p>Robotlegs cannot know when you've finished adding all your views
to the stage, and in fact, that doesn't even make much sense -
unless every view in your app is created and added to the stage at
startup (which is usually not what you want anyway).</p>
<p>Generally, views/mediators are created on demand, at some later
point. If some event has fired in the meantime, you cannot know
about it. This is what models are for - they hold state. The events
broadcast the fact that the state has changed. If a view cares
about that state it needs to do two things:</p>
<ol>
<li>Check the state<br></li>
<li>Listen for changes to the state.</li>
</ol>
<p>In your case it sounds like the problematic mediators are only
doing the second step.</p></div>Shaun Smith