tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/2171-interrupt-uploading-multiple-files-from-viewmediatorRobotlegs: Discussion 2014-04-19T18:08:43Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/260008322013-03-22T14:47:03Z2013-03-22T16:22:01ZInterrupt uploading multiple files from view/Mediator<div><p>Hi Valley,</p>
<p>You can try using commandMap.detain and commandMap.release.</p>
<p>Here a simple scenario: in your LoadSomethingCommand:</p>
<pre>
<code>override public function execute():void
{
commandMap.detain(this);
model.doSomething("BLAH");//sets someProperty
model.callBack=callback;
}
private function callback():void
{
commandMap.release(this);
}</code>
</pre>
<p>In your Model:</p>
<pre>
<code>public var callBack:Function;
…
public function doSomething(value:String):void
{
someProperty=value;
if(someProperty=="")
callBack.call();
}</code>
</pre>
<p>When user clicks cancel, the view dispatches an event, the
mediator can re-dispatch it to trigger a command that sets
someProperty to null or to whatever you needed it to be, and the
Model will call command’s callBack method, where you release
the command.</p>
<p>But I’m not sure whether that’s solving your problem
entirely. You’ll have to make sure that the changes to your
Model’s data won’t affect the state of your app in an
undesired way after cancelling an async process.</p>
<p>Maybe you can also take a look at:<br>
Tim Oxley’s Undoable Command Classes for Robotlegs
Framework:<br>
<a href=
"https://github.com/timoxley/robotlegs-utilities-UndoableCommand">https://github.com/timoxley/robotlegs-utilities-UndoableCommand</a></p>
<p>and this fork:<br>
<a href=
"https://github.com/d3zza/robotlegs-utilities-UndoableCommand">https://github.com/d3zza/robotlegs-utilities-UndoableCommand</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/260008322013-03-22T23:18:03Z2014-04-19T18:08:43ZInterrupt uploading multiple files from view/Mediator<div><p>Hi Ondina,</p>
<p>so in terms of my uploading task: The called uploading command
sees a list of n files to upload to a server async in model
myModel. It starts with the first and registers for progress and
complete events. Whenever one of these events will be received the
command checks in myModel about changes.<br>
Anytime the user can click a cancel button. If i understand you
correctly the Mediator then calls a 2nd command
CancelUploadCommand, which sets a flag 'isCancelled' to true in the
same model myModel and clears the list of remaining files to
upload.<br>
Will the 1st command (which is still running and uploading) see
these two changes which have been performed by the 2nd command and
therefore cancel all future uploading steps ?<br>
To keep the 1st command running i would definitely use<br></p>
<pre>
<code>commandMap.detain(this);</code>
</pre>
<p>I don't think i need callbacks for that.</p></div>rivella50tag:robotlegs.tenderapp.com,2009-10-18:Comment/260008322013-03-23T12:20:42Z2013-03-23T12:20:42ZInterrupt uploading multiple files from view/Mediator<div><p>Hi Valley,</p>
<blockquote>
<p>Anytime the user can click a cancel button. If i understand you
correctly the Mediator then calls a 2nd command
CancelUploadCommand, which sets a flag 'isCancelled' to true in the
same model myModel and clears the list of remaining files to
upload. Will the 1st command (which is still running and uploading)
see these two changes which have been performed by the 2nd command
and therefore cancel all future uploading steps ?</p>
</blockquote>
<p>Right. Since the uploading command is being detained, it will
notice the changes in the model.</p>
<p>Of course you can set the model’s flag
‘isCancelled’ inside your mediator as well, if you
really wanted or needed to. I’d prefer letting a command
access the model. The reasons for that are already well explained
in a number of discussions on this forum. If you’re
interested in knowing why (most of the time) is better to not
inject a model into a mediator, search the discussions for
“inject model into mediator”.</p>
<blockquote>
<p>I don't think i need callbacks for that.</p>
</blockquote>
<p>Yes, you’re right; you don’t need a callback method.
In my little example I just wanted to show you how to use detain
and release. You know your use case better than me, so you’ll
decide what you need to do :) Anyway, you’ll have to call
commandMap.release(this); when isCancelled==true, so the command
can get garbage collected.</p>
<p>Did I answer all your questions?</p>
<p>If you think your problem has been resolved, you can close this
discussion, or let me know so I can close it myself. And, of
course, you can re-open it, if you have any further questions
regarding this issue.</p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/260008322013-03-28T16:40:57Z2014-04-19T18:08:43ZInterrupt uploading multiple files from view/Mediator<div><p>Hi Ondina,</p>
<p>it works fine now: I have extracted the uploading code to a
Service.<br>
There is one command that starts the upload and another that
interrupts it (closing the running URLLoader instance in the
Service) if the user wants that.<br>
Therefore no Boolean flag anymore in another model needed.<br>
Please close the discussion.<br>
Thanks again for your help.<br>
valley</p></div>rivella50tag:robotlegs.tenderapp.com,2009-10-18:Comment/260008322013-03-28T17:12:22Z2013-03-28T17:12:22ZInterrupt uploading multiple files from view/Mediator<div><p>Hey Valley,<br>
No problem. I’m glad it worked out for you.</p></div>Ondina D.F.