introduce createDecorator

This commit is contained in:
Joao Moreno
2017-07-20 10:20:01 +02:00
parent f5c4b7abd3
commit 9bc741ebaf
+21
View File
@@ -5,6 +5,27 @@
'use strict';
export function createDecorator(mapFn: (fn: Function) => Function): Function {
return (target: any, key: string, descriptor: any) => {
let fnKey: string = null;
let fn: Function = null;
if (typeof descriptor.value === 'function') {
fnKey = 'value';
fn = descriptor.value;
} else if (typeof descriptor.get === 'function') {
fnKey = 'get';
fn = descriptor.get;
}
if (!fn) {
throw new Error('not supported');
}
descriptor[fnKey] = mapFn(fn);
};
}
export function memoize(target: any, key: string, descriptor: any) {
let fnKey: string = null;
let fn: Function = null;