Skip to content
On this page

State Store

Pinia store that tracks the application state using object hashing. Emits the load when a state is loaded and the change event when the data changes.

State

NameDescriptionTypeValuesDefault
datacurrent application stateobject-null
historyhistory of statesarray-[]
historySizehistory sizenumber-25
dataChangewhether the state has changed since last requestboolean-false
dataChangeTimelast time a data change was recordednumber-Date.now()

Getters

hash

Returns the hash for the current state.
@returns hash

Methods

calcHash

Calculates the hash of the current application state.
@param {Object} data - the data to calculate a hash for
@returns hash

checkChanges

Check whether state has changed and set dataChange if so.
@returns dataChange

on

Registers an event listener for state events.
@param {String} event - event name
@param {Function} func - callback
@returns handle for event removal

off

Removes an event listener.
@param {String} event - event name
@param {Number} id - event handler id

setData

Update the application state.
@param {object} data
@param {boolean} check - whether to check for changes

loadState

Load the application state from state. If callback is not null, it is called with the current state.
@param {object} state

resetDataChange

Sets dataChange to false.

exportState

Exports the current application state (stringified to prevent Vue Proxy effects) and hash.
@param {boolean} reset - whether to reset dataChange
@returns { state: "...", hash: "..." }

clear

Sets data and hash to null and clears the history.