Constructor
new SharedStateManagerClient(id, transport)
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | Id of the node. |
transport |
Object | Transport to use for synchronizing the state. Must implement a basic EventEmitter API. |
Methods
(async) attach(schemaName, stateIdopt)
- Source:
- See:
Attach to an existing common.SharedState instance.
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 |
Returns:
(async) create(schemaName, initValuesopt)
- Source:
- See:
Create a common.SharedState instance from a previsouly registered 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:
observe(callback)
Observe all the common.SharedState instances that are created on the network.
Example
this.client.stateManager.observe(async (schemaName, stateId, nodeId) => {
if (schemaName === 'something') {
const state = await this.client.stateManager.attach(schemaName, stateId);
console.log(state.getValues());
}
});
Parameters:
Name | Type | Description |
---|---|---|
callback |
client.SharedStateManagerClient~observeCallback | Function to be called when a new state is created on the network. |
Type Definitions
(async) observeCallback(schemaName, stateId, nodeId)
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 |