tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/709-non-singleton-models-and-commandsRobotlegs: Discussion 2018-10-18T16:35:34Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/112464362011-11-08T19:55:22Z2011-11-08T19:55:22ZNon-singleton Models and Commands<div><p>This topic has been discussed a few places on this forum
already.<br>
Here: <a href=
"http://knowledge.robotlegs.org/discussions/questions/196-non-singleton-actors">
http://knowledge.robotlegs.org/discussions/questions/196-non-single...</a><br>
and here: <a href=
"http://knowledge.robotlegs.org/discussions/questions/389-mapping-a-specific-model-non-singleton-to-commands-and-mediators">
http://knowledge.robotlegs.org/discussions/questions/389-mapping-a-...</a></p>
<p>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.</p>
<p>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.</p>
<p>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.</p></div>robtag:robotlegs.tenderapp.com,2009-10-18:Comment/112464362011-11-08T20:08:50Z2011-11-08T20:08:50ZNon-singleton Models and Commands<div><p>Hi Rob, that sounds sensible - the 'id' thing is what folk
usually end up using in this situation.</p>
<p>hth,</p>
<p>Sray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/112464362011-11-08T20:37:56Z2011-11-08T20:37:56ZNon-singleton Models and Commands<div><p>Hey Stray,</p>
<p>Thanks for the feedback, that seems in line with what was said
in one of the prior posts.</p>
<p>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?</p></div>robtag:robotlegs.tenderapp.com,2009-10-18:Comment/112464362011-11-08T21:30:17Z2011-11-08T21:30:17ZNon-singleton Models and Commands<div><p>Hi Rob,</p>
<p>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.</p>
<p>Perhaps we'll get generics before long - in which case it'll be
lovely to do that!</p>
<p>hth,</p>
<p>Stray</p></div>Stray