androidx.compose.runtime.snapshots
Interfaces
ObserverHandle |
The type returned by observer registration methods that unregisters the observer when it is disposed. |
Cmn
|
SnapshotContextElement |
A |
Cmn
|
SnapshotMutableState |
A mutable value holder where reads to the |
Cmn
|
StateObject |
Interface implemented by all snapshot aware state objects. |
Cmn
|
Classes
MutableSnapshot |
A snapshot of the values return by mutable states and other state objects. |
Cmn
|
Snapshot |
A snapshot of the values return by mutable states and other state objects. |
Cmn
|
SnapshotApplyResult |
The result of a applying a mutable snapshot. |
Cmn
|
SnapshotApplyResult.Failure |
Cmn
|
|
SnapshotId |
The type of |
Cmn
android
N
JS
|
SnapshotIdArray |
An array of |
Cmn
android
N
JS
|
SnapshotStateList |
An implementation of |
Cmn
android
|
SnapshotStateMap |
An implementation of |
Cmn
|
SnapshotStateObserver |
Helper class to efficiently observe snapshot state reads. |
Cmn
|
SnapshotStateSet |
An implementation of |
Cmn
android
|
StateRecord |
Snapshot local value of a state object. |
Cmn
|
Exceptions
SnapshotApplyConflictException |
An exception that is thrown when |
Cmn
|
Objects
Annotations
AutoboxingStateValueProperty |
This annotation designates that a property on a State class will autobox when it is read from or assigned to. |
Cmn
|
StateFactoryMarker |
Designates a function as a factory function that produces a State object. |
Cmn
|
Type aliases
SnapshotId |
android
N
JS
|
|
SnapshotIdArray |
android
N
JS
|
Top-level functions summary
SnapshotStateList<T> |
<T : Any?> SnapshotStateList(size: Int, init: (index: Int) -> T)Creates a new snapshot state list with the specified |
Cmn
|
Extension functions summary
SnapshotContextElement |
Return a |
Cmn
|
T |
<T : StateRecord> T.readable(state: StateObject)Return the current readable state record for the current snapshot. |
Cmn
|
T |
<T : StateRecord> T.readable(state: StateObject, snapshot: Snapshot)Return the current readable state record for the |
Cmn
|
Int |
Cmn
|
|
inline Int |
JS
|
|
inline Int |
android
N
JS
|
|
Long |
Cmn
|
|
inline Long |
JS
|
|
inline Long |
android
N
JS
|
|
inline R |
<T : StateRecord, R : Any?> T.withCurrent(block: (r) -> R)Provides a |
Cmn
|
inline R |
<T : StateRecord, R : Any?> T.writable(state: StateObject, block: T.() -> R)Call |
Cmn
|
inline R |
<T : StateRecord, R : Any?> T.writable(Call |
Cmn
|
Top-level functions
SnapshotStateList
fun <T : Any?> SnapshotStateList(size: Int, init: (index: Int) -> T): SnapshotStateList<T>
Creates a new snapshot state list with the specified size, where each element is calculated by calling the specified init function.
The function init is called for each list element sequentially starting from the first one. It should return the value for a list element given its index.
Extension functions
asContextElement
fun Snapshot.asContextElement(): SnapshotContextElement
Return a SnapshotContextElement that will enter this Snapshot whenever the associated coroutine is resumed and leave this snapshot when it suspends. The snapshot still must be disposed separately when it will no longer be used.
import androidx.compose.runtime.snapshots.Snapshot import androidx.compose.runtime.snapshots.asContextElement runBlocking { val snapshot = Snapshot.takeSnapshot() try { withContext(snapshot.asContextElement()) { // Data observed by separately reading stateA and stateB are consistent with // the snapshot context element across suspensions doSomethingSuspending(someObject.stateA) doSomethingSuspending(someObject.stateB) } } finally { // Snapshot must be disposed after it will not be used again snapshot.dispose() } }
readable
fun <T : StateRecord> T.readable(state: StateObject): T
Return the current readable state record for the current snapshot. It is assumed that this is the first record of state
readable
fun <T : StateRecord> T.readable(state: StateObject, snapshot: Snapshot): T
Return the current readable state record for the snapshot. It is assumed that this is the first record of state
withCurrent
inline fun <T : StateRecord, R : Any?> T.withCurrent(block: (r) -> R): R
Provides a block with the current record, without notifying any read observers.
| See also | |
|---|---|
readable |
writable
inline fun <T : StateRecord, R : Any?> T.writable(state: StateObject, block: T.() -> R): R
Call block with a writable state record for the given record. It is assumed that this is called for the first state record in a state object. A record is writable if it was created in the current mutable snapshot.
writable
inline fun <T : StateRecord, R : Any?> T.writable(
state: StateObject,
snapshot: Snapshot,
block: T.() -> R
): R
Call block with a writable state record for snapshot of the given record. It is assumed that this is called for the first state record in a state object. If the snapshot is read-only calling this will throw.