Extends
Methods
(async) attach(schemaName, stateIdopt, filteropt) → {client.SharedState|server.SharedState}
- Description:
Attach to an existing
SharedState
instance.Alternative signatures:
stateManager.attach(schemaName)
stateManager.attach(schemaName, stateId)
stateManager.attach(schemaName, filter)
stateManager.attach(schemaName, stateId, filter)
- Source:
- Inherited From:
- See:
Example
const state = await client.stateManager.attach('my-schema');
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
schemaName |
String | Name of the schema as given on registration (cf. ServerStateManager) |
||
stateId |
Object |
<optional> |
null
|
Id of the state to attach to. If |
filter |
array | null |
<optional> |
null
|
Filter parameters of interest in the
returned state. If set to |
Returns:
(async) create(schemaName, initValuesopt) → {client.SharedState|server.SharedState}
- Description:
Create a
SharedState
instance from a registered schema.
- Source:
- Inherited From:
- See:
Example
const state = await client.stateManager.create('my-schema');
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
schemaName |
String | Name of the schema as given on registration (cf. ServerStateManager) |
||
initValues |
Object |
<optional> |
{}
|
Default values for the state. |
Returns:
(async) getCollection(schemaName, filteropt, optionsopt) → {server.SharedStateCollection|client.SharedStateCollection}
- Description:
Returns a collection of all the states created from the schema name.
Alternitive signatures:
stateManager.getCollection(schemaName)
stateManager.getCollection(schemaName, filter)
stateManager.getCollection(schemaName, options)
stateManager.getCollection(schemaName, filter, options)
- Source:
- Inherited From:
Example
const collection = await client.stateManager.getCollection(schemaName);
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
schemaName |
string | Name of the schema. |
||||||||||||
filter |
array | null |
<optional> |
null
|
Filter parameter of interest for each
state of the collection. If set to |
||||||||||
options |
object |
<optional> |
{}
|
Options. Properties
|
Returns:
(async) getSchema(schemaName)
- Description:
Return the schema from a given registered schema name
- Source:
- Inherited From:
Example
const schema = await client.stateManager.getSchema('my-schema');
Parameters:
Name | Type | Description |
---|---|---|
schemaName |
String | Name of the schema as given on registration (cf. ServerStateManager) |
(async) observe(schemaNameopt, callback, options) → {Promise:.<function()>}
- Description:
Observe all the
SharedState
instances that are created on the network. This can be usefull for clients with some controller role that might want to track the state of all other clients of the application, to monitor them and/or take control over them from a single point.Notes:
- The order of execution is not guaranted between nodes, i.e. an state attached
in the
observe
callback could be created before theasync create
method resolves. - Filtering, i.e.
observedSchemaName
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 share the observe notifications between all observers.
Alternative signatures:
stateManager.observe(callback)
stateManager.observe(schemaName, callback)
stateManager.observe(callback, options)
stateManager.observe(schemaName, callback, options)
- The order of execution is not guaranted between nodes, i.e. an state attached
in the
- Source:
- Inherited From:
Example
client.stateManager.observe(async (schemaName, stateId) => {
if (schemaName === 'something') {
const state = await this.client.stateManager.attach(schemaName, stateId);
console.log(state.getValues());
}
});
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
schemaName |
string |
<optional> |
optionnal schema name to filter the observed states. |
||||||||||
callback |
server.StateManager~ObserveCallback | client.StateManager~ObserveCallback | 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 Definitions
(async) ObserveCallback(schemaName, stateId, nodeId)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
schemaName |
String | name of the schema |
stateId |
Number | id of the state |
nodeId |
Number | id of the node that created the state |