-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
EventEmitter.ts
131 lines (116 loc) · 4.1 KB
/
EventEmitter.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { exportModule } from '../exportModule';
/**
* The name of the event.
*/
type Event = string | symbol;
/**
* The callback function.
*/
type Listener = (...args: any[]) => void;
/** @whatsapp 76521
* @whatsapp 34342 >= 2.2204.13
* @whatsapp 876521 >= 2.2222.8
*/
export declare class EventEmitter {
/**
* Adds the listener function to the end of the listeners array for the event named eventName.
*
* @param eventName The name of the event.
* @param listener The callback function.
* @param context The value of `this` provided for the call to `listener`
* @returns Returns a reference to the `EventEmitter`, so that calls can be chained.
*/
on(eventName: Event, listener: Listener, context?: any): this;
/**
* Adds a one-time listener function for the event named eventName.
*
* @param eventName The name of the event.
* @param listener The callback function.
* @param context The value of `this` provided for the call to `listener`
* @returns Returns a reference to the `EventEmitter`, so that calls can be chained.
*/
once(eventName: Event, listener: Listener, context?: any): this;
/**
* Removes the specified listener from the listener array for the event named eventName.
*
* @param eventName The name of the event.
* @param listener The callback function.
* @param context The value of `this` provided for the call to `listener`
* @returns Returns a reference to the `EventEmitter`, so that calls can be chained.
*/
off(eventName?: Event, listener?: Listener, context?: any): this;
/**
* Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.
* @returns Returns a reference to the `EventEmitter`, so that calls can be chained.
*/
trigger(eventName: Event, ...args: any[]): this;
stopListening(context?: any, eventName?: Event, listener?: Listener): this;
/**
* @param context The value of `this` provided for the call to `listener`
* @param eventName The name of the event.
* @param listener The callback function.
*/
listenTo(context: any, eventName: Event, listener?: Listener): this;
/**
* @param context The value of `this` provided for the call to `listener`
* @param eventName The name of the event.
* @param listener The callback function.
*/
listenToOnce(context: any, eventName: Event, listener?: Listener): this;
/**
* @param context The value of `this` provided for the call to `listener`
* @param eventName The name of the event.
* @param listener The callback function.
*/
listenToAndRun(context: any, eventName: Event, listener?: Listener): this;
isListening(eventName: Event): boolean;
/**
* Alias of `on`
* @alias on
*/
bind(eventName: Event, listener: Listener, context?: any): this;
/**
* Alias of `off`
* @alias off
*/
unbind(eventName?: Event, listener?: Listener, context?: any): this;
/**
* Alias of `off`
* @alias off
*/
removeListener(eventName?: Event, listener?: Listener, context?: any): this;
/**
* Removes all listeners.
* @returns Returns a reference to the `EventEmitter`, so that calls can be chained.
*/
removeAllListeners(): this;
/**
* Alias of `trigger`
* @alias trigger
*/
emit(eventName: Event, ...args: any[]): this;
}
exportModule(
exports,
{
EventEmitter: 'default',
},
(m, id) =>
id === 'WAWebEventEmitter' ||
m.default.toString().includes('Callback parameter passed is not a function')
);