SipaState
SipaState
Tool class to store global states at different persistence levels.
Level 1 (variable): Data will be lost after reload (SipaState.LEVEL.VARIABLE) You can even store references and functions!
Level 2 (session): Data will be lost when browser is closed (SipaState.LEVEL.SESSION) You can not store references but thanks to SipaSerializer isolated functions are possible!
Level 3 (storage): Data will be lost when clearing browser cache only (SipaState.LEVEL.STORAGE) You can not store references but thanks to SipaSerializer isolated functions are possible!
- SipaState
- .set(key, value, options)
- .setVariable(key, value, options)
- .setSession(key, value, options)
- .setStorage(key, value, options)
- .getLevel(key) →
SipaState.LEVEL
|null
- .hasKey(key) →
boolean
- .get(key)
- .getVariables() →
Object.<String, any>
- .getSession() →
Object.<String, any>
- .getStorage() →
Object.<String, any>
- .getAll() →
Object.<String, any>
- .getKeys() →
Array.<String>
- .remove(key) →
boolean
- .removeAll() →
boolean
- .reset() →
boolean
- .Level :
'variable'
|'session'
|'storage'
SipaState.set(key, value, options)
Set a value with the given persistence level, by default SipaState.LEVEL.SESSION
Param | Type | Default | Description |
---|---|---|---|
key | string | ||
value | any | ||
options | object | ||
options.level | Level | 'session' | |
options.force | boolean | false | overwrite value, if it is set at another level already |
SipaState.setVariable(key, value, options)
Set value in persistence level 1 (variable)
Param | Type | Default | Description |
---|---|---|---|
key | string | ||
value | any | ||
options | object | ||
options.force | boolean | false | overwrite value without throwing error, if it is set at another level already |
SipaState.setSession(key, value, options)
Set value in persistence level 2 (session)
Param | Type | Default | Description |
---|---|---|---|
key | string | ||
value | any | ||
options | object | ||
options.force | boolean | false | overwrite value without throwing error, if it is set at another level already |
SipaState.setStorage(key, value, options)
Set value in persistence level 3 (storage)
Param | Type | Default | Description |
---|---|---|---|
key | string | ||
value | any | ||
options | object | ||
options.force | boolean | false | overwrite value without throwing error, if it is set at another level already |
SipaState.getLevel(key) → SipaState.LEVEL
| null
Get the persistence level of the value stored at the given key. If key is not set at any level, returns null.
Param | Type |
---|---|
key | string |
SipaState.hasKey(key) → boolean
Check if key is set already at any persistence level
Param | Type |
---|---|
key | string |
SipaState.get(key)
Get the value of the given key. Persistence level does not matter and is implicit.
Param | Type |
---|---|
key | string |
SipaState.getVariables() → Object.<String, any>
Get all entries of persistence level 1 (variables)
SipaState.getSession() → Object.<String, any>
Get all entries of persistence level 2 (session)
SipaState.getStorage() → Object.<String, any>
Get all entries of persistence level 3 (storage)
SipaState.getAll() → Object.<String, any>
Get all stored entries
SipaState.getKeys() → Array.<String>
Get all keys
SipaState.remove(key) → boolean
Remove the stored value of the given key(s)
Returns: boolean
- true if value of any key was set and has been removed. False if no key did exist.
Param | Type | Description |
---|---|---|
key | string | Array | key or keys to remove |
SipaState.removeAll() → boolean
Delete all stored data - alias method for reset()
Returns: boolean
- true if one or more entries have been deleted
SipaState.reset() → boolean
Delete all stored data
Returns: boolean
- true if one or more entries have been deleted
SipaState.Level : 'variable'
| 'session'
| 'storage'
Kind: static typedef of SipaState