{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

SnapshotKt

public final class SnapshotKt


Summary

Public methods

static final @NonNull T
<T extends StateRecord> readable(@NonNull T receiver, @NonNull StateObject state)

Return the current readable state record for the current snapshot.

static final @NonNull T
<T extends StateRecord> readable(
    @NonNull T receiver,
    @NonNull StateObject state,
    @NonNull Snapshot snapshot
)

Return the current readable state record for the snapshot.

static final @NonNull R
<T extends StateRecord, R extends Object> withCurrent(
    @NonNull T receiver,
    @NonNull Function1<@NonNull r, @NonNull R> block
)

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

static final @NonNull R
<T extends StateRecord, R extends Object> writable(
    @NonNull T receiver,
    @NonNull StateObject state,
    @ExtensionFunctionType @NonNull Function1<@NonNull T, @NonNull R> block
)

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

static final @NonNull R
<T extends StateRecord, R extends Object> writable(
    @NonNull T receiver,
    @NonNull StateObject state,
    @NonNull Snapshot snapshot,
    @ExtensionFunctionType @NonNull Function1<@NonNull T, @NonNull R> block
)

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

Public methods

readable

public static final @NonNull T <T extends StateRecord> readable(@NonNull T receiver, @NonNull StateObject state)

Return the current readable state record for the current snapshot. It is assumed that this is the first record of state

readable

public static final @NonNull T <T extends StateRecord> readable(
    @NonNull T receiver,
    @NonNull StateObject state,
    @NonNull Snapshot snapshot
)

Return the current readable state record for the snapshot. It is assumed that this is the first record of state

withCurrent

public static final @NonNull R <T extends StateRecord, R extends Object> withCurrent(
    @NonNull T receiver,
    @NonNull Function1<@NonNull r, @NonNull R> block
)

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

See also
readable

writable

public static final @NonNull R <T extends StateRecord, R extends Object> writable(
    @NonNull T receiver,
    @NonNull StateObject state,
    @ExtensionFunctionType @NonNull Function1<@NonNull T, @NonNull R> block
)

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

public static final @NonNull R <T extends StateRecord, R extends Object> writable(
    @NonNull T receiver,
    @NonNull StateObject state,
    @NonNull Snapshot snapshot,
    @ExtensionFunctionType @NonNull Function1<@NonNull T, @NonNull R> block
)

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.