mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-20 10:53:53 +01:00
introduce createDecorator
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user