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
reactive.startBatchUpdate();
// Make multiple changes
reactive.value = 10;
reactive.value = 20;
reactive.value = 30;
// End batching and publish only the final state
reactive.endBatchUpdate();
// Or, to publish all intermediate states:
// reactive.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();
}
}
}