take Snapshot
Take a snapshot of the current value of all state objects. The values are preserved until Snapshot.dispose is called on the result.
The readObserver parameter can be used to track when all state objects are read when in Snapshot.enter. A SnapshotApplyObserver can be registered using Snapshot.registerApplyObserver to observe modification of state objects.
An active snapshot (after it is created but before Snapshot.dispose is called) requires resources to track the values in the snapshot. Once a snapshot is no longer needed it should disposed by calling Snapshot.dispose.
Leaving a snapshot active could cause hard to diagnose memory leaks values as are maintained by state objects for these unneeded snapshots. Take care to always call Snapshot.dispose on all snapshots when they are no longer needed.
Composition uses both of these to implicitly subscribe to changes to state object and automatically update the composition when state objects read during composition change.
A nested snapshot can be taken of a snapshot which is an independent read-only copy of the snapshot and can be disposed independently. This is used by takeSnapshot when in a read-only snapshot for API consistency allowing the result of takeSnapshot to be disposed leaving the parent snapshot active.
See also
Parameters
called when any state object is read in the lambda passed to Snapshot.enter or in the Snapshot.enter of any nested snapshot.