StateRecord


Snapshot local value of a state object.

Summary

Public constructors

Cmn

This function is deprecated. Use snapshotId: Long constructor instead

Cmn
StateRecord(snapshotId: SnapshotId)
Cmn

Public functions

abstract Unit

Copy the value into this state record from another for the same state object.

Cmn
abstract StateRecord

Create a new state record for the same state object.

Cmn
open StateRecord
create(snapshotId: SnapshotId)

Create a new state record for the same state object and provided snapshotId.

Cmn

Extension functions

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 snapshot.

Cmn
inline R
<T : StateRecord, R : Any?> T.withCurrent(block: (r) -> R)

This function is deprecated. Use the overload that has a StateObject parameter instead; for example, next.withCurrent(this) { ... }

Cmn
inline R
<T : StateRecord, R : Any?> T.withCurrent(state: StateObject, block: (r) -> R)

Provides a block with the current record, without notifying any read observers.

Cmn
inline R
<T : StateRecord, R : Any?> T.writable(state: StateObject, block: T.() -> R)

Call block with a writable state record for the given record.

Cmn
inline R
<T : StateRecord, R : Any?> T.writable(
    state: StateObject,
    snapshot: Snapshot,
    block: T.() -> R
)

Call block with a writable state record for snapshot of the given record.

Cmn

Public constructors

StateRecord

StateRecord()

StateRecord

StateRecord(id: Int)

StateRecord

StateRecord(snapshotId: SnapshotId)

Public functions

assign

abstract fun assign(value: StateRecord): Unit

Copy the value into this state record from another for the same state object.

create

abstract fun create(): StateRecord

Create a new state record for the same state object. Consider also implementing the create overload that provides snapshotId for faster record construction when snapshot id is known.

create

open fun create(snapshotId: SnapshotId): StateRecord

Create a new state record for the same state object and provided snapshotId. This allows to implement an optimized version of create to avoid accessing currentSnapshot when snapshot id is known. The default implementation provides a backwards compatible behavior, and should be overridden if StateRecord subclass supports this optimization.

Extension functions

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

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

T.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

T.withCurrent

inline fun <T : StateRecord, R : Any?> T.withCurrent(state: StateObject, block: (r) -> R): R

Provides a block with the current record, without notifying any read observers.

Parameters
state: StateObject

the state object for which the receiver is a state record. It is assumed that this is the first record of state (e.g. next.withCurrent(this) { ... }).

block: (r) -> R

a block to be evaluated with the current state record as its parameter. The result of block is the result of withCurrent. It is expected, but not required, that the result of block is either Unit or derives it value from the content of the state record.

Returns
R

the result returned by the block lambda.

See also
readable
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.

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.