source: trip-planner-front/node_modules/eventemitter3/umd/eventemitter3.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 9.8 KB
Line 
1(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.EventEmitter3 = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2'use strict';
3
4var has = Object.prototype.hasOwnProperty
5 , prefix = '~';
6
7/**
8 * Constructor to create a storage for our `EE` objects.
9 * An `Events` instance is a plain object whose properties are event names.
10 *
11 * @constructor
12 * @private
13 */
14function Events() {}
15
16//
17// We try to not inherit from `Object.prototype`. In some engines creating an
18// instance in this way is faster than calling `Object.create(null)` directly.
19// If `Object.create(null)` is not supported we prefix the event names with a
20// character to make sure that the built-in object properties are not
21// overridden or used as an attack vector.
22//
23if (Object.create) {
24 Events.prototype = Object.create(null);
25
26 //
27 // This hack is needed because the `__proto__` property is still inherited in
28 // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
29 //
30 if (!new Events().__proto__) prefix = false;
31}
32
33/**
34 * Representation of a single event listener.
35 *
36 * @param {Function} fn The listener function.
37 * @param {*} context The context to invoke the listener with.
38 * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
39 * @constructor
40 * @private
41 */
42function EE(fn, context, once) {
43 this.fn = fn;
44 this.context = context;
45 this.once = once || false;
46}
47
48/**
49 * Add a listener for a given event.
50 *
51 * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
52 * @param {(String|Symbol)} event The event name.
53 * @param {Function} fn The listener function.
54 * @param {*} context The context to invoke the listener with.
55 * @param {Boolean} once Specify if the listener is a one-time listener.
56 * @returns {EventEmitter}
57 * @private
58 */
59function addListener(emitter, event, fn, context, once) {
60 if (typeof fn !== 'function') {
61 throw new TypeError('The listener must be a function');
62 }
63
64 var listener = new EE(fn, context || emitter, once)
65 , evt = prefix ? prefix + event : event;
66
67 if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
68 else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
69 else emitter._events[evt] = [emitter._events[evt], listener];
70
71 return emitter;
72}
73
74/**
75 * Clear event by name.
76 *
77 * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
78 * @param {(String|Symbol)} evt The Event name.
79 * @private
80 */
81function clearEvent(emitter, evt) {
82 if (--emitter._eventsCount === 0) emitter._events = new Events();
83 else delete emitter._events[evt];
84}
85
86/**
87 * Minimal `EventEmitter` interface that is molded against the Node.js
88 * `EventEmitter` interface.
89 *
90 * @constructor
91 * @public
92 */
93function EventEmitter() {
94 this._events = new Events();
95 this._eventsCount = 0;
96}
97
98/**
99 * Return an array listing the events for which the emitter has registered
100 * listeners.
101 *
102 * @returns {Array}
103 * @public
104 */
105EventEmitter.prototype.eventNames = function eventNames() {
106 var names = []
107 , events
108 , name;
109
110 if (this._eventsCount === 0) return names;
111
112 for (name in (events = this._events)) {
113 if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
114 }
115
116 if (Object.getOwnPropertySymbols) {
117 return names.concat(Object.getOwnPropertySymbols(events));
118 }
119
120 return names;
121};
122
123/**
124 * Return the listeners registered for a given event.
125 *
126 * @param {(String|Symbol)} event The event name.
127 * @returns {Array} The registered listeners.
128 * @public
129 */
130EventEmitter.prototype.listeners = function listeners(event) {
131 var evt = prefix ? prefix + event : event
132 , handlers = this._events[evt];
133
134 if (!handlers) return [];
135 if (handlers.fn) return [handlers.fn];
136
137 for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
138 ee[i] = handlers[i].fn;
139 }
140
141 return ee;
142};
143
144/**
145 * Return the number of listeners listening to a given event.
146 *
147 * @param {(String|Symbol)} event The event name.
148 * @returns {Number} The number of listeners.
149 * @public
150 */
151EventEmitter.prototype.listenerCount = function listenerCount(event) {
152 var evt = prefix ? prefix + event : event
153 , listeners = this._events[evt];
154
155 if (!listeners) return 0;
156 if (listeners.fn) return 1;
157 return listeners.length;
158};
159
160/**
161 * Calls each of the listeners registered for a given event.
162 *
163 * @param {(String|Symbol)} event The event name.
164 * @returns {Boolean} `true` if the event had listeners, else `false`.
165 * @public
166 */
167EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
168 var evt = prefix ? prefix + event : event;
169
170 if (!this._events[evt]) return false;
171
172 var listeners = this._events[evt]
173 , len = arguments.length
174 , args
175 , i;
176
177 if (listeners.fn) {
178 if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
179
180 switch (len) {
181 case 1: return listeners.fn.call(listeners.context), true;
182 case 2: return listeners.fn.call(listeners.context, a1), true;
183 case 3: return listeners.fn.call(listeners.context, a1, a2), true;
184 case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
185 case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
186 case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
187 }
188
189 for (i = 1, args = new Array(len -1); i < len; i++) {
190 args[i - 1] = arguments[i];
191 }
192
193 listeners.fn.apply(listeners.context, args);
194 } else {
195 var length = listeners.length
196 , j;
197
198 for (i = 0; i < length; i++) {
199 if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
200
201 switch (len) {
202 case 1: listeners[i].fn.call(listeners[i].context); break;
203 case 2: listeners[i].fn.call(listeners[i].context, a1); break;
204 case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
205 case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
206 default:
207 if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
208 args[j - 1] = arguments[j];
209 }
210
211 listeners[i].fn.apply(listeners[i].context, args);
212 }
213 }
214 }
215
216 return true;
217};
218
219/**
220 * Add a listener for a given event.
221 *
222 * @param {(String|Symbol)} event The event name.
223 * @param {Function} fn The listener function.
224 * @param {*} [context=this] The context to invoke the listener with.
225 * @returns {EventEmitter} `this`.
226 * @public
227 */
228EventEmitter.prototype.on = function on(event, fn, context) {
229 return addListener(this, event, fn, context, false);
230};
231
232/**
233 * Add a one-time listener for a given event.
234 *
235 * @param {(String|Symbol)} event The event name.
236 * @param {Function} fn The listener function.
237 * @param {*} [context=this] The context to invoke the listener with.
238 * @returns {EventEmitter} `this`.
239 * @public
240 */
241EventEmitter.prototype.once = function once(event, fn, context) {
242 return addListener(this, event, fn, context, true);
243};
244
245/**
246 * Remove the listeners of a given event.
247 *
248 * @param {(String|Symbol)} event The event name.
249 * @param {Function} fn Only remove the listeners that match this function.
250 * @param {*} context Only remove the listeners that have this context.
251 * @param {Boolean} once Only remove one-time listeners.
252 * @returns {EventEmitter} `this`.
253 * @public
254 */
255EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
256 var evt = prefix ? prefix + event : event;
257
258 if (!this._events[evt]) return this;
259 if (!fn) {
260 clearEvent(this, evt);
261 return this;
262 }
263
264 var listeners = this._events[evt];
265
266 if (listeners.fn) {
267 if (
268 listeners.fn === fn &&
269 (!once || listeners.once) &&
270 (!context || listeners.context === context)
271 ) {
272 clearEvent(this, evt);
273 }
274 } else {
275 for (var i = 0, events = [], length = listeners.length; i < length; i++) {
276 if (
277 listeners[i].fn !== fn ||
278 (once && !listeners[i].once) ||
279 (context && listeners[i].context !== context)
280 ) {
281 events.push(listeners[i]);
282 }
283 }
284
285 //
286 // Reset the array, or remove it completely if we have no more listeners.
287 //
288 if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
289 else clearEvent(this, evt);
290 }
291
292 return this;
293};
294
295/**
296 * Remove all listeners, or those of the specified event.
297 *
298 * @param {(String|Symbol)} [event] The event name.
299 * @returns {EventEmitter} `this`.
300 * @public
301 */
302EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
303 var evt;
304
305 if (event) {
306 evt = prefix ? prefix + event : event;
307 if (this._events[evt]) clearEvent(this, evt);
308 } else {
309 this._events = new Events();
310 this._eventsCount = 0;
311 }
312
313 return this;
314};
315
316//
317// Alias methods names because people roll like that.
318//
319EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
320EventEmitter.prototype.addListener = EventEmitter.prototype.on;
321
322//
323// Expose the prefix.
324//
325EventEmitter.prefixed = prefix;
326
327//
328// Allow `EventEmitter` to be imported as module namespace.
329//
330EventEmitter.EventEmitter = EventEmitter;
331
332//
333// Expose the module.
334//
335if ('undefined' !== typeof module) {
336 module.exports = EventEmitter;
337}
338
339},{}]},{},[1])(1)
340});
Note: See TracBrowser for help on using the repository browser.