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

Re : Pause-able / Resume-able events in CanJS

$
0
0
can.batch.stop() and can.batch.start() will prevent any events from being fired system wide.  

Instead of unbinding, I would simply prevent all events from being triggered on an object.  There's however, no currently great way of doing this.  Your best bet might be to overwrite _triggerChange.  And add a stopBatch and startBatch method on can.Map like:

var oldTrigger= can.Map.prototype._triggerChange
can.extend(can.Map,{
  batchStart: function(){
    this._batchedEvents = [];
  },
  batchEnd: function(){
    var events = this. _batchedEvents;
    delete this. _batchedEvents
    // go through  events   and call this._triggerChange
  },
  _triggerChange: function(){
    if(this._batchedEvents){
      this._batchedEvents.push(arguments)

    } else {
      oldTrigger.apply(this, arguments)
    }
  }
})

Viewing all articles
Browse latest Browse all 3491

Trending Articles