Skip to content

Commit

Permalink
refactor: get rid of schema semantics (tbc...)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ma committed Oct 2, 2024
1 parent 3311196 commit 4a629f6
Show file tree
Hide file tree
Showing 4 changed files with 708 additions and 20 deletions.
16 changes: 8 additions & 8 deletions src/common/BaseStateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
OBSERVE_ERROR,
OBSERVE_NOTIFICATION,
UNOBSERVE_NOTIFICATION,
DELETE_SCHEMA,
GET_SCHEMA_REQUEST,
GET_SCHEMA_RESPONSE,
GET_SCHEMA_ERROR,
DELETE_SHARED_STATE_CLASS,
GET_CLASS_DESCRIPTION_REQUEST,
GET_CLASS_DESCRIPTION_RESPONSE,
GET_CLASS_DESCRIPTION_ERROR,
} from './constants.js';

export const kStateManagerInit = Symbol('soundworks:state-manager-init');
Expand Down Expand Up @@ -194,14 +194,14 @@ class BaseStateManager {
// ---------------------------------------------
// Clear cache when a shared state class is deleted
// ---------------------------------------------
this[kStateManagerClient].transport.addListener(DELETE_SCHEMA, className => {
this[kStateManagerClient].transport.addListener(DELETE_SHARED_STATE_CLASS, className => {
this.#cachedClasses.delete(className);
});

// ---------------------------------------------
// Get class description
// ---------------------------------------------
this[kStateManagerClient].transport.addListener(GET_SCHEMA_RESPONSE, (reqId, className, classDescription) => {
this[kStateManagerClient].transport.addListener(GET_CLASS_DESCRIPTION_RESPONSE, (reqId, className, classDescription) => {
if (!this.#cachedClasses.has(className)) {
this.#cachedClasses.set(className, classDescription);
}
Expand All @@ -210,7 +210,7 @@ class BaseStateManager {
this.#promiseStore.resolve(reqId, parameterBag.getDescription());
});

this[kStateManagerClient].transport.addListener(GET_SCHEMA_ERROR, (reqId, msg) => {
this[kStateManagerClient].transport.addListener(GET_CLASS_DESCRIPTION_ERROR, (reqId, msg) => {
this.#promiseStore.reject(reqId, msg);
});

Expand Down Expand Up @@ -240,7 +240,7 @@ class BaseStateManager {

return new Promise((resolve, reject) => {
const reqId = this.#promiseStore.add(resolve, reject, 'get-schema');
this[kStateManagerClient].transport.emit(GET_SCHEMA_REQUEST, reqId, className);
this[kStateManagerClient].transport.emit(GET_CLASS_DESCRIPTION_REQUEST, reqId, className);
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export const UPDATE_RESPONSE = 's:u:res';
export const UPDATE_ABORT = 's:u:ab';
export const UPDATE_NOTIFICATION = 's:u:not';

export const DELETE_SCHEMA = 's:d:s';
export const DELETE_SHARED_STATE_CLASS = 's:d:s';

export const GET_SCHEMA_REQUEST = 's:s:req';
export const GET_SCHEMA_RESPONSE = 's:s:res';
export const GET_SCHEMA_ERROR = 's:s:err';
export const GET_CLASS_DESCRIPTION_REQUEST = 's:s:req';
export const GET_CLASS_DESCRIPTION_RESPONSE = 's:s:res';
export const GET_CLASS_DESCRIPTION_ERROR = 's:s:err';

// context channels
export const CONTEXT_ENTER_REQUEST = 'c:en:req';
Expand Down
16 changes: 8 additions & 8 deletions src/server/ServerStateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
OBSERVE_ERROR,
OBSERVE_NOTIFICATION,
UNOBSERVE_NOTIFICATION,
DELETE_SCHEMA,
GET_SCHEMA_REQUEST,
GET_SCHEMA_RESPONSE,
GET_SCHEMA_ERROR,
DELETE_SHARED_STATE_CLASS,
GET_CLASS_DESCRIPTION_REQUEST,
GET_CLASS_DESCRIPTION_RESPONSE,
GET_CLASS_DESCRIPTION_ERROR,
PRIVATE_STATES,
} from '../common/constants.js';

Expand Down Expand Up @@ -317,13 +317,13 @@ class ServerStateManager extends BaseStateManager {
// ---------------------------------------------
// GET SCHEMA
// ---------------------------------------------
client.transport.addListener(GET_SCHEMA_REQUEST, (reqId, className) => {
client.transport.addListener(GET_CLASS_DESCRIPTION_REQUEST, (reqId, className) => {
if (this.#classes.has(className)) {
const classDescription = this.#classes.get(className);
client.transport.emit(GET_SCHEMA_RESPONSE, reqId, className, classDescription);
client.transport.emit(GET_CLASS_DESCRIPTION_RESPONSE, reqId, className, classDescription);
} else {
const msg = `[stateManager] Cannot get class "${className}", class does not exists`;
client.transport.emit(GET_SCHEMA_ERROR, reqId, msg);
client.transport.emit(GET_CLASS_DESCRIPTION_ERROR, reqId, msg);
}
});
}
Expand Down Expand Up @@ -453,7 +453,7 @@ class ServerStateManager extends BaseStateManager {

// clear class cache of all connected clients
for (let client of this[kStateManagerClientsByNodeId].values()) {
client.transport.emit(`${DELETE_SCHEMA}`, className);
client.transport.emit(`${DELETE_SHARED_STATE_CLASS}`, className);
}

this.#classes.delete(className);
Expand Down
Loading

0 comments on commit 4a629f6

Please sign in to comment.