4
*--------------------------------------------------------------------------------------------*/
5
6
>
function createDecorator(mapFn: (fn: Function, key: string) => Function): MethodDecorator {
decorators.ts
7
>
return (_target: Object, key: string | symbol, descriptor: TypedPropertyDescriptor<any>) => {
8
>
let fnKey: 'value' | 'get' | null = null;
9
>
let fn: Function | null = null;
10
>
11
>
if (typeof descriptor.value === 'function') {
12
>
fnKey = 'value';
13
>
fn = descriptor.value;
14
>
} else if (typeof descriptor.get === 'function') {
15
fnKey = 'get';
16
fn = descriptor.get;
17
}
19
>
if (!fn || typeof key === 'symbol') {
20
throw new Error('not supported');
21
}
23
>
descriptor[fnKey!] = mapFn(fn, key);
24
>
};
25
>
}
26
27
export function memoize(_target: Object, key: string, descriptor: PropertyDescriptor) {