Google is committed to advancing racial equity for Black communities. See how.

StateObject

interface StateObject
androidx.compose.runtime.snapshots.StateObject

Interface implemented by all snapshot aware state objects. Used by this module to maintain the state records of a state object.

Summary

Public methods
open StateRecord?
mergeRecords(previous: StateRecord, current: StateRecord, applied: StateRecord)

Produce a merged state based on the conflicting state changes.

abstract Unit

Add a new state record to the beginning of a list.

Properties
abstract StateRecord

The first state record in a linked list of state records.

Public methods

mergeRecords

open fun mergeRecords(
    previous: StateRecord,
    current: StateRecord,
    applied: StateRecord
): StateRecord?

Produce a merged state based on the conflicting state changes.

This method must not modify any of the records received and should treat the state records as immutable, even the applied record.

Parameters
previous: StateRecord the state record that was used to create the applied record and is a state that also (though indirectly) produced the current record.
current: StateRecord the state record of the parent snapshot or global state.
applied: StateRecord the state record that is being applied of the parent snapshot or global state.
Return
the modified state or null if the values cannot be merged. If the states cannot be merged the current apply will fail. Any of the parameters can be returned as a result. If it is not one of the parameter values then it must be a new value that is created by calling StateRecord.create on one of the records passed and then can be modified to have the merged value before being returned. If a new record is returned MutableSnapshot.apply will update the internal snapshot id and call prependStateRecord if the record is used.

prependStateRecord

abstract fun prependStateRecord(value: StateRecord): Unit

Add a new state record to the beginning of a list. After this call firstStateRecord should be value.

Properties

firstStateRecord

abstract val firstStateRecord: StateRecord

The first state record in a linked list of state records.