StateObject

Known direct subclasses
SnapshotStateList

An implementation of MutableList that can be observed and snapshot.

SnapshotStateMap

An implementation of MutableMap that can be observed and snapshot.

SnapshotStateSet

An implementation of MutableSet that can be observed and snapshot.


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

Summary

Public functions

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

Produce a merged state based on the conflicting state changes.

Cmn
Unit

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

Cmn

Public properties

StateRecord

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

Cmn

Public functions

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.

Returns
StateRecord?

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

fun prependStateRecord(value: StateRecord): Unit

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

Public properties

firstStateRecord

val firstStateRecordStateRecord

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