Class Item

About 1 min

Class Item

Declared in packages/core/echo/echo-db/dist/types/src/packlets/database/item.d.ts:24

A globally addressable data item. Items are hermetic data structures contained within a Space. They may be hierarchical. The Item data structure is governed by a Model class, which implements data consistency.

Manages the state machine lifecycle. Snapshots represent the reified state of a set of mutations up until at a particular Timeframe. The state machine maintains a queue of optimistic and committed mutations as they are written to the output stream. Each mutation written to the stream gets a receipt the provides an async callback when the message is written to the store. If another mutation is written to the store ahead of the optimistic mutation, then the state machine is rolled back to the previous snapshot, and the ordered set of mutations since that point is replayed.

The state of the model is formed from the following components (in order):

  • The custom snapshot from the initial state.
  • The snapshot mutations from the initial state.
  • The mutatation queue.
  • Optimistic mutations.

Constructors

constructor(_itemManager, _id)

Items are constructed by the Database object.

Returns: Item<M>

Arguments:

_itemManager: ItemManager

_id: string

Properties

_debugLabel

Type: undefined | string

_itemManager

Type: ItemManager

_modelMeta

Type: "null" | ModelMeta<any, any, any>

deleted

Type: boolean

id

Type: string

initialized

Type: boolean

modelMeta

Type: undefined | ModelMeta<any, any, any>

modelType

Type: string

parent

Type: "null" | string

state

Type: StateOf<M>

Methods

createSnapshot()

Create a snapshot of the current state.

Returns: EchoObject

Arguments: none

initialize(modelConstructor)

Perform late intitalization.

Only possible if the modelContructor wasn't passed during StateManager's creation.

Returns: void

Arguments:

modelConstructor: ModelConstructor<M>

processMessage(mutation)

Processes mutations from the inbound stream.

Returns: void

Arguments:

mutation: Mutation

processOptimisticMutation(mutation)

Returns: void

Arguments:

mutation: Mutation

resetToSnapshot(snapshot)

Reset the state to existing snapshot.

Returns: void

Arguments:

snapshot: EchoObject

toString()

Returns: string

Arguments: none