stop

  • function
 

End an event batch.

can.batch.stop([force[, callStart]])

Parameters

  1. force=false {bool}Optional

    whether to stop batching events immediately

  2. callStart=false {bool}Optional

    whether to call can.batch.start after firing batched events

can.batch.stop matches an earlier can.batch.start call. If can.batch.stop has been called as many times as can.batch.start (or if force is true), all batched events will be fired and any callbacks passed to can.batch.start since the beginning of the batch will be called. If _force and callStart are both true, a new batch will be started when all the events and callbacks have been fired.

See can.batch.start for examples of can.batch.start and can.batch.stop in normal use.

In this example, the batch is forceably ended in the addPeople function.

var addPeople = function(observable) {
    can.batch.start();
    observable.attr('a', 'Alice');
    observable.attr('b', 'Bob');
    observable.attr('e', 'Eve');
    can.batch.stop(true);
};

// In a completely different place:
var list = new can.Map();
list.bind('change', function() {
    console.log('The list changed.');
});

can.batch.start();
addPeople(list);
console.log('Still in the batch.');

// Here, the console has:
// Still in the batch.

can.batch.stop();

// Here, the console has:
// The list changed.
// The list changed.
// The list changed.
// Still in the batch.