Extends
Methods
(async) attach(className, stateIdOrFilteropt, filteropt) → {Promise.<SharedState>}
- Description:
Attach to an existing SharedState instance.
Alternative signatures:
stateManager.attach(className)
stateManager.attach(className, stateId)
stateManager.attach(className, filter)
stateManager.attach(className, stateId, filter)
- Source:
- Inherited From:
Example
const state = await client.stateManager.attach('my-class');
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
className |
SharedStateClassName | Name of the class. |
||
stateIdOrFilter |
number | Array.<string> |
<optional> |
null
|
Id of the state to attach to. If |
filter |
Array.<string> |
<optional> |
null
|
List of parameters of interest in the
returned state. If set to |
Returns:
- Type
- Promise.<SharedState>
(async) create(className, initValuesopt) → {Promise.<SharedState>}
- Description:
Create a SharedState instance from a registered class.
- Source:
- Inherited From:
Example
const state = await client.stateManager.create('my-class');
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
className |
SharedStateClassName | Name of the class. |
||
initValues |
Object.<string, any> |
<optional> |
{}
|
Default values of the created shared state. |
Returns:
- Type
- Promise.<SharedState>
(async) getClassDescription(className) → {SharedStateClassDescription}
- Description:
Return a class description from a given class name
- Source:
- Inherited From:
Example
const classDescription = await client.stateManager.getClassDescription('my-class');
Parameters:
Name | Type | Description |
---|---|---|
className |
SharedStateClassName | Name of the shared state class. (cf. ServerStateManager) |
Returns:
(async) getCollection(className, filteropt, optionsopt) → {Promise.<SharedStateCollection>}
- Description:
Returns a collection of all the states created from a given shared state class.
Alternative signatures:
stateManager.getCollection(className)
stateManager.getCollection(className, filter)
stateManager.getCollection(className, options)
stateManager.getCollection(className, filter, options)
- Source:
- Inherited From:
Example
const collection = await client.stateManager.getCollection(className);
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
className |
SharedStateClassName | Name of the shared state class. |
||||||||||||
filter |
array | null |
<optional> |
null
|
Filter parameter of interest for each
state of the collection. If set to |
||||||||||
options |
object |
<optional> |
{}
|
Options. Properties
|
Returns:
- Type
- Promise.<SharedStateCollection>
(async) getSchema()
- Source:
- Inherited From:
- Deprecated:
- Use BaseStateManager#getClassDescription instead.
(async) observe(classNameopt, callback, options) → {Promise.<stateManagerDeleteObserveCallback>}
- Description:
Observe all the SharedState instances that are created on the network.
Notes:
- The order of execution is not guaranteed between nodes, i.e. a state attached
in the
observe
callback can be instantiated before theasync create
method resolves on the creator node. - Filtering, i.e.
observedClassName
andoptions.excludeLocal
are handled on the node side, the server just notify all state creation activity and the node executes the given callbacks according to the different filter rules. Such strategy allows to simply share the observe notifications between all observers.
Alternative signatures:
stateManager.observe(callback)
stateManager.observe(className, callback)
stateManager.observe(callback, options)
stateManager.observe(className, callback, options)
- The order of execution is not guaranteed between nodes, i.e. a state attached
in the
- Source:
- Inherited From:
Example
client.stateManager.observe(async (className, stateId) => {
if (className === 'my-shared-state-class') {
const attached = await client.stateManager.attach(className, stateId);
}
});
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
className |
SharedStateClassName |
<optional> |
Optional class name to filter the observed states. |
||||||||||
callback |
stateManagerObserveCallback | Function to be called when a new state is created on the network. |
|||||||||||
options |
object | Options. Properties
|
Returns:
- Returns a Promise that resolves when the given callback as been executed on each existing states. The promise value is a function which allows to stop observing the states on the network.
- Type
- Promise.<stateManagerDeleteObserveCallback>
Type Definitions
(async) ObserveCallback(className, stateId, nodeId)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
className |
String | Name of the shared state class. |
stateId |
Number | Id of the state. |
nodeId |
Number | Id of the node that created the state. |