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

Unified Diff: lib/events.js

Issue 29729594: Noissue - Use Map to store EventEmitter listeners (Closed)
Patch Set: Created March 21, 2018, 1:49 p.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 | lib/filterNotifier.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/events.js
diff --git a/lib/events.js b/lib/events.js
index 3e9067a2b1bfe88ccace767b19ded6fdc42c5be1..ace413d2a26ac6e45f29cbef6f7d61acdc83284f 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -24,7 +24,7 @@
*/
exports.EventEmitter = function()
{
- this._listeners = Object.create(null);
+ this._listeners = new Map();
};
exports.EventEmitter.prototype = {
@@ -36,10 +36,10 @@ exports.EventEmitter.prototype = {
*/
on(name, listener)
{
- if (name in this._listeners)
- this._listeners[name].push(listener);
+ if (this._listeners.has(name))
Manish Jethani 2018/04/01 08:44:16 It's usually not worth calling Map.has if you're g
kzar 2018/04/03 17:27:55 Done.
+ this._listeners.get(name).push(listener);
else
- this._listeners[name] = [listener];
+ this._listeners.set(name, [listener]);
},
/**
@@ -50,7 +50,7 @@ exports.EventEmitter.prototype = {
*/
off(name, listener)
{
- let listeners = this._listeners[name];
+ let listeners = this._listeners.get(name);
Manish Jethani 2018/04/01 08:44:16 While we're at it, perhaps it would be a good idea
kzar 2018/04/03 17:27:55 Good idea, but I'd rather not since this would cha
Sebastian Noack 2018/04/03 20:42:34 What change of behavior are you concerned about? M
Manish Jethani 2018/04/04 06:54:49 Dave has a point that this would be more likely to
if (listeners)
{
let idx = listeners.indexOf(listener);
@@ -87,7 +87,7 @@ exports.EventEmitter.prototype = {
*/
listeners(name)
{
- let listeners = this._listeners[name];
+ let listeners = this._listeners.get(name);
return listeners ? listeners.slice() : [];
},
« no previous file with comments | « no previous file | lib/filterNotifier.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld