I don't think it's a good idea to fire some "fake" event since
(at least) there can be other members who could respond to it and
make some useless complex calculations. It's better for model to
keep size so you could get them when needed and apply them to your
background image when needed.
Thanks for the reply, so are you saying i should inject the
ResizeModel into the BgdViewMediator instance, and then just grab
the stage w/h data off it once the image has loaded? I know it's a
bit controversial to reference the models directly from the
mediators isn't it?
I was thinking about sending a message to the model to tell it to
send a message back with the latest stage data is that a better way
of doing it or just a different way?
Sorry to be pedantic about it, i'm just very new to the framework
and want to make sure i'm doing it the best way for the long term
so as to keep things decoupled.
Would you suggest to inject the Model and reference it directly
in the mediator?
I have tried it both ways now, and certainly the injection
method is the easiest and most elegant way of the two :)
I just wanted to make sure i wasn't making some fatal error which
could lead to major issues later on.
Well I mentioned one most (for me) obvious and expensive
side-effect. Imagine you have several other something
(components/actors/commands/whatever) that listen to that same
resize event. So when you force to fire it — all of them will
react instead of background only. Not nice IMHO.
You could think of others...
Support Staff7 Posted by creynders on 01 Sep, 2011 06:17 PM
I'm certainly no guru, but maybe my 2 cents can help out as
In general I let views respond to the stage resize event directly.
It IS a view event and all display objects have a direct reference
to the stage, so I see no need to drag the entire framework into
However, if complex calculations need to be made or multiple views
need the same coordinates for instance then I do rely on a
StageModel. More often than not this means it maintains a set of
coordinates, registration points that several views need to adjust
their position to. In that case the update cycle is pretty
straight-forward too. The ContextViewMediator picks up the stage
resize event and either relays it to the framework or dispatches a
custom event. A command picks it up and updates the StageModel,
which decides whether the dispatched data is relevant and updates
its data if necessary. The model sends out some kind of
STAGEDATA_UPDATE event with a VO which gets picked up by the
various mediators that pass the relevant data to their views.
To solve the problem of mediators "missing" the event because they
are not registered yet I use the RelaxedEventMap utility: https://github.com/Stray/robotlegs-utilities-RelaxedEventMap
After a couple of days experimenting with the framework (i'm a
bit slow;) i'm starting to get a grip on the event flow process and
the different ways RL can be used to update views ( via the model,
commands, injection etc).
Thanks for your input on this - the link for the RelaxedEventMap
will certainly come in useful.