new StateHolder(states, initialState)
Keep state among known ones
Parameters:
Name | Type | Description |
---|---|---|
states |
Object | An Object representing states |
initialState |
string | A state picked from states |
Example
var states = { READ: 'READ', ERROR: 'ERROR', CREATE: 'CREATE', UPDATE: 'UPDATE', DELETE: 'DELETE' }; var initialState = states.READ; var stateHolder = new StateHolder(initialState, states); console.log(stateHolder.$current === states.READ); // true stateHolder.set(states.CREATE) console.log(stateHolder.$current === states.CREATE); // true
Methods
-
<static> StateHolder#load()
-
Load all given states into itself All states are upper-cased before being set.
Returns:
this
-
<static> StateHolder#set(state)
-
Set a state picked from
states
referenceParameters:
Name Type Description state
string A state picked from states
Returns:
this