-
Notifications
You must be signed in to change notification settings - Fork 1
/
evemit.d.ts
84 lines (76 loc) · 2.35 KB
/
evemit.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
/**
* @name Evemit
* @description Minimal and fast JavaScript event emitter for Node.js and front-end.
* @author Nicolas Tallefourtane <[email protected]>
* @link https://github.com/Nicolab/evemit
* @license MIT https://github.com/Nicolab/evemit/blob/master/LICENSE
*/
declare module 'evemit' {
class Evemit {
/**
* Events object.
*/
events: Record<string, Function[]>;
/**
* Evemit
*
* @constructor
* @api public
*/
constructor();
/**
* Register a new event listener for a given event.
*
* @param {string} event Event name.
* @param {function} fn Callback function (listener).
* @param {*} [context] Context for function execution.
* @return {Evemit} Current instance.
* @api public
*/
on(event: string, fn: Function, context?: any): this;
/**
* Add an event listener that's only called once.
*
* @param {string} event Event name.
* @param {function} fn Callback function (listener).
* @param {*} [context] Context for function execution.
* @return {Evemit} Current instance.
* @api public
*/
once(event: string, fn: Function, context?: any): this;
/**
* Emit an event to all registered event listeners.
*
* @param {string} event Event name.
* @param {*} [...arg] One or more arguments to pass to the listeners.
* @return {bool} Indication, `true` if at least one listener was executed,
* otherwise returns `false`.
* @api public
*/
emit(event: string, ...args: any[]): boolean;
/**
* Remove event listeners.
*
* @param {string} event The event to remove.
* @param {function} fn The listener that we need to find.
* @return {Evemit} Current instance.
* @api public
*/
off(event: string, fn: Function): this;
/**
* Get a list of assigned event listeners.
*
* @param {string} [event] The events that should be listed.
* If not provided, all listeners are returned.
* Use the property `Evemit.events` if you want to get an object like
* ```
* {event1: [array of listeners], event2: [array of listeners], ...}
* ```
*
* @return {array}
* @api public
*/
listeners(event?: string): Function[];
}
export = Evemit;
}