Package androidx.compose.runtime.snapshots

Types

MutableSnapshot
Link copied to clipboard
common
open class MutableSnapshot : Snapshot
A snapshot of the values return by mutable states and other state objects.
Snapshot
Link copied to clipboard
common
sealed class Snapshot
A snapshot of the values return by mutable states and other state objects.
SnapshotApplyConflictException
Link copied to clipboard
common
class SnapshotApplyConflictException(snapshot: Snapshot) : Exception
An exception that is thrown when SnapshotApplyResult.check is called on a result of a MutableSnapshot.apply that fails to apply.
SnapshotApplyObserver
Link copied to clipboard
common
typealias SnapshotApplyObserver = (changed: Set<Any>, snapshot: Snapshot) -> Unit

Callback type for observing when a non-nested mutable snapshot is applied by calling MutableSnapshot.apply, modifying the visible global state of state objects. Changes to a state object outside of a snapshot are also sent to the snapshot apply observer whenever Snapshot.sendApplyNotifications is called.

The committed parameter is a collection of state objects modified in the snapshot. The snapshot parameter is the snapshot that was applied.

SnapshotApplyResult
Link copied to clipboard
common
sealed class SnapshotApplyResult
The result of a applying a mutable snapshot.
SnapshotReadObserver
Link copied to clipboard
common
typealias SnapshotReadObserver = (state: Any) -> Unit

Callback type for observing reads of state objects in a snapshot.

SnapshotStateList
Link copied to clipboard
common
class SnapshotStateList<T> : MutableList<T> , StateObject
An implementation of MutableList that can be observed and snapshot.
SnapshotStateMap
Link copied to clipboard
common
class SnapshotStateMap<K, V> : MutableMap<K, V> , StateObject
An implementation of MutableMap that can be observed and snapshot.
SnapshotStateObserver
Link copied to clipboard
common
class SnapshotStateObserver(onChangedExecutor: (callback: () -> Unit) -> Unit)
SnapshotWriteObserver
Link copied to clipboard
common
typealias SnapshotWriteObserver = (state: Any) -> Unit

Callback type for observing writes to state objects in a snapshot.

StateObject
Link copied to clipboard
common
interface StateObject
Interface implemented by all snapshot aware state objects.
StateRecord
Link copied to clipboard
common
abstract class StateRecord
Snapshot local value of a state object.

Functions

readable
Link copied to clipboard
common
fun <T : StateRecord> T.readable(state: StateObject): T
Return the current readable state record for the current snapshot.
fun <T : StateRecord> T.readable(state: StateObject, snapshot: Snapshot): T
Return the current readable state record for the snapshot.
snapshotFlow
Link copied to clipboard
common
fun <T> snapshotFlow(block: () -> T): Flow<T>
Create a Flow from observable Snapshot state.
takeMutableSnapshot
Link copied to clipboard
common
fun takeMutableSnapshot(readObserver: SnapshotReadObserver? = null, writeObserver: SnapshotWriteObserver? = null): MutableSnapshot
Take a snapshot of the current value of all state objects that also allows the state to be changed and later atomically applied when MutableSnapshot.apply is called.
takeSnapshot
Link copied to clipboard
common
fun takeSnapshot(readObserver: SnapshotReadObserver? = null): Snapshot
Take a snapshot of the current value of all state objects.
withCurrent
Link copied to clipboard
common
inline fun <T : StateRecord, R> T.withCurrent(block: (T) -> R): R
Provides a block with the current record, without notifying any read observers.
withMutableSnapshot
Link copied to clipboard
common
inline fun <R> withMutableSnapshot(block: () -> R): R
Take a MutableSnapshot and run block within it.
writable
Link copied to clipboard
common
inline fun <T : StateRecord, R> T.writable(state: StateObject, block: T.() -> R): R
Call block with a writable state record for the given record.
inline fun <T : StateRecord, R> T.writable(state: StateObject, snapshot: Snapshot, block: T.() -> R): R
Call block with a writable state record for snapshot of the given record.