Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Clean up on control/view removal

$
0
0
I would put all your deferreds in an array, (they remove themselves when the request completes).  Overwrite the destroy method to .abort() all remaining requests in that array.


doSomething: function(){
  this.request( Todo.findAll({}, $.proxy(this.showTodos) ) )
},
request: function(deferred){
  var requests = this._requests || (this._requests = [] )
  requests.push(deferred)

   deferred.always(function(){
     requests.splice(requests.indexOf(deferrred),1)
   })
   return deferred;
}
destroy: function(){
  can.each(this._requests || [], function(def){
    def.abort()
  })
  return can.Control.prototype.destroy.apply(this, arguments)
}

Viewing all articles
Browse latest Browse all 3491

Trending Articles