Creating an array of objects, each with their own model
I'm so happy that my brain is finally starting to understand Robotlegs. I've begun porting some of my old projects over for practice, and I'm running into lots of situations that seem like judgement calls, so I'd like to get suggestions from programmers more experienced than I.
In this situation, I've got a Gallery of ProfileCells, each one
containing a picture, name, email, etc.
I add the Gallery container to the main ContextView in a startup
command.
Once the XML is loaded, it dispatches an event which calls the
CreateCells command. This command makes a new ProfileCell View for
each 'person' entry in the XML. This is where the question comes
in. I don't load the photo or fill in the name areas of the
ProfileCell View, since that's a job for its Mediator. So instead I
instantiate a new ProfileCellModel and populate it with the
XML.
It works just fine, but I'd love to get some feedback on this
method. One reason it feels a little strange to me is this: the
'model' property on the ProfileCell view is dynamic. The
ProfileCell View itself is loaded from a SWC and relies on its
Mediator for all declared properties.
My previous projects working with SWCs in this way felt hacky and
Robotlegs has gone a long way towards helping me nail down some
best practices, so I definitely want to avoid learning any bad
habits as I get into it further.
Apologies for the long first post, major thanks to the community for creating and supporting this framework.
Comments are currently closed for this discussion. You can start a new one.
2 Posted by surya on 03 May, 2010 05:11 PM
Doh - didn't read the description of this forum subsection, this thread should be in 'Questions'.
3 Posted by Jonny Reeves on 04 May, 2010 02:08 PM
Hi Surya,
I also use SWCs to pull in Assets (created in CS4). Instead of directly mediating the SWC instance; I create a new View object which extends Sprite and creates an instance of the SWC Asset via composition, for example:
You are now free to create your own API for the view class without having to rely on dynamic properties, etc.
Also; I would add that I don't think it's a great idea to set the Model object on your view - I prefer to let the Mediator talk to the view in primative / built-in datatypes (Strings, Numbers, Arrays, etc) to ensure they are as uncoupled from the rest of the application as possible - this makes them much more reusable.
Hope that helps
Jonny.
4 Posted by surya on 07 May, 2010 06:31 PM
Good suggestions, Jonny - thanks! If I don't set the Model in the view, then what method would you recommend for keeping track of which Model instance a particular view is bound to? I could set the View in the Model, I suppose, or pair them via another model - do either of these sounds better?
Stray closed this discussion on 12 Feb, 2011 12:54 AM.