MutableSnapshot

open class MutableSnapshot : Snapshot

A snapshot of the values return by mutable states and other state objects. All state object will have the same value in the snapshot as they had when the snapshot was created unless they are explicitly changed in the snapshot.

To enter a snapshot call enter. The snapshot is the current snapshot as returned by currentSnapshot until the control returns from the lambda (or until a nested enter is called. All state objects will return the values associated with this snapshot, locally in the thread, until enter returns. All other threads are unaffected.

All changes made in a MutableSnapshot are snapshot isolated from all other snapshots and their changes can only be seen globally, or by new shots, after MutableSnapshot.apply as been called.

Snapshots can be nested by calling takeNestedSnapshot or MutableSnapshot.takeNestedMutableSnapshot.

See also

Functions

apply
Link copied to clipboard
common
open fun apply(): SnapshotApplyResult
Apply the changes made to state objects in this snapshot to the global state, or to the parent snapshot if this is a nested mutable snapshot.
dispose
Link copied to clipboard
common
open override fun dispose()
Dispose the snapshot.
enter
Link copied to clipboard
common
inline fun <T> enter(block: () -> T): T
Enter the snapshot.
equals
Link copied to clipboard
common
open operator fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
common
open fun hashCode(): Int
hasPendingChanges
Link copied to clipboard
common
open override fun hasPendingChanges(): Boolean
Whether there are any pending changes in this snapshot.
takeNestedMutableSnapshot
Link copied to clipboard
common
open fun takeNestedMutableSnapshot(readObserver: SnapshotReadObserver? = null, writeObserver: SnapshotWriteObserver? = null): MutableSnapshot
Take a mutable snapshot of the state values in this snapshot.
takeNestedSnapshot
Link copied to clipboard
common
open override fun takeNestedSnapshot(readObserver: SnapshotReadObserver?): Snapshot
Take a snapshot of the state values in this snapshot.
toString
Link copied to clipboard
common
open fun toString(): String

Properties

id
Link copied to clipboard
common
open var id: Int
The snapshot id of the snapshot.
modified
Link copied to clipboard
common
internal open override var modified: MutableSet<StateObject>? = null
The set of state objects that have been modified in this snapshot.
readonly
Link copied to clipboard
common
open override val readonly: Boolean
True if any change to a state object in this snapshot will throw.
root
Link copied to clipboard
common
open override val root: Snapshot
The root snapshot for this snapshot.