API
Here's the API documentation for the utility stores module.
Store class
Use this class if you wish to store a value under an unnamed store. This class can act as a "global" store.
set(key, value)
Sets a value in the store with the specified key.
- Throws an
Error
if the key is empty.
Prop | Type | Default |
---|---|---|
key | string | - |
value | any | - |
get(key)
Gets a value from the store by the specified key.
- Returns the value associated with the key or
undefined
if the key does not exist. - Throws an
Error
if the key is empty.
Prop | Type | Default |
---|---|---|
key | string | - |
delete(key)
Deletes a value from the store by the specified key.
- Throws an
Error
if the key is empty.
Prop | Type | Default |
---|---|---|
key | string | - |
addListener(key, callback)
Adds a listener for changes to the specified key.
- Throws an
Error
if the key is empty.
Prop | Type | Default |
---|---|---|
key | string | - |
callback | function | - |
removeListener()
Removes a listener for changes to the specified key.
- Throws an
Error
if the key is empty.
Prop | Type | Default |
---|---|---|
key | string | - |
callback | function | - |
NamedStores class
Use this class to create named stores. Named stores can be useful to categorize your datas and to easily manage them.
Prop | Type | Default |
---|---|---|
name | string | - |
createStore(name)
Creates a new store with the specified name.
- Returns the created
Store
instance. - Throws an
Error
if the name is empty or already exists.
Prop | Type | Default |
---|---|---|
name | string | - |
getStore()
Gets a store by the specified name.
- Returns the
Store
instance associated with the name. - Throws an
Error
if the name is empty or does not exist.
Prop | Type | Default |
---|---|---|
name | string | - |
deleteStore()
Deletes a store by the specified name.
- Throws an
Error
if the name is empty or does not exist.
Prop | Type | Default |
---|---|---|
name | string | - |
Note when using the NamedStore class
After creating a named store, it will return an instance of the Store
class. Therefore, you can use the exact function of the Store
class to set, retrieve, delete, etc, to the created named store.
Last updated on