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

Unified Diff: lib/messaging.js

Issue 29338534: Issue 3826 - Filter preference change events (Closed)
Patch Set: Fixed some issues Created March 23, 2016, 11:32 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
« lib/events.js ('K') | « lib/events.js ('k') | lib/prefs.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/messaging.js
===================================================================
--- a/lib/messaging.js
+++ b/lib/messaging.js
@@ -19,6 +19,8 @@
"use strict";
+let {EventEmitter} = require("events");
+
/**
* Communication port wrapping ext.onMessage to receive messages.
*
@@ -26,7 +28,7 @@
*/
function Port()
{
- this._callbacks = Object.create(null);
+ this._eventEmitter = new EventEmitter();
this._onMessage = this._onMessage.bind(this);
ext.onMessage.addListener(this._onMessage);
};
@@ -35,7 +37,7 @@
_onMessage: function(message, sender, sendResponse)
{
let async = false;
- let callbacks = this._callbacks[message.type];
+ let callbacks = this._eventEmitter._listeners[message.type];
if (callbacks)
{
@@ -84,10 +86,7 @@
*/
on: function(name, callback)
{
- if (name in this._callbacks)
- this._callbacks[name].push(callback);
- else
- this._callbacks[name] = [callback];
+ this._eventEmitter.on(name, callback);
},
/**
@@ -98,13 +97,7 @@
*/
off: function(name, callback)
{
- let callbacks = this._callbacks[name];
- if (callbacks)
- {
- let idx = callbacks.indexOf(callback);
- if (idx != -1)
- callbacks.splice(idx, 1);
- }
+ this._eventEmitter.off(name, callback);
},
/**
« lib/events.js ('K') | « lib/events.js ('k') | lib/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld