tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/1739-how-do-i-initialize-a-view-without-a-modelRobotlegs: Discussion 2013-01-23T09:49:32Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/240398362013-01-21T04:06:39Z2013-01-21T04:06:40ZHow do I initialize a view without a model?<div><p>I've read many posts and the most recommended way is to not
inject the Model into the View, but instead have the Mediator
provide the data to the View in onRegister(), or for even more
decoupling have the Mediator fire a request event A, process it
with some Command, fire another response event B, catch it in the
Mediator and put the data into the View.</p>
<p>I have no issues with that approach (could be a bit of a
boilerplate code), but my question is: what if the View needs the
model data just to initialize itself, before the mediator is even
instantiated? For example, say I am writing a board game and the
size of the board (8x8 or 9x9) is stored in the Model. Ideally, I
want to have access to that configuration as soon as my View's
addedToStage() handler is invoked, because that's where all the UI
initialization is happening. Getting the board size <em>after</em>
the view has been initialized and potentially creating more UI
elements in the callback from the Mediator feels rather weird. If
we were in a multi-threaded environment it would mean that the View
might have to display itself while not knowing what to display.</p>
<p>Appreciate your thoughts.<br>
Thanks.</p></div>inquisitortag:robotlegs.tenderapp.com,2009-10-18:Comment/240398362013-01-21T12:14:41Z2013-01-21T12:14:41ZHow do I initialize a view without a model?<div><p>Hi inquisitor,</p>
<p>For rl 1, you might want to look at the links Neil provided in
his answer:<br>
<a href=
"http://knowledge.robotlegs.org/discussions/questions/1228-binding-in-a-mediator#comment_20495519">
http://knowledge.robotlegs.org/discussions/questions/1228-binding-i...</a></p>
<p>Robotlegs 2 offers more solutions to this kind of problems than
Robotlegs 1.</p>
<p>See: <a href=
"https://github.com/robotlegs/robotlegs-framework/tree/master/src/robotlegs/bender/extensions/viewProcessorMap">
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...</a></p>
<p>and the readme file for inspiration:<br>
<a href=
"https://github.com/robotlegs/robotlegs-framework/blob/master/src/robotlegs/bender/extensions/viewProcessorMap/readme.md">
https://github.com/robotlegs/robotlegs-framework/blob/master/src/ro...</a></p>
<p>One of the many ways of using the ViewProcessorMapExtension:</p>
<p>For example, you could inject a class containing some config
values (rectWidth, rectHeight) into the View.</p>
<p>In your context config class:</p>
<p>injector.map(SomeVO).asSingleton();</p>
<p>_viewProcessorMap.map(ViewToBeInjected).toInjection();</p>
<p>In ViewToBeInjected:<br>
[Inject] public var someVO:SomeVO;<br>
…<br>
graphics.drawRect(0, 0, someVO.rectWidth, someVO.rectHeight);</p>
<p>or</p>
<p>in your context config:<br>
const expectedViewWidth:Number = 100;<br>
const expectedViewHeight:Number = 200;</p>
<p>injector.map(Number,
'rectHeight').toValue(expectedViewHeight);<br>
injector.map(Number, 'rectWidth').toValue(expectedViewWidth);</p>
<p>_viewProcessorMap.map(ViewToBeInjected).toInjection();</p>
<p>In the View:</p>
<p>[Inject(name="rectWidth")] public var rectWidth:Number;</p>
<p>[Inject(name="rectHeight")] public var rectHeight:Number;</p>
<p>…</p>
<p>graphics.drawRect(0, 0, rectWidth, rectHeight);</p>
<p>Does this help?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/240398362013-01-21T18:40:06Z2013-01-21T18:40:06ZHow do I initialize a view without a model?<div><p>Hi Ondina,</p>
<p>Thank you for the links. I am already using the Presentation
Model pattern, because I dislike the chaotic nature of global
events. I prefer to work against well-defined interfaces, which are
just as good for separation of concerns, but much better for
compile time safety, coding (IDE support), and testing.</p>
<p>If I understand your suggestion correctly, using the View
Processors follows pretty much the same life cycle as I described
in the first paragraph of my original post, only without additional
events and with no boilerplate code. That sounds pretty useful. I
am not sure if I can use that at the moment, because I am using
Starling for my project, with s9tpepper's plugin for RL, which may
only work with RL-1.</p>
<p>Is the target release date for RL-2 known?</p></div>inquisitortag:robotlegs.tenderapp.com,2009-10-18:Comment/240398362013-01-22T09:59:21Z2013-01-22T09:59:21ZHow do I initialize a view without a model?<div><p>Hey inquisitor,</p>
<p>Yes, ViewProcessorMap is pretty flexible. Take a look at the
very simple example I posted yesterday in another post:</p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/robotlegs-2/752-guards-and-hooks#comment_24056610">
http://knowledge.robotlegs.org/discussions/robotlegs-2/752-guards-a...</a></p>
<p>Regarding Robotlegs 2 and Starling:</p>
<p><a href=
"https://github.com/Vj3k0/robotlegs-extensions-SARS">https://github.com/Vj3k0/robotlegs-extensions-SARS</a></p>
<p><a href=
"https://github.com/alebianco/StarlingExtension-example">https://github.com/alebianco/StarlingExtension-example</a></p>
<p><a href=
"https://github.com/jamieowen/robotlegs2-starling-viewmap">https://github.com/jamieowen/robotlegs2-starling-viewmap</a></p>
<blockquote>
<p>Is the target release date for RL-2 known?</p>
</blockquote>
<p>Oh, that’s a hard to answer question! ;-)</p>
<p>Here, Shaun’s answer on Twitter:<br>
“It'll be released when it's been thoroughly reviewed:
<a href=
"https://github.com/robotlegs/robotlegs-framework/issues/99%E2%80%9D">
https://github.com/robotlegs/robotlegs-framework/issues/99”</a></p>
<p>In fact, everyone who’s trying out RL2 and is writing
about encountered rl2 issues/problems on this forum is also
contributing to that reviewing process! Thus, I encourage you to
start using RL2 :)</p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/240398362013-01-23T03:50:50Z2013-01-23T03:50:50ZHow do I initialize a view without a model?<div><p>Thanks again, Ondina. I will checkout the SARS extension
(however <a href=
"http://en.wikipedia.org/wiki/Severe_acute_respiratory_syndrome">disturbing</a>
the name might be), as it seems to be most recently maintained.</p></div>inquisitortag:robotlegs.tenderapp.com,2009-10-18:Comment/240398362013-01-23T09:49:32Z2013-01-23T09:49:32ZHow do I initialize a view without a model?<div><p>My pleasure!</p>
<p>Hehe, I agree, SARS is a disturbing acronym. I don’t know
whether Vjekoslav was intentionally trying to scare us, but since
only Robotlungs would be affected by an infection, we
shouldn’t care: P</p>
<p>Have fun with Robotlegs 2 and Starling!</p></div>Ondina D.F.