forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
js-signals.d.ts
110 lines (92 loc) · 3.33 KB
/
js-signals.d.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Type definitions for JS-Signals
// Project: http://millermedeiros.github.io/js-signals/
// Definitions by: Diullei Gomes <https://github.com/diullei>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare var signals: SignalWrapper;
declare module "signals" {
export = signals;
}
interface SignalWrapper {
Signal: Signal
}
interface SignalBinding {
active: boolean;
context: any;
params: any;
detach(): Function;
execute(paramsArr?:any[]): any;
getListener(): Function;
getSignal(): Signal;
isBound(): boolean;
isOnce(): boolean;
}
interface Signal {
/**
* Custom event broadcaster
* <br />- inspired by Robert Penner's AS3 Signals.
* @name Signal
* @author Miller Medeiros
* @constructor
*/
new(): Signal;
/**
* If Signal is active and should broadcast events.
*/
active: boolean;
/**
* If Signal should keep record of previously dispatched parameters and automatically
* execute listener during add()/addOnce() if Signal was already dispatched before.
*/
memorize: boolean;
/**
* Signals Version Number
*/
VERSION: string;
/**
* Add a listener to the signal.
*
* @param listener Signal handler function.
* @param listenercontext Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @param priority The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
*/
add(listener: Function, listenerContext?: any, priority?: Number): SignalBinding;
/**
* Add listener to the signal that should be removed after first execution (will be executed only once).
*
* @param listener Signal handler function.
* @param listenercontext Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @param priority The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
*/
addOnce(listener: Function, listenerContext?: any, priority?: Number): SignalBinding;
/**
* Dispatch/Broadcast Signal to all listeners added to the queue.
*
* @param params Parameters that should be passed to each handler.
*/
dispatch(...params: any[]): void;
/**
* Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
*/
dispose(): void;
/**
* Forget memorized arguments.
*/
forget(): void;
/**
* Returns a number of listeners attached to the Signal.
*/
getNumListeners(): number;
/**
* Stop propagation of the event, blocking the dispatch to next listeners on the queue.
*/
halt(): void;
/**
* Check if listener was attached to Signal.
*/
has(listener: Function, context?: any): boolean;
/**
* Remove a single listener from the dispatch queue.
*/
remove(listener: Function, context?: any): Function;
removeAll(): void;
}