watchChanges method
Stream<void>
watchChanges({
- Duration? debounce = const Duration(milliseconds: 200),
- bool fireImmediately = false,
- List<
StoreParts> storeParts = const [StoreParts.metadata, StoreParts.tiles, StoreParts.stats],
Watch for changes in the current store
Useful to update UI only when required, for example, in a StreamBuilder
.
Whenever this has an event, it is likely the other statistics will have
changed.
Control where changes are caught from using storeParts
. See documentation
on those parts for their scope.
Enable debouncing to prevent unnecessary events for small changes in detail
using debounce
. Defaults to 200ms, or set to null to disable debouncing.
Debouncing example (dash roughly represents debounce
):
input: 1-2-3---4---5-6-|
output: ------3---4-----6|
Implementation
Stream<void> watchChanges({
Duration? debounce = const Duration(milliseconds: 200),
bool fireImmediately = false,
List<StoreParts> storeParts = const [
StoreParts.metadata,
StoreParts.tiles,
StoreParts.stats,
],
}) =>
StreamGroup.merge([
if (storeParts.contains(StoreParts.metadata))
_db.metadata.watchLazy(fireImmediately: fireImmediately),
if (storeParts.contains(StoreParts.tiles))
_db.tiles.watchLazy(fireImmediately: fireImmediately),
if (storeParts.contains(StoreParts.stats))
_db.storeDescriptor
.watchObjectLazy(0, fireImmediately: fireImmediately),
]).debounce(debounce ?? Duration.zero);