Skip to main content

StateInstance

view on npm

A trackable State

.id

The internal id of the state

.instanceId

The internal id of the state with an instance prefix

.name

Set the name of the state for internal tracking

.name

The name of the state (NOTE: set with the .name(name) function)

.value

The value of the state

.lastValue

The previous (reactive) value of the state

.nextValue

The next value to apply to the state This is normally managed internally, but you can use it to "prepare" the state before applying the value.

Example

state.nextValue = { foo: 'bar' }
state.set() // The state will be { foo: "bar" }

.initialValue

The initial (default) value of the state

.set(value)

Set the value of the state

ParamDescription
value

The new value of this state

.patch(value)

Patch the current value of the state

ParamDescription
value

A value of the state to merge with the current value

.watch(callback, from) ⇒

Watch for changes on this state

Returns:

The remove function to stop watching

ParamDescription
callback

The callback to run when the state changes

from

(optional) The id of the watcher

.persist(name)

Persist the state to selected storage

ParamDescription
name

The storage prefix to use

.reset()

Reset the state to the initial value

.interval(setterFunction, ms)

On a set interval, run a function to update the state

ParamDescription
setterFunction

The function used to update the state on the interval; returns the new value

ms

The interval duration (in milliseconds)

.clearInterval()

Stop the state interval

.key()

Deprecated

Set the key of the state for internal tracking