---
title: "StateObject"
description: "Interface implemented by all snapshot aware state objects. Used by this module to maintain the
state records of a state object."
type: "interface"
---

<div class='type'>Interface</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>



```kotlin
@JvmDefaultWithCompatibility
public interface StateObject
```


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


## Functions

```kotlin
public fun prependStateRecord(value: StateRecord)
```


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


```kotlin
public 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 | the state record that was used to create the `applied` record and is a state that also (though indirectly) produced the `current` record. |
| current | the state record of the parent snapshot or global state. |
| applied | the state record that is being applied of the parent snapshot or global state. |


#### Returns

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




