Skip to content

Commit 5614aa6

Browse files
committed
feat(core): Add support to create Store over Symbol
1 parent 8747530 commit 5614aa6

File tree

2 files changed

+131
-99
lines changed

2 files changed

+131
-99
lines changed

packages/core/src/class/Store.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {DecoratorParameters} from "../interfaces";
2-
import {deepClone, deepExtends, descriptorOf, getDecoratorType, nameOf} from "../utils";
2+
import {deepClone, deepExtends, descriptorOf, getDecoratorType, isSymbol, nameOf} from "../utils";
33

44
import {Metadata} from "./Metadata";
55

@@ -10,6 +10,8 @@ export const PARAM_STORE = "tsed:param:store";
1010

1111
export type StoreMap = Map<string, any>;
1212

13+
const stores = new Map<symbol, any>();
14+
1315
/**
1416
*
1517
*/
@@ -71,6 +73,7 @@ export class Store {
7173
* @deprecated Use StoreFn
7274
* @returns {Function}
7375
*/
76+
7477
/* istanbul ignore next */
7578
static decorate(fn: (store: Store, parameters: DecoratorParameters) => void): Function {
7679
return (...parameters: any[]): any => {
@@ -214,12 +217,20 @@ export class Store {
214217
* @private
215218
*/
216219
private _storeGet(key: string, ...args: any[]): StoreMap {
217-
const registry = Metadata as any;
220+
if (isSymbol(args[0])) {
221+
if (!stores.has(args[0])) {
222+
stores.set(args[0], new Map<string, any>());
223+
}
218224

219-
if (!registry.hasOwn(key, ...args)) {
220-
registry.set(key, new Map<string, any>(), ...args);
221-
}
225+
return stores.get(args[0]);
226+
} else {
227+
const registry = Metadata as any;
222228

223-
return registry.getOwn(key, ...args);
229+
if (!registry.hasOwn(key, ...args)) {
230+
registry.set(key, new Map<string, any>(), ...args);
231+
}
232+
233+
return registry.getOwn(key, ...args);
234+
}
224235
}
225236
}

0 commit comments

Comments
 (0)