You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

1 lines
26 KiB

{"version":3,"sources":["eventemitter2.js"],"names":[],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"index.js","sourcesContent":["/*!\n * EventEmitter2\n * https://github.com/hij1nx/EventEmitter2\n *\n * Copyright (c) 2013 hij1nx\n * Licensed under the MIT license.\n */\n;!function(undefined) {\n\n var isArray = Array.isArray ? Array.isArray : function _isArray(obj) {\n return Object.prototype.toString.call(obj) === \"[object Array]\";\n };\n var defaultMaxListeners = 10;\n\n function init() {\n this._events = {};\n if (this._conf) {\n configure.call(this, this._conf);\n }\n }\n\n function configure(conf) {\n if (conf) {\n this._conf = conf;\n\n conf.delimiter && (this.delimiter = conf.delimiter);\n this._maxListeners = conf.maxListeners !== undefined ? conf.maxListeners : defaultMaxListeners;\n\n conf.wildcard && (this.wildcard = conf.wildcard);\n conf.newListener && (this._newListener = conf.newListener);\n conf.removeListener && (this._removeListener = conf.removeListener);\n conf.verboseMemoryLeak && (this.verboseMemoryLeak = conf.verboseMemoryLeak);\n\n if (this.wildcard) {\n this.listenerTree = {};\n }\n } else {\n this._maxListeners = defaultMaxListeners;\n }\n }\n\n function logPossibleMemoryLeak(count, eventName) {\n var errorMsg = '(node) warning: possible EventEmitter memory ' +\n 'leak detected. ' + count + ' listeners added. ' +\n 'Use emitter.setMaxListeners() to increase limit.';\n\n if(this.verboseMemoryLeak){\n errorMsg += ' Event name: ' + eventName + '.';\n }\n\n if(typeof process !== 'undefined' && process.emitWarning){\n var e = new Error(errorMsg);\n e.name = 'MaxListenersExceededWarning';\n e.emitter = this;\n e.count = count;\n process.emitWarning(e);\n } else {\n console.error(errorMsg);\n\n if (console.trace){\n console.trace();\n }\n }\n }\n\n function EventEmitter(conf) {\n this._events = {};\n this._newListener = false;\n this._removeListener = false;\n this.verboseMemoryLeak = false;\n configure.call(this, conf);\n }\n EventEmitter.EventEmitter2 = EventEmitter; // backwards compatibility for exporting EventEmitter property\n\n //\n // Attention, function return type now is array, always !\n // It has zero elements if no any matches found and one or more\n // elements (leafs) if there are matches\n //\n function searchListenerTree(handlers, type, tree, i) {\n if (!tree) {\n return [];\n }\n var listeners=[], leaf, len, branch, xTree, xxTree, isolatedBranch, endReached,\n typeLength = type.length, currentType = type[i], nextType = type[i+1];\n if (i === typeLength && tree._listeners) {\n //\n // If at the end of the event(s) list and the tree has listeners\n // invoke those listeners.\n //\n if (typeof tree._listeners === 'function') {\n handlers && handlers.push(tree._listeners);\n return [tree];\n } else {\n for (leaf = 0, len = tree._listeners.length; leaf < len; leaf++) {\n handlers && handlers.push(tree._listeners[leaf]);\n }\n return [tree];\n }\n }\n\n if ((currentType === '*' || currentType === '**') || tree[currentType]) {\n //\n // If the event emitted is '*' at this part\n // or there is a concrete match at this patch\n //\n if (currentType === '*') {\n for (branch in tree) {\n if (branch !== '_listeners' && tree.hasOwnProperty(branch)) {\n listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], i+1));\n }\n }\n return listeners;\n } else if(currentType === '**') {\n endReached = (i+1 === typeLength || (i+2 === typeLength && nextType === '*'));\n if(endReached && tree._listeners) {\n // The next element has a _listeners, add it to the handlers.\n listeners = listeners.concat(searchListenerTree(handlers, type, tree, typeLength));\n }\n\n for (branch in tree) {\n if (branch !== '_listeners' && tree.hasOwnProperty(branch)) {\n if(branch === '*' || branch === '**') {\n if(tree[branch]._listeners && !endReached) {\n listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], typeLength));\n }\n listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], i));\n } else if(branch === nextType) {\n listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], i+2));\n } else {\n // No match on this one, shift into the tree but not in the type array.\n listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], i));\n }\n }\n }\n return listeners;\n }\n\n listeners = listeners.concat(searchListenerTree(handlers, type, tree[currentType], i+1));\n }\n\n xTree = tree['*'];\n if (xTree) {\n //\n // If the listener tree will allow any match for this part,\n // then recursively explore all branches of the tree\n //\n searchListenerTree(handlers, type, xTree, i+1);\n }\n\n xxTree = tree['**'];\n if(xxTree) {\n if(i < typeLength) {\n if(xxTree._listeners) {\n // If we have a listener on a '**', it will catch all, so add its handler.\n searchListenerTree(handlers, type, xxTree, typeLength);\n }\n\n // Build arrays of matching next branches and others.\n for(branch in xxTree) {\n if(branch !== '_listeners' && xxTree.hasOwnProperty(branch)) {\n if(branch === nextType) {\n // We know the next element will match, so jump twice.\n searchListenerTree(handlers, type, xxTree[branch], i+2);\n } else if(branch === currentType) {\n // Current node matches, move into the tree.\n searchListenerTree(handlers, type, xxTree[branch], i+1);\n } else {\n isolatedBranch = {};\n isolatedBranch[branch] = xxTree[branch];\n searchListenerTree(handlers, type, { '**': isolatedBranch }, i+1);\n }\n }\n }\n } else if(xxTree._listeners) {\n // We have reached the end and still on a '**'\n searchListenerTree(handlers, type, xxTree, typeLength);\n } else if(xxTree['*'] && xxTree['*']._listeners) {\n searchListenerTree(handlers, type, xxTree['*'], typeLength);\n }\n }\n\n return listeners;\n }\n\n function growListenerTree(type, listener) {\n\n type = typeof type === 'string' ? type.split(this.delimiter) : type.slice();\n\n //\n // Looks for two consecutive '**', if so, don't add the event at all.\n //\n for(var i = 0, len = type.length; i+1 < len; i++) {\n if(type[i] === '**' && type[i+1] === '**') {\n return;\n }\n }\n\n var tree = this.listenerTree;\n var name = type.shift();\n\n while (name !== undefined) {\n\n if (!tree[name]) {\n tree[name] = {};\n }\n\n tree = tree[name];\n\n if (type.length === 0) {\n\n if (!tree._listeners) {\n tree._listeners = listener;\n }\n else {\n if (typeof tree._listeners === 'function') {\n tree._listeners = [tree._listeners];\n }\n\n tree._listeners.push(listener);\n\n if (\n !tree._listeners.warned &&\n this._maxListeners > 0 &&\n tree._listeners.length > this._maxListeners\n ) {\n tree._listeners.warned = true;\n logPossibleMemoryLeak.call(this, tree._listeners.length, name);\n }\n }\n return true;\n }\n name = type.shift();\n }\n return true;\n }\n\n // By default EventEmitters will print a warning if more than\n // 10 listeners are added to it. This is a useful default which\n // helps finding memory leaks.\n //\n // Obviously not all Emitters should be limited to 10. This function allows\n // that to be increased. Set to zero for unlimited.\n\n EventEmitter.prototype.delimiter = '.';\n\n EventEmitter.prototype.setMaxListeners = function(n) {\n if (n !== undefined) {\n this._maxListeners = n;\n if (!this._conf) this._conf = {};\n this._conf.maxListeners = n;\n }\n };\n\n EventEmitter.prototype.event = '';\n\n\n EventEmitter.prototype.once = function(event, fn) {\n return this._once(event, fn, false);\n };\n\n EventEmitter.prototype.prependOnceListener = function(event, fn) {\n return this._once(event, fn, true);\n };\n\n EventEmitter.prototype._once = function(event, fn, prepend) {\n this._many(event, 1, fn, prepend);\n return this;\n };\n\n EventEmitter.prototype.many = function(event, ttl, fn) {\n return this._many(event, ttl, fn, false);\n }\n\n EventEmitter.prototype.prependMany = function(event, ttl, fn) {\n return this._many(event, ttl, fn, true);\n }\n\n EventEmitter.prototype._many = function(event, ttl, fn, prepend) {\n var self = this;\n\n if (typeof fn !== 'function') {\n throw new Error('many only accepts instances of Function');\n }\n\n function listener() {\n if (--ttl === 0) {\n self.off(event, listener);\n }\n return fn.apply(this, arguments);\n }\n\n listener._origin = fn;\n\n this._on(event, listener, prepend);\n\n return self;\n };\n\n EventEmitter.prototype.emit = function() {\n if (!this._events && !this._all) {\n return false;\n }\n\n this._events || init.call(this);\n\n var type = arguments[0];\n\n if (type === 'newListener' && !this._newListener) {\n if (!this._events.newListener) {\n return false;\n }\n }\n\n var al = arguments.length;\n var args,l,i,j;\n var handler;\n\n if (this._all && this._all.length) {\n handler = this._all.slice();\n if (al > 3) {\n args = new Array(al);\n for (j = 0; j < al; j++) args[j] = arguments[j];\n }\n\n for (i = 0, l = handler.length; i < l; i++) {\n this.event = type;\n switch (al) {\n case 1:\n handler[i].call(this, type);\n break;\n case 2:\n handler[i].call(this, type, arguments[1]);\n break;\n case 3:\n handler[i].call(this, type, arguments[1], arguments[2]);\n break;\n default:\n handler[i].apply(this, args);\n }\n }\n }\n\n if (this.wildcard) {\n handler = [];\n var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();\n searchListenerTree.call(this, handler, ns, this.listenerTree, 0);\n } else {\n handler = this._events[type];\n if (typeof handler === 'function') {\n this.event = type;\n switch (al) {\n case 1:\n handler.call(this);\n break;\n case 2:\n handler.call(this, arguments[1]);\n break;\n case 3:\n handler.call(this, arguments[1], arguments[2]);\n break;\n default:\n args = new Array(al - 1);\n for (j = 1; j < al; j++) args[j - 1] = arguments[j];\n handler.apply(this, args);\n }\n return true;\n } else if (handler) {\n // need to make copy of handlers because list can change in the middle\n // of emit call\n handler = handler.slice();\n }\n }\n\n if (handler && handler.length) {\n if (al > 3) {\n args = new Array(al - 1);\n for (j = 1; j < al; j++) args[j - 1] = arguments[j];\n }\n for (i = 0, l = handler.length; i < l; i++) {\n this.event = type;\n switch (al) {\n case 1:\n handler[i].call(this);\n break;\n case 2:\n handler[i].call(this, arguments[1]);\n break;\n case 3:\n handler[i].call(this, arguments[1], arguments[2]);\n break;\n default:\n handler[i].apply(this, args);\n }\n }\n return true;\n } else if (!this._all && type === 'error') {\n if (arguments[1] instanceof Error) {\n throw arguments[1]; // Unhandled 'error' event\n } else {\n throw new Error(\"Uncaught, unspecified 'error' event.\");\n }\n return false;\n }\n\n return !!this._all;\n };\n\n EventEmitter.prototype.emitAsync = function() {\n if (!this._events && !this._all) {\n return false;\n }\n\n this._events || init.call(this);\n\n var type = arguments[0];\n\n if (type === 'newListener' && !this._newListener) {\n if (!this._events.newListener) { return Promise.resolve([false]); }\n }\n\n var promises= [];\n\n var al = arguments.length;\n var args,l,i,j;\n var handler;\n\n if (this._all) {\n if (al > 3) {\n args = new Array(al);\n for (j = 1; j < al; j++) args[j] = arguments[j];\n }\n for (i = 0, l = this._all.length; i < l; i++) {\n this.event = type;\n switch (al) {\n case 1:\n promises.push(this._all[i].call(this, type));\n break;\n case 2:\n promises.push(this._all[i].call(this, type, arguments[1]));\n break;\n case 3:\n promises.push(this._all[i].call(this, type, arguments[1], arguments[2]));\n break;\n default:\n promises.push(this._all[i].apply(this, args));\n }\n }\n }\n\n if (this.wildcard) {\n handler = [];\n var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();\n searchListenerTree.call(this, handler, ns, this.listenerTree, 0);\n } else {\n handler = this._events[type];\n }\n\n if (typeof handler === 'function') {\n this.event = type;\n switch (al) {\n case 1:\n promises.push(handler.call(this));\n break;\n case 2:\n promises.push(handler.call(this, arguments[1]));\n break;\n case 3:\n promises.push(handler.call(this, arguments[1], arguments[2]));\n break;\n default:\n args = new Array(al - 1);\n for (j = 1; j < al; j++) args[j - 1] = arguments[j];\n promises.push(handler.apply(this, args));\n }\n } else if (handler && handler.length) {\n handler = handler.slice();\n if (al > 3) {\n args = new Array(al - 1);\n for (j = 1; j < al; j++) args[j - 1] = arguments[j];\n }\n for (i = 0, l = handler.length; i < l; i++) {\n this.event = type;\n switch (al) {\n case 1:\n promises.push(handler[i].call(this));\n break;\n case 2:\n promises.push(handler[i].call(this, arguments[1]));\n break;\n case 3:\n promises.push(handler[i].call(this, arguments[1], arguments[2]));\n break;\n default:\n promises.push(handler[i].apply(this, args));\n }\n }\n } else if (!this._all && type === 'error') {\n if (arguments[1] instanceof Error) {\n return Promise.reject(arguments[1]); // Unhandled 'error' event\n } else {\n return Promise.reject(\"Uncaught, unspecified 'error' event.\");\n }\n }\n\n return Promise.all(promises);\n };\n\n EventEmitter.prototype.on = function(type, listener) {\n return this._on(type, listener, false);\n };\n\n EventEmitter.prototype.prependListener = function(type, listener) {\n return this._on(type, listener, true);\n };\n\n EventEmitter.prototype.onAny = function(fn) {\n return this._onAny(fn, false);\n };\n\n EventEmitter.prototype.prependAny = function(fn) {\n return this._onAny(fn, true);\n };\n\n EventEmitter.prototype.addListener = EventEmitter.prototype.on;\n\n EventEmitter.prototype._onAny = function(fn, prepend){\n if (typeof fn !== 'function') {\n throw new Error('onAny only accepts instances of Function');\n }\n\n if (!this._all) {\n this._all = [];\n }\n\n // Add the function to the event listener collection.\n if(prepend){\n this._all.unshift(fn);\n }else{\n this._all.push(fn);\n }\n\n return this;\n }\n\n EventEmitter.prototype._on = function(type, listener, prepend) {\n if (typeof type === 'function') {\n this._onAny(type, listener);\n return this;\n }\n\n if (typeof listener !== 'function') {\n throw new Error('on only accepts instances of Function');\n }\n this._events || init.call(this);\n\n // To avoid recursion in the case that type == \"newListeners\"! Before\n // adding it to the listeners, first emit \"newListeners\".\n if (this._newListener)\n this.emit('newListener', type, listener);\n\n if (this.wildcard) {\n growListenerTree.call(this, type, listener);\n return this;\n }\n\n if (!this._events[type]) {\n // Optimize the case of one listener. Don't need the extra array object.\n this._events[type] = listener;\n }\n else {\n if (typeof this._events[type] === 'function') {\n // Change to array.\n this._events[type] = [this._events[type]];\n }\n\n // If we've already got an array, just add\n if(prepend){\n this._events[type].unshift(listener);\n }else{\n this._events[type].push(listener);\n }\n\n // Check for listener leak\n if (\n !this._events[type].warned &&\n this._maxListeners > 0 &&\n this._events[type].length > this._maxListeners\n ) {\n this._events[type].warned = true;\n logPossibleMemoryLeak.call(this, this._events[type].length, type);\n }\n }\n\n return this;\n }\n\n EventEmitter.prototype.off = function(type, listener) {\n if (typeof listener !== 'function') {\n throw new Error('removeListener only takes instances of Function');\n }\n\n var handlers,leafs=[];\n\n if(this.wildcard) {\n var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();\n leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0);\n }\n else {\n // does not use listeners(), so no side effect of creating _events[type]\n if (!this._events[type]) return this;\n handlers = this._events[type];\n leafs.push({_listeners:handlers});\n }\n\n for (var iLeaf=0; iLeaf<leafs.length; iLeaf++) {\n var leaf = leafs[iLeaf];\n handlers = leaf._listeners;\n if (isArray(handlers)) {\n\n var position = -1;\n\n for (var i = 0, length = handlers.length; i < length; i++) {\n if (handlers[i] === listener ||\n (handlers[i].listener && handlers[i].listener === listener) ||\n (handlers[i]._origin && handlers[i]._origin === listener)) {\n position = i;\n break;\n }\n }\n\n if (position < 0) {\n continue;\n }\n\n if(this.wildcard) {\n leaf._listeners.splice(position, 1);\n }\n else {\n this._events[type].splice(position, 1);\n }\n\n if (handlers.length === 0) {\n if(this.wildcard) {\n delete leaf._listeners;\n }\n else {\n delete this._events[type];\n }\n }\n if (this._removeListener)\n this.emit(\"removeListener\", type, listener);\n\n return this;\n }\n else if (handlers === listener ||\n (handlers.listener && handlers.listener === listener) ||\n (handlers._origin && handlers._origin === listener)) {\n if(this.wildcard) {\n delete leaf._listeners;\n }\n else {\n delete this._events[type];\n }\n if (this._removeListener)\n this.emit(\"removeListener\", type, listener);\n }\n }\n\n function recursivelyGarbageCollect(root) {\n if (root === undefined) {\n return;\n }\n var keys = Object.keys(root);\n for (var i in keys) {\n var key = keys[i];\n var obj = root[key];\n if ((obj instanceof Function) || (typeof obj !== \"object\") || (obj === null))\n continue;\n if (Object.keys(obj).length > 0) {\n recursivelyGarbageCollect(root[key]);\n }\n if (Object.keys(obj).length === 0) {\n delete root[key];\n }\n }\n }\n recursivelyGarbageCollect(this.listenerTree);\n\n return this;\n };\n\n EventEmitter.prototype.offAny = function(fn) {\n var i = 0, l = 0, fns;\n if (fn && this._all && this._all.length > 0) {\n fns = this._all;\n for(i = 0, l = fns.length; i < l; i++) {\n if(fn === fns[i]) {\n fns.splice(i, 1);\n if (this._removeListener)\n this.emit(\"removeListenerAny\", fn);\n return this;\n }\n }\n } else {\n fns = this._all;\n if (this._removeListener) {\n for(i = 0, l = fns.length; i < l; i++)\n this.emit(\"removeListenerAny\", fns[i]);\n }\n this._all = [];\n }\n return this;\n };\n\n EventEmitter.prototype.removeListener = EventEmitter.prototype.off;\n\n EventEmitter.prototype.removeAllListeners = function(type) {\n if (type === undefined) {\n !this._events || init.call(this);\n return this;\n }\n\n if (this.wildcard) {\n var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();\n var leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0);\n\n for (var iLeaf=0; iLeaf<leafs.length; iLeaf++) {\n var leaf = leafs[iLeaf];\n leaf._listeners = null;\n }\n }\n else if (this._events) {\n this._events[type] = null;\n }\n return this;\n };\n\n EventEmitter.prototype.listeners = function(type) {\n if (this.wildcard) {\n var handlers = [];\n var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();\n searchListenerTree.call(this, handlers, ns, this.listenerTree, 0);\n return handlers;\n }\n\n this._events || init.call(this);\n\n if (!this._events[type]) this._events[type] = [];\n if (!isArray(this._events[type])) {\n this._events[type] = [this._events[type]];\n }\n return this._events[type];\n };\n\n EventEmitter.prototype.eventNames = function(){\n return Object.keys(this._events);\n }\n\n EventEmitter.prototype.listenerCount = function(type) {\n return this.listeners(type).length;\n };\n\n EventEmitter.prototype.listenersAny = function() {\n\n if(this._all) {\n return this._all;\n }\n else {\n return [];\n }\n\n };\n\n if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define(function() {\n return EventEmitter;\n });\n } else if (typeof exports === 'object') {\n // CommonJS\n module.exports = EventEmitter;\n }\n else {\n // Browser global.\n window.EventEmitter2 = EventEmitter;\n }\n}();\n"]}