tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/412-global-objects-in-viewsRobotlegs: Discussion 2018-10-18T16:35:33Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/109138972011-10-27T15:36:38Z2011-10-27T15:36:38ZGlobal objects in Views<div><p>This is a scenario I run into often. There are a few other
threads that<br>
will have some different thoughts (either for app strings, or
for<br>
styling/skinning, or for factories, or common view utility
classes).</p>
<p>In some ways it's not really a Robotlegs issue since it's
something<br>
that's completely specific to the view layer. At the same time,<br>
Robotlegs gives us some handy tools like dependency injection that
I<br>
would love to use in the view layer as well. Going forward, the<br>
Robotlegs 2 roadmap mentions some things about improved view
utility<br>
support, so I'm hoping the geniuses on the core team have some
great<br>
ideas in store for the future.</p>
<p>However, for now there are a few approaches I've considered and
used:<br>
1. Just use a static class, the same way you've done before.<br>
2. Create a property on your view like "locale". In your<br>
context/configuration, map your Locale class as a singleton. Inject
the<br>
Locale class into the mediator, and in the mediator's
onRegister()<br>
method, have it set view.locale to the injected Locale
instance.<br>
3. Create several properties on the view for the various strings,
then<br>
do something similar to 2 but setting individual values rather than
a<br>
single Locale object.</p>
<p>etc.</p>
<p>Paul</p></div>Paul Robertsontag:robotlegs.tenderapp.com,2009-10-18:Comment/109138972011-10-28T11:19:10Z2011-10-28T11:19:11ZGlobal objects in Views<div><p>Thank you for your answer. I guess its about how decoupled the
view should be. I came up with the same idea to let the mediator
setup the injected variable through a init(data:Object) function in
the view. :-) Theres always more than one way of solving a problem
:-)</p></div>cdomp