Skip to content

Commit

Permalink
breaking: rename ServerStateManager#registerSchema to `ServerStateM…
Browse files Browse the repository at this point in the history
…anager#defineClass`
  • Loading branch information
b-ma committed Oct 2, 2024
1 parent 17d104d commit 7e97a5a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
17 changes: 11 additions & 6 deletions src/server/ServerStateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,12 @@ class ServerStateManager extends BaseStateManager {
/**
* Delete a whole class of {@link ShareState}.
*
* All {@link SharedState} instance that belong to this class are deleted
* as well. The `onDetach` and `onDelete` callbacks of existing {@link SharedState}
* instances will be called.
*
* _In a future revision, this method and its arguments will be renamed_
* All {@link SharedState} instances created from this class will be deleted
* as well, triggering their eventual `onDetach` and `onDelete` callbacks.
*
* @param {SharedStateClassName} className - Name of the shared state class to delete.
*/
deleteSchema(className) {
deleteClass(className) {
// @note: deleting schema
for (let [_, state] of this.#sharedStatePrivateById) {
if (state.className === className) {
Expand All @@ -469,6 +466,14 @@ class ServerStateManager extends BaseStateManager {
this.#hooksByClassName.delete(className);
}

/**
* @deprecated Use {@link ServerStateManager#defineClass} instead.
*/
deleteSchema(className) {
logger.deprecated('ServerStateManager#deleteSchema', 'ServerStateManager#deleteClass', '4.0.0-alpha.29');
this.deleteClass(className);
}

/**
* Register a function for a given shared state class the be executed between
* `set` instructions and `onUpdate` callback(s).
Expand Down
10 changes: 5 additions & 5 deletions tests/misc/deprecated.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('# deprecated API', () => {
const state = await server.stateManager.create('a');
assert.equal(state.className, 'a'); // actual
assert.equal(state.schemaName, 'a'); // deprecated
server.stateManager.deleteSchema('a');
server.stateManager.deleteClass('a');
await server.stop();
});

Expand All @@ -28,7 +28,7 @@ describe('# deprecated API', () => {
const collection = await server.stateManager.getCollection('a');
assert.equal(collection.className, 'a'); // actual
assert.equal(collection.schemaName, 'a'); // deprecated
server.stateManager.deleteSchema('a');
server.stateManager.deleteClass('a');
await server.stop();
});

Expand All @@ -40,7 +40,7 @@ describe('# deprecated API', () => {
const state = await server.stateManager.create('a');
assert.deepEqual(state.getDescription(), aExpectedDescription); // actual
assert.deepEqual(state.getSchema(), aExpectedDescription); // deprecated
server.stateManager.deleteSchema('a');
server.stateManager.deleteClass('a');
await server.stop();
});

Expand All @@ -52,7 +52,7 @@ describe('# deprecated API', () => {
const collection = await server.stateManager.getCollection('a');
assert.deepEqual(collection.getDescription(), aExpectedDescription); // actual
assert.deepEqual(collection.getSchema(), aExpectedDescription); // deprecated
server.stateManager.deleteSchema('a');
server.stateManager.deleteClass('a');
await server.stop();
});

Expand All @@ -67,7 +67,7 @@ describe('# deprecated API', () => {
const schema = await server.stateManager.getSchema('a'); // deprecated
assert.deepEqual(schema, aExpectedDescription);

server.stateManager.deleteSchema('a');
server.stateManager.deleteClass('a');
await server.stop();
});
});
Expand Down
2 changes: 1 addition & 1 deletion tests/states/SharedState.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ describe('# SharedState', () => {
await delay(10);

assert.equal(onUpdateCalled, true);
server.stateManager.deleteSchema('with-event');
server.stateManager.deleteClass('with-event');
});

it('should copy stored value for "any" type to have a predictable behavior', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/states/SharedStateCollection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ describe(`# SharedStateCollection`, () => {
await delay(10);

assert.equal(onUpdateCalled, true);
server.stateManager.deleteSchema('with-event');
server.stateManager.deleteClass('with-event');
});

});
Expand Down
40 changes: 20 additions & 20 deletions tests/states/StateManager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ describe(`# StateManager`, () => {
});
});

describe('## [server] deleteSchema(name)', () => {
describe('## [server] deleteClass(name)', () => {
it('should call state.onDetach and state.onDelete on all states of its kind', async () => {
server.stateManager.defineClass('a-delete', a);

Expand All @@ -288,7 +288,7 @@ describe(`# StateManager`, () => {
state.onDelete(() => deleteCalled[index] = true);
});

server.stateManager.deleteSchema('a-delete');
server.stateManager.deleteClass('a-delete');

setTimeout(() => {
assert.deepEqual([true, true, true, true], detachCalled);
Expand All @@ -310,7 +310,7 @@ describe(`# StateManager`, () => {
deleteCalled = true;
});

server.stateManager.deleteSchema('a-delete-observe');
server.stateManager.deleteClass('a-delete-observe');
await delay(10);

assert.equal(deleteCalled, true);
Expand Down Expand Up @@ -765,10 +765,10 @@ describe(`# StateManager`, () => {
// @todo - review, this is weird
try {
await Promise.all([serverPromise, clientPromise]);
server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
return Promise.resolve();
} catch(err) {
server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
return Promise.reject(err);
}
});
Expand All @@ -792,7 +792,7 @@ describe(`# StateManager`, () => {

await h.set({ name: 'test' }, { myContext: true });

server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
});
});

Expand All @@ -814,10 +814,10 @@ describe(`# StateManager`, () => {
assert.deepEqual(h1.getValues(), { name: 'test', value: 'test-value' });
assert.deepEqual(h2.getValues(), { name: null, value: null });

server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
return Promise.resolve();
} catch(err) {
server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
return Promise.reject(err);
}
});
Expand All @@ -841,10 +841,10 @@ describe(`# StateManager`, () => {

try {
assert.deepEqual(h.getValues(), { name: 'test', value: 'async-ok' });
server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
return Promise.resolve();
} catch(err) {
server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
return Promise.reject(err);
}
});
Expand All @@ -865,10 +865,10 @@ describe(`# StateManager`, () => {

try {
assert.deepEqual(h.getValues(), { name: 'test', value: 'ok-2' });
server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
return Promise.resolve();
} catch(err) {
server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
return Promise.reject(err);
}
});
Expand All @@ -894,9 +894,9 @@ describe(`# StateManager`, () => {
await h.set({ name: 'test-2' });
assert.deepEqual(h.getValues(), { name: 'test-2', value: 'ok-1' });

server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
} catch(err) {
server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
return Promise.reject(err);
}
});
Expand All @@ -920,9 +920,9 @@ describe(`# StateManager`, () => {
// should have changed
assert.deepEqual(h.getValues(), { name: null, value: null });

server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
} catch(err) {
server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
return Promise.reject(err);
}
});
Expand All @@ -949,9 +949,9 @@ describe(`# StateManager`, () => {
// should have changed
assert.deepEqual(h.getValues(), { value: null });

server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
} catch(err) {
server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
return Promise.reject(err);
}
});
Expand All @@ -978,9 +978,9 @@ describe(`# StateManager`, () => {
await h.set({ name: 'test-2' });
assert.deepEqual(h.getValues(), { name: 'test-2', value: 'ok' });

server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
} catch(err) {
server.stateManager.deleteSchema('hooked');
server.stateManager.deleteClass('hooked');
return Promise.reject(err);
}
});
Expand Down

0 comments on commit 7e97a5a

Please sign in to comment.