generated from gxc-solutions/gxc-template-repo
This commit is contained in:
parent
41a325f5e1
commit
0f8546bc69
10 changed files with 149 additions and 1 deletions
15
lib/src/decorators/immutable.ts
Normal file
15
lib/src/decorators/immutable.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { ModelConstructor } from "../interfaces";
|
||||
|
||||
export const IMMUTABLE_FIELDS = new WeakMap<ModelConstructor, Set<string>>();
|
||||
|
||||
export function immutable(value: unknown, context: ClassFieldDecoratorContext) {
|
||||
context.addInitializer(function () {
|
||||
const ctor = this.constructor as ModelConstructor;
|
||||
let set = IMMUTABLE_FIELDS.get(ctor);
|
||||
if (!set) {
|
||||
set = new Set<string>();
|
||||
IMMUTABLE_FIELDS.set(ctor, set);
|
||||
}
|
||||
set.add(context.name as string);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue