Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/events.js

Issue 29339038: Issue 3862 - Added EventEmitter.listeners() (Closed)
Patch Set: Created March 24, 2016, 11:03 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/events.js
===================================================================
--- a/lib/events.js
+++ b/lib/events.js
@@ -80,6 +80,17 @@
},
/**
+ * Returns a copy of the array of listeners for the specified event.
+ *
+ * @return {function[]}
+ */
+ listeners: function(name)
Sebastian Noack 2016/03/24 11:07:13 node.js has that method as well. We need it to reu
+ {
+ let listeners = this._listeners[name];
+ return listeners ? listeners.slice() : [];
+ },
+
+ /**
* Calls all previously added listeners for the given event name.
*
* @param {string} name
@@ -87,16 +98,12 @@
*/
emit: function(name)
{
- let listeners = this._listeners[name];
- if (listeners)
- {
- let args = [];
- for (let i = 1; i < arguments.length; i++)
- args.push(arguments[i]);
+ let args = [];
+ for (let i = 1; i < arguments.length; i++)
+ args.push(arguments[i]);
- let currentListeners = listeners.slice();
- for (let listener of currentListeners)
- listener.apply(null, args);
- }
+ let listeners = this.listeners(name);
+ for (let listener of listeners)
+ listener.apply(null, args);
}
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld