Constructor
new State()
Creates an instance of State
Example
const initialContainerState = {
'foo': 'bar'
}
State.initContainer('CONTAINER', initialContainerState)
const foo = State.get('CONTAINER.foo') // = 'bar'
Methods
clear()
Clear all containers
destroyContainer(containerId)
Destroy a container
Parameters:
Name | Type | Description |
---|---|---|
containerId |
string | Container id |
Throws:
-
Cannot destroy a container that does not exist
- Type
- Error
get(query) → {any}
Get a value
Parameters:
Name | Type | Description |
---|---|---|
query |
string | Query string |
Throws:
-
Cannot get a value from a container that does not exist
- Type
- Error
Returns:
Value
- Type
- any
has(query) → {boolean}
Has a value
Parameters:
Name | Type | Description |
---|---|---|
query |
string | Query string |
Returns:
True if a value is found, false otherwise
- Type
- boolean
initContainer(containerId, value)
Initialize a container
Parameters:
Name | Type | Description |
---|---|---|
containerId |
string | Container id |
value |
object | Object to initialize the container |
Throws:
-
Second argument must be an Object
- Type
- TypeError
onChange(query, callback)
Add a callback on value change
Parameters:
Name | Type | Description |
---|---|---|
query |
string | Query string |
callback |
function | Callback |
Throws:
-
-
Second argument must be a Function
- Type
- TypeError
-
-
-
Cannot add a change callback on a container that does not exist
- Type
- Error
-
removeChangeCallback(query, callback)
Remove callback on change
Parameters:
Name | Type | Description |
---|---|---|
query |
string | Query string |
callback |
function | Callback |
Throws:
-
-
Second argument must be a Function
- Type
- TypeError
-
-
-
Cannot remove a change callback on a container that does not exist
- Type
- Error
-
-
-
No signal found to remove a change callback with query : 'CONTAINER.query'
- Type
- Error
-
set(query, value, overwriteopt)
Set a value
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
query |
string | Query string |
||
value |
any | Value to set |
||
overwrite |
boolean |
<optional> |
false | Flag to overwrite an object |
Throws:
-
Cannot set a value on a container that does not exist
- Type
- Error