forked from yysun/apprun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecorator.ts
33 lines (27 loc) · 987 Bytes
/
decorator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
export const Reflect = {
meta: new WeakMap(),
defineMetadata(metadataKey, metadataValue, target) {
if (!this.meta.has(target)) this.meta.set(target, {});
this.meta.get(target)[metadataKey] = metadataValue;
},
getMetadataKeys(target) {
target = Object.getPrototypeOf(target);
return this.meta.get(target) ? Object.keys(this.meta.get(target)) : [];
},
getMetadata(metadataKey, target) {
target = Object.getPrototypeOf(target);
return this.meta.get(target) ? this.meta.get(target)[metadataKey] : null;
}
}
export function update(name: string, options: any = {}) {
return (target: any, key: string, descriptor: any) => {
Reflect.defineMetadata(`apprun-update:${name}`,
{ name, action: [descriptor.value, options] }, target)
return descriptor;
}
}
export function on(name: string, options: any = {}) {
return function (target: any, key: string) {
Reflect.defineMetadata(`apprun-update:${name}`, { name, key }, target)
}
}