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: Added missing documentation for argument Created March 24, 2016, 11:25 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,18 @@
},
/**
+ * Returns a copy of the array of listeners for the specified event.
+ *
+ * @param {string} name
+ * @return {function[]}
+ */
+ listeners: function(name)
+ {
+ let listeners = this._listeners[name];
+ return listeners ? listeners.slice() : [];
+ },
+
+ /**
* Calls all previously added listeners for the given event name.
*
* @param {string} name
@@ -87,16 +99,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 = [];
kzar 2016/03/24 11:29:53 Any reason why you now create the args array even
Sebastian Noack 2016/03/24 11:33:27 To keep the logic simple. Before we had to handle
kzar 2016/03/24 11:35:58 Fair enough I guess
+ 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