• function

stopBatch can.Observe.stopBatch

 

End an event batch.

can.Observe.stopBatch([force[, callStart]])

Parameters

  1. force=false {bool}Optional

    whether to stop batching events immediately

  2. callStart=false {bool}Optional

    whether to call startBatch after firing batched events

stopBatch matches an earlier can.Observe.startBatch call. If stopBatch has been called as many times as startBatch (or if force is true), all batched events will be fired and any callbacks passed to startBatch 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.Observe.startBatch for examples of startBatch and stopBatch in normal use.

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

var addPeople = function(observable) {
    can.Observe.startBatch();
    observable.attr('a', 'Alice');
    observable.attr('b', 'Bob');
    observable.attr('e', 'Eve');
    can.Observe.stopBatch(true);
};

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

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

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

can.Observe.stopBatch();

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