Skip to content

Commit

Permalink
doc: document local parameter option
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ma committed Oct 2, 2024
1 parent 7e97a5a commit 334b028
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/client/ClientContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class ClientContext {
// we need the try/catch block to change the promise rejection into proper error
try {
await new Promise((resolve, reject) => {
const reqId = promiseStore.add(resolve, reject, 'enter-context');
const reqId = promiseStore.add(resolve, reject, 'ClientContext#enter');
this.#client.socket.send(CONTEXT_ENTER_REQUEST, reqId, this.name);
});
} catch (err) {
Expand Down Expand Up @@ -249,7 +249,7 @@ class ClientContext {
// we need the try/catch block to change the promise rejection into proper error
try {
await new Promise((resolve, reject) => {
const reqId = promiseStore.add(resolve, reject, 'exit-context');
const reqId = promiseStore.add(resolve, reject, 'ClientContext#exit');
this.#client.socket.send(CONTEXT_EXIT_REQUEST, reqId, this.name);
});
} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions src/common/BaseStateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class BaseStateManager {
}

return new Promise((resolve, reject) => {
const reqId = this.#promiseStore.add(resolve, reject, 'create-request');
const reqId = this.#promiseStore.add(resolve, reject, 'BaseStateManager#create');
const requireDescription = this.#cachedClasses.has(className) ? false : true;
this[kStateManagerClient].transport.emit(CREATE_REQUEST, reqId, className, requireDescription, initValues);
});
Expand Down Expand Up @@ -376,7 +376,7 @@ class BaseStateManager {
}

return new Promise((resolve, reject) => {
const reqId = this.#promiseStore.add(resolve, reject, 'attach-request');
const reqId = this.#promiseStore.add(resolve, reject, 'BaseStateManager#attach');
const requireDescription = this.#cachedClasses.has(className) ? false : true;
this[kStateManagerClient].transport.emit(ATTACH_REQUEST, reqId, className, stateId, requireDescription, filter);
});
Expand Down Expand Up @@ -559,7 +559,7 @@ class BaseStateManager {

// resend request to get updated list of states
return new Promise((resolve, reject) => {
const reqId = this.#promiseStore.add(resolve, reject, 'observe-request');
const reqId = this.#promiseStore.add(resolve, reject, 'BaseStateManager#observe');
// store the callback for execution on the response. the returned Promise
// is fullfiled once callback has been executed with each existing states
const observeInfos = [observedClassName, callback, options];
Expand Down
6 changes: 3 additions & 3 deletions src/common/SharedState.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ ${JSON.stringify(initValues, null, 2)}`);

// go through server-side normal behavior
return new Promise((resolve, reject) => {
const reqId = this[kSharedStatePromiseStore].add(resolve, reject, 'update-request', forwardParams);
const reqId = this[kSharedStatePromiseStore].add(resolve, reject, 'SharedState#set', forwardParams);
this.#client.transport.emit(`${UPDATE_REQUEST}-${this.#id}-${this.#remoteId}`, reqId, updates, context);
});
}
Expand Down Expand Up @@ -675,12 +675,12 @@ ${JSON.stringify(initValues, null, 2)}`);

if (this.#isOwner) {
return new Promise((resolve, reject) => {
const reqId = this[kSharedStatePromiseStore].add(resolve, reject, 'delete-request');
const reqId = this[kSharedStatePromiseStore].add(resolve, reject, 'SharedState#delete');
this.#client.transport.emit(`${DELETE_REQUEST}-${this.#id}-${this.#remoteId}`, reqId);
});
} else {
return new Promise((resolve, reject) => {
const reqId = this[kSharedStatePromiseStore].add(resolve, reject, 'detach-request');
const reqId = this[kSharedStatePromiseStore].add(resolve, reject, 'SharedState#detach');
this.#client.transport.emit(`${DETACH_REQUEST}-${this.#id}-${this.#remoteId}`, reqId);
});
}
Expand Down
4 changes: 4 additions & 0 deletions src/common/shared-state-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
* latency on the client.
* If for some reason the value is overriden server-side (e.g. in an `updateHook`)
* the listeners will be called again when the "real" value is received.
* @property {boolean} [local=false] - When set to true, the parameter is never
* propagated on the network (hence it is no longer a shared parameter :). This
* is usefull to declare some common parameter (e.g. some interface state) that
* don't need to be shared but to stay in the shared state API paradigm.
* @property {number} [min=-Number.MIN_VALUE] - Minimum value of the parameter. Only applies
* for `integer` and `float` types.
* @property {number} [max=Number.MAX_VALUE] - Maximum value of the parameter. Only applies
Expand Down
2 changes: 1 addition & 1 deletion tests/states/schema-options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ describe('# SharedState - schema options', () => {
await server.stop();
});

it('[local=true] mixed with regular param', async () => {
it('[local=true] mixed with regular param', async () => {
const localConfig = structuredClone(config);
localConfig.env.port = 8082;
const server = new Server(localConfig);
Expand Down

0 comments on commit 334b028

Please sign in to comment.