Skip to content

Commit

Permalink
feat: add a setModelStore to force model store
Browse files Browse the repository at this point in the history
  • Loading branch information
loopingz committed Nov 29, 2023
1 parent 997e11b commit 5354f46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,11 @@ class CoreTest extends WebdaTest {
assert.throws(() => this.webda.registerOperation("__proto__", undefined), Error);

assert.ok(Core["getSingletonInfo"](this.webda).match(/- file:\/\/.*packages\/core\/src\/core.ts \/ \d+.\d+.\d+/));

assert.strictEqual(User.store().getName(), "MemoryUsers");
const memoryStore = new MemoryStore(this.webda, "test", {});
this.webda.setModelStore(User, memoryStore);
assert.strictEqual(User.store().getName(), "test");
}

@test
Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,18 @@ export class Core<E extends CoreEvents = CoreEvents> extends events.EventEmitter
return singleton;
}

/**
* Enforce a specific store for a model
*
* Useful in some specific case when you want to update store dynamically
*
* @param model
* @param store
*/
setModelStore(model: Constructor<CoreModel>, store: Store) {
this._modelStoresCache.set(model, store);
}

/**
* Get the store assigned to this model
* @param model
Expand Down

0 comments on commit 5354f46

Please sign in to comment.