metro-runtime 0.73.4 → 0.73.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/modules/HMRClient.js +9 -42
- package/src/modules/asyncRequire.js +3 -2
- package/src/modules/fast-refresh.js +1 -0
- package/src/modules/null-module.js +1 -0
- package/src/modules/types.flow.js +1 -0
- package/src/modules/vendor/eventemitter3.js +32 -52
- package/src/polyfills/require.js +80 -199
- package/src/polyfills/require.js.flow +12 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro-runtime",
|
|
3
|
-
"version": "0.73.
|
|
3
|
+
"version": "0.73.6",
|
|
4
4
|
"description": "🚇 Module required for evaluating Metro bundles.",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"repository": {
|
|
@@ -17,6 +17,6 @@
|
|
|
17
17
|
"react-refresh": "^0.4.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@babel/core": "^7.
|
|
20
|
+
"@babel/core": "^7.20.0"
|
|
21
21
|
}
|
|
22
22
|
}
|
package/src/modules/HMRClient.js
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
|
+
|
|
11
12
|
"use strict";
|
|
12
13
|
|
|
13
14
|
const EventEmitter = require("./vendor/eventemitter3");
|
|
14
|
-
|
|
15
15
|
const inject = ({ module: [id, code], sourceURL }) => {
|
|
16
16
|
// Some engines do not support `sourceURL` as a comment. We expose a
|
|
17
17
|
// `globalEvalWithSourceUrl` function to handle updates in that case.
|
|
@@ -22,64 +22,51 @@ const inject = ({ module: [id, code], sourceURL }) => {
|
|
|
22
22
|
eval(code);
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
|
|
26
25
|
const injectUpdate = (update) => {
|
|
27
26
|
update.added.forEach(inject);
|
|
28
27
|
update.modified.forEach(inject);
|
|
29
28
|
};
|
|
30
|
-
|
|
31
29
|
class HMRClient extends EventEmitter {
|
|
32
30
|
_isEnabled = false;
|
|
33
31
|
_pendingUpdate = null;
|
|
34
32
|
_queue = [];
|
|
35
33
|
_state = "opening";
|
|
36
|
-
|
|
37
34
|
constructor(url) {
|
|
38
|
-
super();
|
|
39
|
-
// since some polyfills do the initialization lazily.
|
|
35
|
+
super();
|
|
40
36
|
|
|
37
|
+
// Access the global WebSocket object only after enabling the client,
|
|
38
|
+
// since some polyfills do the initialization lazily.
|
|
41
39
|
this._ws = new global.WebSocket(url);
|
|
42
|
-
|
|
43
40
|
this._ws.onopen = () => {
|
|
44
41
|
this._state = "open";
|
|
45
42
|
this.emit("open");
|
|
46
|
-
|
|
47
43
|
this._flushQueue();
|
|
48
44
|
};
|
|
49
|
-
|
|
50
45
|
this._ws.onerror = (error) => {
|
|
51
46
|
this.emit("connection-error", error);
|
|
52
47
|
};
|
|
53
|
-
|
|
54
48
|
this._ws.onclose = (closeEvent) => {
|
|
55
49
|
this._state = "closed";
|
|
56
50
|
this.emit("close", closeEvent);
|
|
57
51
|
};
|
|
58
|
-
|
|
59
52
|
this._ws.onmessage = (message) => {
|
|
60
53
|
const data = JSON.parse(String(message.data));
|
|
61
|
-
|
|
62
54
|
switch (data.type) {
|
|
63
55
|
case "bundle-registered":
|
|
64
56
|
this.emit("bundle-registered");
|
|
65
57
|
break;
|
|
66
|
-
|
|
67
58
|
case "update-start":
|
|
68
59
|
this.emit("update-start", data.body);
|
|
69
60
|
break;
|
|
70
|
-
|
|
71
61
|
case "update":
|
|
72
62
|
this.emit("update", data.body);
|
|
73
63
|
break;
|
|
74
|
-
|
|
75
64
|
case "update-done":
|
|
76
65
|
this.emit("update-done");
|
|
77
66
|
break;
|
|
78
|
-
|
|
79
67
|
case "error":
|
|
80
68
|
this.emit("error", data.body);
|
|
81
69
|
break;
|
|
82
|
-
|
|
83
70
|
default:
|
|
84
71
|
this.emit("error", {
|
|
85
72
|
type: "unknown-message",
|
|
@@ -87,7 +74,6 @@ class HMRClient extends EventEmitter {
|
|
|
87
74
|
});
|
|
88
75
|
}
|
|
89
76
|
};
|
|
90
|
-
|
|
91
77
|
this.on("update", (update) => {
|
|
92
78
|
if (this._isEnabled) {
|
|
93
79
|
injectUpdate(update);
|
|
@@ -98,69 +84,54 @@ class HMRClient extends EventEmitter {
|
|
|
98
84
|
}
|
|
99
85
|
});
|
|
100
86
|
}
|
|
101
|
-
|
|
102
87
|
close() {
|
|
103
88
|
this._ws.close();
|
|
104
89
|
}
|
|
105
|
-
|
|
106
90
|
send(message) {
|
|
107
91
|
switch (this._state) {
|
|
108
92
|
case "opening":
|
|
109
93
|
this._queue.push(message);
|
|
110
|
-
|
|
111
94
|
break;
|
|
112
|
-
|
|
113
95
|
case "open":
|
|
114
96
|
this._ws.send(message);
|
|
115
|
-
|
|
116
97
|
break;
|
|
117
|
-
|
|
118
98
|
case "closed":
|
|
119
99
|
// Ignore.
|
|
120
100
|
break;
|
|
121
|
-
|
|
122
101
|
default:
|
|
123
102
|
throw new Error("[WebSocketHMRClient] Unknown state: " + this._state);
|
|
124
103
|
}
|
|
125
104
|
}
|
|
126
|
-
|
|
127
105
|
_flushQueue() {
|
|
128
106
|
this._queue.forEach((message) => this.send(message));
|
|
129
|
-
|
|
130
107
|
this._queue.length = 0;
|
|
131
108
|
}
|
|
132
|
-
|
|
133
109
|
enable() {
|
|
134
110
|
this._isEnabled = true;
|
|
135
111
|
const update = this._pendingUpdate;
|
|
136
112
|
this._pendingUpdate = null;
|
|
137
|
-
|
|
138
113
|
if (update != null) {
|
|
139
114
|
injectUpdate(update);
|
|
140
115
|
}
|
|
141
116
|
}
|
|
142
|
-
|
|
143
117
|
disable() {
|
|
144
118
|
this._isEnabled = false;
|
|
145
119
|
}
|
|
146
|
-
|
|
147
120
|
isEnabled() {
|
|
148
121
|
return this._isEnabled;
|
|
149
122
|
}
|
|
150
|
-
|
|
151
123
|
hasPendingUpdates() {
|
|
152
124
|
return this._pendingUpdate != null;
|
|
153
125
|
}
|
|
154
126
|
}
|
|
155
|
-
|
|
156
127
|
function mergeUpdates(base, next) {
|
|
157
128
|
const addedIDs = new Set();
|
|
158
129
|
const deletedIDs = new Set();
|
|
159
|
-
const moduleMap = new Map();
|
|
130
|
+
const moduleMap = new Map();
|
|
160
131
|
|
|
132
|
+
// Fill in the temporary maps and sets from both updates in their order.
|
|
161
133
|
applyUpdateLocally(base);
|
|
162
134
|
applyUpdateLocally(next);
|
|
163
|
-
|
|
164
135
|
function applyUpdateLocally(update) {
|
|
165
136
|
update.deleted.forEach((id) => {
|
|
166
137
|
if (addedIDs.has(id)) {
|
|
@@ -168,27 +139,25 @@ function mergeUpdates(base, next) {
|
|
|
168
139
|
} else {
|
|
169
140
|
deletedIDs.add(id);
|
|
170
141
|
}
|
|
171
|
-
|
|
172
142
|
moduleMap.delete(id);
|
|
173
143
|
});
|
|
174
144
|
update.added.forEach((item) => {
|
|
175
145
|
const id = item.module[0];
|
|
176
|
-
|
|
177
146
|
if (deletedIDs.has(id)) {
|
|
178
147
|
deletedIDs.delete(id);
|
|
179
148
|
} else {
|
|
180
149
|
addedIDs.add(id);
|
|
181
150
|
}
|
|
182
|
-
|
|
183
151
|
moduleMap.set(id, item);
|
|
184
152
|
});
|
|
185
153
|
update.modified.forEach((item) => {
|
|
186
154
|
const id = item.module[0];
|
|
187
155
|
moduleMap.set(id, item);
|
|
188
156
|
});
|
|
189
|
-
}
|
|
190
|
-
// Applying it should be equivalent to applying both of them individually.
|
|
157
|
+
}
|
|
191
158
|
|
|
159
|
+
// Now reconstruct a unified update from our in-memory maps and sets.
|
|
160
|
+
// Applying it should be equivalent to applying both of them individually.
|
|
192
161
|
const result = {
|
|
193
162
|
isInitialUpdate: next.isInitialUpdate,
|
|
194
163
|
revisionId: next.revisionId,
|
|
@@ -203,7 +172,6 @@ function mergeUpdates(base, next) {
|
|
|
203
172
|
if (deletedIDs.has(id)) {
|
|
204
173
|
return;
|
|
205
174
|
}
|
|
206
|
-
|
|
207
175
|
if (addedIDs.has(id)) {
|
|
208
176
|
result.added.push(item);
|
|
209
177
|
} else {
|
|
@@ -212,5 +180,4 @@ function mergeUpdates(base, next) {
|
|
|
212
180
|
});
|
|
213
181
|
return result;
|
|
214
182
|
}
|
|
215
|
-
|
|
216
183
|
module.exports = HMRClient;
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
* @format
|
|
8
8
|
*
|
|
9
9
|
*/
|
|
10
|
-
"use strict"; // $FlowExpectedError Flow does not know about Metro's require extensions.
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
"use strict";
|
|
13
12
|
|
|
13
|
+
// $FlowExpectedError Flow does not know about Metro's require extensions.
|
|
14
|
+
const dynamicRequire = require;
|
|
14
15
|
module.exports = function (moduleID) {
|
|
15
16
|
return Promise.resolve().then(() => dynamicRequire.importAll(moduleID));
|
|
16
17
|
};
|
|
@@ -16,10 +16,12 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
/* eslint-disable */
|
|
19
|
+
|
|
19
20
|
"use strict";
|
|
20
21
|
|
|
21
22
|
var has = Object.prototype.hasOwnProperty,
|
|
22
23
|
prefix = "~";
|
|
24
|
+
|
|
23
25
|
/**
|
|
24
26
|
* Constructor to create a storage for our `EE` objects.
|
|
25
27
|
* An `Events` instance is a plain object whose properties are event names.
|
|
@@ -27,23 +29,25 @@ var has = Object.prototype.hasOwnProperty,
|
|
|
27
29
|
* @constructor
|
|
28
30
|
* @private
|
|
29
31
|
*/
|
|
32
|
+
function Events() {}
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
//
|
|
32
35
|
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
33
36
|
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
34
37
|
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
35
38
|
// character to make sure that the built-in object properties are not
|
|
36
39
|
// overridden or used as an attack vector.
|
|
37
40
|
//
|
|
38
|
-
|
|
39
41
|
if (Object.create) {
|
|
40
|
-
Events.prototype = Object.create(null);
|
|
42
|
+
Events.prototype = Object.create(null);
|
|
43
|
+
|
|
44
|
+
//
|
|
41
45
|
// This hack is needed because the `__proto__` property is still inherited in
|
|
42
46
|
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
43
47
|
//
|
|
44
|
-
|
|
45
48
|
if (!new Events().__proto__) prefix = false;
|
|
46
49
|
}
|
|
50
|
+
|
|
47
51
|
/**
|
|
48
52
|
* Representation of a single event listener.
|
|
49
53
|
*
|
|
@@ -53,12 +57,12 @@ if (Object.create) {
|
|
|
53
57
|
* @constructor
|
|
54
58
|
* @private
|
|
55
59
|
*/
|
|
56
|
-
|
|
57
60
|
function EE(fn, context, once) {
|
|
58
61
|
this.fn = fn;
|
|
59
62
|
this.context = context;
|
|
60
63
|
this.once = once || false;
|
|
61
64
|
}
|
|
65
|
+
|
|
62
66
|
/**
|
|
63
67
|
* Add a listener for a given event.
|
|
64
68
|
*
|
|
@@ -70,12 +74,10 @@ function EE(fn, context, once) {
|
|
|
70
74
|
* @returns {EventEmitter}
|
|
71
75
|
* @private
|
|
72
76
|
*/
|
|
73
|
-
|
|
74
77
|
function addListener(emitter, event, fn, context, once) {
|
|
75
78
|
if (typeof fn !== "function") {
|
|
76
79
|
throw new TypeError("The listener must be a function");
|
|
77
80
|
}
|
|
78
|
-
|
|
79
81
|
var listener = new EE(fn, context || emitter, once),
|
|
80
82
|
evt = prefix ? prefix + event : event;
|
|
81
83
|
if (!emitter._events[evt])
|
|
@@ -84,6 +86,7 @@ function addListener(emitter, event, fn, context, once) {
|
|
|
84
86
|
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
85
87
|
return emitter;
|
|
86
88
|
}
|
|
89
|
+
|
|
87
90
|
/**
|
|
88
91
|
* Clear event by name.
|
|
89
92
|
*
|
|
@@ -91,11 +94,11 @@ function addListener(emitter, event, fn, context, once) {
|
|
|
91
94
|
* @param {(String|Symbol)} evt The Event name.
|
|
92
95
|
* @private
|
|
93
96
|
*/
|
|
94
|
-
|
|
95
97
|
function clearEvent(emitter, evt) {
|
|
96
98
|
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
97
99
|
else delete emitter._events[evt];
|
|
98
100
|
}
|
|
101
|
+
|
|
99
102
|
/**
|
|
100
103
|
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
101
104
|
* `EventEmitter` interface.
|
|
@@ -103,11 +106,11 @@ function clearEvent(emitter, evt) {
|
|
|
103
106
|
* @constructor
|
|
104
107
|
* @public
|
|
105
108
|
*/
|
|
106
|
-
|
|
107
109
|
function EventEmitter() {
|
|
108
110
|
this._events = new Events();
|
|
109
111
|
this._eventsCount = 0;
|
|
110
112
|
}
|
|
113
|
+
|
|
111
114
|
/**
|
|
112
115
|
* Return an array listing the events for which the emitter has registered
|
|
113
116
|
* listeners.
|
|
@@ -115,23 +118,20 @@ function EventEmitter() {
|
|
|
115
118
|
* @returns {Array}
|
|
116
119
|
* @public
|
|
117
120
|
*/
|
|
118
|
-
|
|
119
121
|
EventEmitter.prototype.eventNames = function eventNames() {
|
|
120
122
|
var names = [],
|
|
121
123
|
events,
|
|
122
124
|
name;
|
|
123
125
|
if (this._eventsCount === 0) return names;
|
|
124
|
-
|
|
125
126
|
for (name in (events = this._events)) {
|
|
126
127
|
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
127
128
|
}
|
|
128
|
-
|
|
129
129
|
if (Object.getOwnPropertySymbols) {
|
|
130
130
|
return names.concat(Object.getOwnPropertySymbols(events));
|
|
131
131
|
}
|
|
132
|
-
|
|
133
132
|
return names;
|
|
134
133
|
};
|
|
134
|
+
|
|
135
135
|
/**
|
|
136
136
|
* Return the listeners registered for a given event.
|
|
137
137
|
*
|
|
@@ -139,19 +139,17 @@ EventEmitter.prototype.eventNames = function eventNames() {
|
|
|
139
139
|
* @returns {Array} The registered listeners.
|
|
140
140
|
* @public
|
|
141
141
|
*/
|
|
142
|
-
|
|
143
142
|
EventEmitter.prototype.listeners = function listeners(event) {
|
|
144
143
|
var evt = prefix ? prefix + event : event,
|
|
145
144
|
handlers = this._events[evt];
|
|
146
145
|
if (!handlers) return [];
|
|
147
146
|
if (handlers.fn) return [handlers.fn];
|
|
148
|
-
|
|
149
147
|
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
150
148
|
ee[i] = handlers[i].fn;
|
|
151
149
|
}
|
|
152
|
-
|
|
153
150
|
return ee;
|
|
154
151
|
};
|
|
152
|
+
|
|
155
153
|
/**
|
|
156
154
|
* Return the number of listeners listening to a given event.
|
|
157
155
|
*
|
|
@@ -159,7 +157,6 @@ EventEmitter.prototype.listeners = function listeners(event) {
|
|
|
159
157
|
* @returns {Number} The number of listeners.
|
|
160
158
|
* @public
|
|
161
159
|
*/
|
|
162
|
-
|
|
163
160
|
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
164
161
|
var evt = prefix ? prefix + event : event,
|
|
165
162
|
listeners = this._events[evt];
|
|
@@ -167,6 +164,7 @@ EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
|
167
164
|
if (listeners.fn) return 1;
|
|
168
165
|
return listeners.length;
|
|
169
166
|
};
|
|
167
|
+
|
|
170
168
|
/**
|
|
171
169
|
* Calls each of the listeners registered for a given event.
|
|
172
170
|
*
|
|
@@ -174,7 +172,6 @@ EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
|
174
172
|
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
175
173
|
* @public
|
|
176
174
|
*/
|
|
177
|
-
|
|
178
175
|
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
179
176
|
var evt = prefix ? prefix + event : event;
|
|
180
177
|
if (!this._events[evt]) return false;
|
|
@@ -182,61 +179,46 @@ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
|
182
179
|
len = arguments.length,
|
|
183
180
|
args,
|
|
184
181
|
i;
|
|
185
|
-
|
|
186
182
|
if (listeners.fn) {
|
|
187
183
|
if (listeners.once)
|
|
188
184
|
this.removeListener(event, listeners.fn, undefined, true);
|
|
189
|
-
|
|
190
185
|
switch (len) {
|
|
191
186
|
case 1:
|
|
192
187
|
return listeners.fn.call(listeners.context), true;
|
|
193
|
-
|
|
194
188
|
case 2:
|
|
195
189
|
return listeners.fn.call(listeners.context, a1), true;
|
|
196
|
-
|
|
197
190
|
case 3:
|
|
198
191
|
return listeners.fn.call(listeners.context, a1, a2), true;
|
|
199
|
-
|
|
200
192
|
case 4:
|
|
201
193
|
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
202
|
-
|
|
203
194
|
case 5:
|
|
204
195
|
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
205
|
-
|
|
206
196
|
case 6:
|
|
207
197
|
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
208
198
|
}
|
|
209
|
-
|
|
210
199
|
for (i = 1, args = new Array(len - 1); i < len; i++) {
|
|
211
200
|
args[i - 1] = arguments[i];
|
|
212
201
|
}
|
|
213
|
-
|
|
214
202
|
listeners.fn.apply(listeners.context, args);
|
|
215
203
|
} else {
|
|
216
204
|
var length = listeners.length,
|
|
217
205
|
j;
|
|
218
|
-
|
|
219
206
|
for (i = 0; i < length; i++) {
|
|
220
207
|
if (listeners[i].once)
|
|
221
208
|
this.removeListener(event, listeners[i].fn, undefined, true);
|
|
222
|
-
|
|
223
209
|
switch (len) {
|
|
224
210
|
case 1:
|
|
225
211
|
listeners[i].fn.call(listeners[i].context);
|
|
226
212
|
break;
|
|
227
|
-
|
|
228
213
|
case 2:
|
|
229
214
|
listeners[i].fn.call(listeners[i].context, a1);
|
|
230
215
|
break;
|
|
231
|
-
|
|
232
216
|
case 3:
|
|
233
217
|
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
234
218
|
break;
|
|
235
|
-
|
|
236
219
|
case 4:
|
|
237
220
|
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
238
221
|
break;
|
|
239
|
-
|
|
240
222
|
default:
|
|
241
223
|
if (!args)
|
|
242
224
|
for (j = 1, args = new Array(len - 1); j < len; j++) {
|
|
@@ -246,9 +228,9 @@ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
|
246
228
|
}
|
|
247
229
|
}
|
|
248
230
|
}
|
|
249
|
-
|
|
250
231
|
return true;
|
|
251
232
|
};
|
|
233
|
+
|
|
252
234
|
/**
|
|
253
235
|
* Add a listener for a given event.
|
|
254
236
|
*
|
|
@@ -258,10 +240,10 @@ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
|
258
240
|
* @returns {EventEmitter} `this`.
|
|
259
241
|
* @public
|
|
260
242
|
*/
|
|
261
|
-
|
|
262
243
|
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
263
244
|
return addListener(this, event, fn, context, false);
|
|
264
245
|
};
|
|
246
|
+
|
|
265
247
|
/**
|
|
266
248
|
* Add a one-time listener for a given event.
|
|
267
249
|
*
|
|
@@ -271,10 +253,10 @@ EventEmitter.prototype.on = function on(event, fn, context) {
|
|
|
271
253
|
* @returns {EventEmitter} `this`.
|
|
272
254
|
* @public
|
|
273
255
|
*/
|
|
274
|
-
|
|
275
256
|
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
276
257
|
return addListener(this, event, fn, context, true);
|
|
277
258
|
};
|
|
259
|
+
|
|
278
260
|
/**
|
|
279
261
|
* Remove the listeners of a given event.
|
|
280
262
|
*
|
|
@@ -285,7 +267,6 @@ EventEmitter.prototype.once = function once(event, fn, context) {
|
|
|
285
267
|
* @returns {EventEmitter} `this`.
|
|
286
268
|
* @public
|
|
287
269
|
*/
|
|
288
|
-
|
|
289
270
|
EventEmitter.prototype.removeListener = function removeListener(
|
|
290
271
|
event,
|
|
291
272
|
fn,
|
|
@@ -294,14 +275,11 @@ EventEmitter.prototype.removeListener = function removeListener(
|
|
|
294
275
|
) {
|
|
295
276
|
var evt = prefix ? prefix + event : event;
|
|
296
277
|
if (!this._events[evt]) return this;
|
|
297
|
-
|
|
298
278
|
if (!fn) {
|
|
299
279
|
clearEvent(this, evt);
|
|
300
280
|
return this;
|
|
301
281
|
}
|
|
302
|
-
|
|
303
282
|
var listeners = this._events[evt];
|
|
304
|
-
|
|
305
283
|
if (listeners.fn) {
|
|
306
284
|
if (
|
|
307
285
|
listeners.fn === fn &&
|
|
@@ -319,17 +297,18 @@ EventEmitter.prototype.removeListener = function removeListener(
|
|
|
319
297
|
) {
|
|
320
298
|
events.push(listeners[i]);
|
|
321
299
|
}
|
|
322
|
-
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
//
|
|
323
303
|
// Reset the array, or remove it completely if we have no more listeners.
|
|
324
304
|
//
|
|
325
|
-
|
|
326
305
|
if (events.length)
|
|
327
306
|
this._events[evt] = events.length === 1 ? events[0] : events;
|
|
328
307
|
else clearEvent(this, evt);
|
|
329
308
|
}
|
|
330
|
-
|
|
331
309
|
return this;
|
|
332
310
|
};
|
|
311
|
+
|
|
333
312
|
/**
|
|
334
313
|
* Remove all listeners, or those of the specified event.
|
|
335
314
|
*
|
|
@@ -337,10 +316,8 @@ EventEmitter.prototype.removeListener = function removeListener(
|
|
|
337
316
|
* @returns {EventEmitter} `this`.
|
|
338
317
|
* @public
|
|
339
318
|
*/
|
|
340
|
-
|
|
341
319
|
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
342
320
|
var evt;
|
|
343
|
-
|
|
344
321
|
if (event) {
|
|
345
322
|
evt = prefix ? prefix + event : event;
|
|
346
323
|
if (this._events[evt]) clearEvent(this, evt);
|
|
@@ -348,25 +325,28 @@ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
|
348
325
|
this._events = new Events();
|
|
349
326
|
this._eventsCount = 0;
|
|
350
327
|
}
|
|
351
|
-
|
|
352
328
|
return this;
|
|
353
|
-
};
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
//
|
|
354
332
|
// Alias methods names because people roll like that.
|
|
355
333
|
//
|
|
356
|
-
|
|
357
334
|
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
358
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
335
|
+
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
336
|
+
|
|
337
|
+
//
|
|
359
338
|
// Expose the prefix.
|
|
360
339
|
//
|
|
340
|
+
EventEmitter.prefixed = prefix;
|
|
361
341
|
|
|
362
|
-
|
|
342
|
+
//
|
|
363
343
|
// Allow `EventEmitter` to be imported as module namespace.
|
|
364
344
|
//
|
|
345
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
365
346
|
|
|
366
|
-
|
|
347
|
+
//
|
|
367
348
|
// Expose the module.
|
|
368
349
|
//
|
|
369
|
-
|
|
370
350
|
if ("undefined" !== typeof module) {
|
|
371
351
|
module.exports = EventEmitter;
|
|
372
352
|
}
|