Global objects in Views
Hi am totally new to RL dont be to hard on me for asking stupid
questions.
In RL the view shouldnt have any dependencies with the rest of the
app other than through the mediator if i got it all right.
Im used to have a static class that holds all strings to populate
labels on the displaylist. somethng like this in the view:
textfield.text = Locale.getString("id");
Is it a good approach in RL or how would you set it up?
I especially think of when initiating complex views with much text,
the static approach is pretty handy.
How do you think of it?
//Criss
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Paul Robertson on 27 Oct, 2011 03:36 PM
This is a scenario I run into often. There are a few other threads that
will have some different thoughts (either for app strings, or for
styling/skinning, or for factories, or common view utility classes).
In some ways it's not really a Robotlegs issue since it's something
that's completely specific to the view layer. At the same time,
Robotlegs gives us some handy tools like dependency injection that I
would love to use in the view layer as well. Going forward, the
Robotlegs 2 roadmap mentions some things about improved view utility
support, so I'm hoping the geniuses on the core team have some great
ideas in store for the future.
However, for now there are a few approaches I've considered and used:
1. Just use a static class, the same way you've done before.
2. Create a property on your view like "locale". In your
context/configuration, map your Locale class as a singleton. Inject the
Locale class into the mediator, and in the mediator's onRegister()
method, have it set view.locale to the injected Locale instance.
3. Create several properties on the view for the various strings, then
do something similar to 2 but setting individual values rather than a
single Locale object.
etc.
Paul
2 Posted by cdomp on 28 Oct, 2011 11:19 AM
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 :-)
cdomp closed this discussion on 28 Oct, 2011 11:19 AM.