From 334b028bf65e5700e78bf15d440f5d99688919f6 Mon Sep 17 00:00:00 2001 From: b-ma Date: Wed, 2 Oct 2024 17:55:34 +0200 Subject: [PATCH] doc: document local parameter option --- src/client/ClientContext.js | 4 ++-- src/common/BaseStateManager.js | 6 +++--- src/common/SharedState.js | 6 +++--- src/common/shared-state-types.js | 4 ++++ tests/states/schema-options.spec.js | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/client/ClientContext.js b/src/client/ClientContext.js index 95c0c146..750321f0 100644 --- a/src/client/ClientContext.js +++ b/src/client/ClientContext.js @@ -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) { @@ -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) { diff --git a/src/common/BaseStateManager.js b/src/common/BaseStateManager.js index afd0b6f7..4b253364 100644 --- a/src/common/BaseStateManager.js +++ b/src/common/BaseStateManager.js @@ -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); }); @@ -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); }); @@ -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]; diff --git a/src/common/SharedState.js b/src/common/SharedState.js index afc95407..7cc30cff 100644 --- a/src/common/SharedState.js +++ b/src/common/SharedState.js @@ -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); }); } @@ -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); }); } diff --git a/src/common/shared-state-types.js b/src/common/shared-state-types.js index 2568f705..368dabbe 100644 --- a/src/common/shared-state-types.js +++ b/src/common/shared-state-types.js @@ -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 diff --git a/tests/states/schema-options.spec.js b/tests/states/schema-options.spec.js index 083f6def..533751f1 100644 --- a/tests/states/schema-options.spec.js +++ b/tests/states/schema-options.spec.js @@ -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);