tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/585-loading-data-for-a-specific-view-instanceRobotlegs: Discussion 2013-04-28T10:18:34Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/78792002011-06-13T21:12:51Z2011-06-13T21:12:52ZLoading data for a specific view instance?<div><p>Ugh, my formatting got massacred...</p></div>Shawntag:robotlegs.tenderapp.com,2009-10-18:Comment/78792002011-06-13T21:20:11Z2011-06-13T21:20:11ZLoading data for a specific view instance?<div><p>I fixed your formatting :)</p>
<p>So... one option is simply to put <code>false</code> for the
autoRemove parameter for this mediator mapping.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/78792002011-06-13T21:22:45Z2011-06-13T21:22:45ZLoading data for a specific view instance?<div><p>Actually, on top of that I would combine it with a
request-response pattern of signals - where you pass a signal to be
used for the response, so you don't have to mess about with ids and
such on your responses.</p>
<p>If you're interested in that approach then if you search for
request and response in this forum you'll find a few discussions of
it.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/78792002011-06-13T21:29:39Z2011-06-13T21:29:40ZLoading data for a specific view instance?<div><p>Thanks Stray!</p>
<p>I don't think that wouldn't fix the problem, as then we would
just have both mediators picking up the event. So both views would
end up with data from Service Call 2. I want the proper view to end
up with the proper data.<br>
(Not to mention, the app is basically one big view stack, views are
added/removed at the user's will, and it has a "Back" button. So
that would mean essentially disabling autoRemove for every
view)</p>
<p>Either way, I need to pass the view to the command right? I
don't see anyway to avoid this...</p>
<p>I have to pass the view to the command, and when the service
completes, the command needs to update the model, and pass the view
in, so the model can map view > data.</p>
<p>Also, I don't see anyway I can do this without having my command
listen to the service directly...is there a design pattern I'm just
missing?</p></div>Shawntag:robotlegs.tenderapp.com,2009-10-18:Comment/78792002011-06-13T21:32:01Z2011-06-13T21:32:02ZLoading data for a specific view instance?<div><p>Could you expand on the signals approach? I've never used
signals. (I can't switch this project to signals, we're stuck with
events, but maybe the general approach would work?)</p>
<p>Would this be essentially passing a callback to the Command, so
when the service has completed, it just calls the callback? And
this callback would be view.setData() or something?</p></div>Shawntag:robotlegs.tenderapp.com,2009-10-18:Comment/78792002011-06-13T21:54:37Z2011-06-13T21:54:37ZLoading data for a specific view instance?<div><p>Hi Shaun, no problem,</p>
<p>You'd need to put an ID on the mediator obviously and have each
mediator filter which call backs it responds to based on whether
the ID matches its ID.</p>
<p>I wasn't clear from your question how many of these things there
are - I'm not talking about disabling autoRemove for all views,
just for the class that the comments need to be fed back into.</p>
<p>Like I said - if you search around request/response+signal on
the forum you'll get quite a few hits.</p>
<p>Signals isn't a 'switch' really - it's just a library, most
people use them in combination with events. It's no different to
adding TweenLite or something similar to your project.</p>
<p>So, yes - basically signals are kind of like callbacks but with
intelligent error checking so you can't send something that hasn't
been expected and you can do 'addOnce' so that the callback is
unwired as soon as it has been used.</p>
<p>The other option would be a Promise. Check out Shaun's oil utils
repository on github.</p>
<p>And finally, you could maintain a history by view reference, and
just request the latest data when the mediator does onRegister.</p>
<p>All of these should be viable solutions.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/78792002011-06-13T22:06:49Z2011-06-13T22:06:50ZLoading data for a specific view instance?<div><p>Ok, cool I'll look into Promise, and see how that might fit the
bill. I see what you mean about signals not being all-in or
all-out.</p>
<p>Regarding mediator id, well that is sorta the crux of the issue,
seems like the id needs to be the view instance...</p>
<p>I "get" the history mapping approach, I'm a little less clear on
how this would work with a promise.</p></div>Shawntag:robotlegs.tenderapp.com,2009-10-18:Comment/78792002011-11-01T14:27:37Z2011-11-01T14:27:37ZLoading data for a specific view instance?<div><p>Thank you for posting.<br>
Feel free to reopen this discussion if you feel the answer(s) to be
dis-satisfactory or if you need more help with this issue,
otherwise we'll consider the thread closed. Please open new threads
for new issues.<br>
Ondina</p></div>Ondina D.F.