Class: ReactiveState
Provides a syncronized state storage which is accessible in both browser and web worker contexts
Constructors
Constructor
new ReactiveState(namespace: string, secret: string): ReactiveState;Creates a new instance of the ReactiveState class
Parameters
| Parameter | Type | Description |
|---|---|---|
namespace | string | The namespace used to identify the reactive state storage |
secret | string | The secret used to encrypt the values stored in the reactive state storage |
Returns
ReactiveState
Accessors
count
Get Signature
get count(): number;Returns an integer representing the number of records in the reactive state storage
Returns
number
onError
Set Signature
set onError(onError: (error: Error) => void): void;Sets the error handler for the reactive state storage
Parameters
| Parameter | Type | Description |
|---|---|---|
onError | (error: Error) => void | The error handler function |
Returns
void
size
Get Signature
get size(): number;Returns an integer representing the number of records in the reactive state storage
Returns
number
Methods
[iterator]()
iterator: Generator<any[], void, unknown>;The [Symbol.iterator]() method of ReactiveState implements the iterable protocol and allows ReactiveState objects to be consumed by most syntaxes expecting iterables, such as the spread syntax and for...of loops. It returns an iterator object that yields the key-value pairs of the ReactiveState object.
Returns
Generator<any[], void, unknown>
An iterator object that contains the key-value pairs of the ReactiveState object
clear()
clear(): Promise<void>;Clears all values stored in the reactive state storage
Returns
Promise<void>
entries()
entries(): IterableIterator<[string, any]>;Returns a new iterator object that contains the [key, value] pairs for each element in the reactive state storage
Returns
IterableIterator<[string, any]>
An iterator object that contains the [key, value] pairs for each element in the reactive state storage
fetch()
fetch(keys: string[]): Record<string, any>;Retrieves multiple values from the reactive state storage
Parameters
| Parameter | Type | Description |
|---|---|---|
keys | string[] | The keys used to identify the values |
Returns
Record<string, any>
An object with the keys representing the keys requested and their corresponding values in the reactive state storage
forEach()
forEach(callbackfn: (value: any, key: string, map: Map<string, any>) => void, thisArg?: any): void;Executes a provided function once per each key/value pair in this reactive state storage
Parameters
| Parameter | Type | Description |
|---|---|---|
callbackfn | (value: any, key: string, map: Map<string, any>) => void | A function that accepts up to three arguments. The forEach method calls the callbackfn function for each key/value pair in the reactive state storage. |
thisArg? | any | Value to use as this when executing callbackfn |
Returns
void
Remarks
The map object provided to the callback function is a clone of the original map object. This is done to prevent any modifications to the original map object during iteration.
get()
get(key: string): any;Retrieve the value stored in the reactive state storage for the given key
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key used to identify the value |
Returns
any
The value stored in the reactive state storage
has()
has(key: string): boolean;Returns a boolean indicating whether the reactive state storage contains a value for the given key
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key used to identify the value |
Returns
boolean
keys()
keys(): IterableIterator<string>;Returns an iterator object which contains the keys for each element in the reactive state storage
Returns
IterableIterator<string>
An iterator object that contains the keys for each element in the reactive state storage
off()
off(): void;Removes all event listeners from the reactive state storage
Returns
void
offChange()
offChange(callback: (key: string, is: any, was?: any) => void): this;Unsubscribe from changes in the reactive state storage
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | (key: string, is: any, was?: any) => void | A function which is called when the value of the reactive state storage changes |
Returns
this
The current instance of the ReactiveState class
offChangeToKey()
offChangeToKey(key: string, callback: (is: any, was?: any) => void): this;Unsubscribe from changes in the reactive state storage for a specific key
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | - |
callback | (is: any, was?: any) => void | A function which is called when the value of the reactive state storage changes |
Returns
this
The current instance of the ReactiveState class
onceChange()
onceChange(callback: (key: string, is: any, was?: any) => void): this;Subscribe to changes in the reactive state storage once
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | (key: string, is: any, was?: any) => void | A function which is called when the value of the reactive state storage changes |
Returns
this
The current instance of the ReactiveState class
Remarks
This can be called multiple times for multiple callbacks
onceChangeToKey()
onceChangeToKey(key: string, callback: (is: any, was?: any) => void): this;Subscribe to changes in the reactive state storage once for a specific key
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | - |
callback | (is: any, was?: any) => void | A function which is called when the value of the reactive state storage changes |
Returns
this
The current instance of the ReactiveState class
Remarks
This can be called multiple times for multiple callbacks
onChange()
onChange(callback: (key: string, is: any, was?: any) => void): this;Subscribe to changes in the reactive state storage
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | (key: string, is: any, was?: any) => void | A function which is called when the value of the reactive state storage changes |
Returns
this
The current instance of the ReactiveState class
Remarks
This can be called multiple times for multiple callbacks
onChangeToKey()
onChangeToKey(key: string, callback: (is: any, was?: any) => void): this;Subscribe to changes in the reactive state storage for a specific key
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | - |
callback | (is: any, was?: any) => void | A function which is called when the value of the reactive state storage changes |
Returns
this
The current instance of the ReactiveState class
Remarks
This can be called multiple times for multiple callbacks
put()
put(values: {
key: string;
value: any;
}[]): Promise<void>;Stores multiple values in the reactive state storage
Parameters
| Parameter | Type | Description |
|---|---|---|
values | { key: string; value: any; }[] | An array of objects containing the key and value to be stored in the reactive state storage |
Returns
Promise<void>
Remarks
Using the put method is faster and more efficient than using the set method for multiple values
remove()
remove(key: string): Promise<void>;Removes the value stored in the reactive state storage for the given key
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key used to identify the value |
Returns
Promise<void>
set()
set(key: string, value: any): Promise<void>;Stores the value in the reactive state storage for the given key
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | The key used to identify the value |
value | any | The value to be stored in the reactive state storage |
Returns
Promise<void>
Remarks
If you have a large number of values to store, consider using the put method instead
subscribe()
subscribe(observer: Partial<Observer<Record<string, any>[]>>): Subscription;Subscribe to updates from the reactive state storage
Parameters
| Parameter | Type |
|---|---|
observer | Partial<Observer<Record<string, any>[]>> |
Returns
See
rxjs documentation for more information
values()
values(): IterableIterator<any>;Returns an iterator object which contains the values for each element in the reactive state storage
Returns
IterableIterator<any>
An iterator object that contains the values for each element in the reactive state storage