提交 9bc741eb 编写于 作者: J Joao Moreno

introduce createDecorator

上级 f5c4b7ab
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册