Non-singleton Models and Commands

rob's Avatar


08 Nov, 2011 07:55 PM

This topic has been discussed a few places on this forum already.
and here:

But I can't reopen those topics (at least I don't think I can) so I decided to start a new discussion. Admins please correct me if that's bad etiquette.

I'm building an autocomplete form exactly like the one you see on Facebook when you type your friend's name in at the top. The exception is that I have 5 of these on the page instead of just one, and when you pick a friend from the little dropdown it displays their picture and name. In my mind, each of those 5 autocomplete fields is a View, which should have a little FriendModel associated to it. In this scenario, the FriendModel is unique to each View so I'm doing injector.mapClass instead of injector.mapSingleton. When I click the little send button next to my friend's name, ideally (in my mind at least) it should somehow make that unique FriendModel available in the command that then sends my friend a message. However, it seems that the RL way is to use singleton models instead of individuals. If that's the case then I'll probably need a singleton model which has a collection inside of it, and then my view will have an id of some kind. The id will be sent along as the payload for the event/signal that triggers the command which sends my friend their message. In the command my model will need to reconcile the id with its collection and provide the right friend info. Saving my friend to the collection follows this same process I think.

Does that seem right or am I making the process too convoluted? I like the idea of an individual model associated with each view, kinda like how rails works, but I understand that Flash is a different beast and sometimes you just have to do things differently.

  1. 1 Posted by Stray on 08 Nov, 2011 08:08 PM

    Stray's Avatar

    Hi Rob, that sounds sensible - the 'id' thing is what folk usually end up using in this situation.



  2. 2 Posted by rob on 08 Nov, 2011 08:37 PM

    rob's Avatar

    Hey Stray,

    Thanks for the feedback, that seems in line with what was said in one of the prior posts.

    Speaking hypothetically, do you think there is value for RL in allowing individual models to be quickly looked up, similar to how rails lets you find a user model or something with the param id? In Rails that behavior is just built-in and people use it all the time. RL is different since it's supposed to be minimal, but it seems like such a thing could be a useful extension?

  3. 3 Posted by Stray on 08 Nov, 2011 09:30 PM

    Stray's Avatar

    Hi Rob,

    Until AS3 has proper generics, there's no way to do that in a way that is both reusable across apps and type safe. Type safety is one of our priorities, so sadly that's not an area that I can imagine it's possible to build a useful extension for - it wouldn't be worth giving up your type safety just to save the dozen lines of code or so that it takes to roll your own.

    Perhaps we'll get generics before long - in which case it'll be lovely to do that!



  4. rob closed this discussion on 10 Nov, 2011 06:21 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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