8
8
import { done } from "./util" ;
9
9
10
10
function decorate (
11
- decorator : ( fn : Function , key : string ) => Function
12
- ) : Function {
11
+ decorator : ( fn : ( ... args : any [ ] ) => void , key : string ) => void
12
+ ) : ( _target : any , key : string , descriptor : any ) => void {
13
13
return ( _target : any , key : string , descriptor : any ) => {
14
14
let fnKey : string | null = null ;
15
- let fn : Function | null = null ;
15
+ let fn : ( ( ... args : any [ ] ) => void ) | null = null ;
16
16
17
17
if ( typeof descriptor . value === "function" ) {
18
18
fnKey = "value" ;
@@ -30,7 +30,10 @@ function decorate(
30
30
} ;
31
31
}
32
32
33
- function _memoize ( fn : Function , key : string ) : Function {
33
+ function _memoize (
34
+ fn : ( ...args : any [ ] ) => void ,
35
+ key : string
36
+ ) : ( this : any , ...args : any [ ] ) => any {
34
37
const memoizeKey = `$memoize$${ key } ` ;
35
38
36
39
return function ( this : any , ...args : any [ ] ) {
@@ -49,7 +52,10 @@ function _memoize(fn: Function, key: string): Function {
49
52
50
53
export const memoize = decorate ( _memoize ) ;
51
54
52
- function _throttle < T > ( fn : Function , key : string ) : Function {
55
+ function _throttle (
56
+ fn : ( ...args : any [ ] ) => void ,
57
+ key : string
58
+ ) : ( this : any , ...args : any [ ] ) => any {
53
59
const currentKey = `$throttle$current$${ key } ` ;
54
60
const nextKey = `$throttle$next$${ key } ` ;
55
61
@@ -67,7 +73,7 @@ function _throttle<T>(fn: Function, key: string): Function {
67
73
return this [ nextKey ] ;
68
74
}
69
75
70
- this [ currentKey ] = fn . apply ( this , args ) as Promise < T > ;
76
+ this [ currentKey ] = fn . apply ( this , args ) ;
71
77
72
78
const clear = ( ) => ( this [ currentKey ] = undefined ) ;
73
79
done ( this [ currentKey ] ) . then ( clear , clear ) ;
@@ -80,7 +86,10 @@ function _throttle<T>(fn: Function, key: string): Function {
80
86
81
87
export const throttle = decorate ( _throttle ) ;
82
88
83
- function _sequentialize ( fn : Function , key : string ) : Function {
89
+ function _sequentialize (
90
+ fn : ( ...args : any [ ] ) => void ,
91
+ key : string
92
+ ) : ( this : any , ...args : any [ ] ) => any {
84
93
const currentKey = `__$sequence$${ key } ` ;
85
94
86
95
return function ( this : any , ...args : any [ ] ) {
@@ -94,7 +103,9 @@ function _sequentialize(fn: Function, key: string): Function {
94
103
95
104
export const sequentialize = decorate ( _sequentialize ) ;
96
105
97
- export function debounce ( delay : number ) : Function {
106
+ export function debounce (
107
+ delay : number
108
+ ) : ( _target : any , key : string , descriptor : any ) => void {
98
109
return decorate ( ( fn , key ) => {
99
110
const timerKey = `$debounce$${ key } ` ;
100
111
@@ -107,7 +118,9 @@ export function debounce(delay: number): Function {
107
118
108
119
const _seqList : { [ key : string ] : any } = { } ;
109
120
110
- export function globalSequentialize ( name : string ) : Function {
121
+ export function globalSequentialize (
122
+ name : string
123
+ ) : ( _target : any , key : string , descriptor : any ) => void {
111
124
return decorate ( ( fn , _key ) => {
112
125
return function ( this : any , ...args : any [ ] ) {
113
126
const currentPromise =
0 commit comments