State

State

State class

Constructor

new State()

Creates an instance of State

Author:
License:
Source:
Example
const initialContainerState = {
  'foo': 'bar'
}

State.initContainer('CONTAINER', initialContainerState)
const foo = State.get('CONTAINER.foo') // = 'bar'

Methods

clear()

Clear all containers

Source:

destroyContainer(containerId)

Destroy a container

Parameters:
Name Type Description
containerId string

Container id

Source:
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

Source:
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

Source:
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

Source:
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

Source:
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

Source:
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

Source:
Throws:

Cannot set a value on a container that does not exist

Type
Error