-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecorators.ts
36 lines (25 loc) · 904 Bytes
/
decorators.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
34
/// <reference path="index.d.ts" />
import { _throttle } from 'td';
import { _debounce } from 'td'
function debounce(wait: number): Function {
return function(target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor {
if(descriptor === undefined) {
descriptor = Object.getOwnPropertyDescriptor(target, propertyKey);
}
descriptor.value = function(func: Function): Function {
return _debounce(func, wait);
};
return descriptor;
}
}
function throttle(wait: number): Function {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor {
if(descriptor === undefined) {
descriptor = Object.getOwnPropertyDescriptor(target, propertyKey);
}
descriptor.value = function (func: Function): Function {
return _throttle(func, wait);
};
return descriptor;
}
}