endBatchUpdate method
Ends a batch update session and optionally publishes the buffered changes.
When the outermost batch update is ended (when the internal counter reaches zero),
the buffered changes are published to listeners. By default, only the last change
is published, but you can publish all buffered changes by setting publishAll to true.
Parameters:
publishAll: If true, all buffered updates are published in sequence. If false (default), only the most recent update is published.
Example usage:
// Start batching updates
computed.startBatchUpdate();
// Make multiple changes to sources
source1.value = 10;
source2.value = 20;
source3.value = 30;
// End batching and publish only the final state
computed.endBatchUpdate();
// Or, to publish all intermediate states:
// computed.endBatchUpdate(publishAll: true);
See also:
- startBatchUpdate: Starts a batch update session
Implementation
void endBatchUpdate({bool publishAll = false}) {
if (_batchUpdateCounter > 0) {
_batchUpdateCounter--;
if (_batchUpdateCounter == 0 && _bufferedEvents.isNotEmpty) {
if (publishAll) {
for (var event in _bufferedEvents) {
_controller.add(event);
}
} else {
_controller.add(_bufferedEvents.last);
}
_bufferedEvents.clear();
}
}
}