[Pkg-mozext-commits] [adblock-plus] 08/98: Issue 4129 - Reuse EventEmitter class in messaging module
David Prévot
taffit at moszumanska.debian.org
Tue Oct 24 01:30:12 UTC 2017
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit 76a3292ec6105756f57e4931b42bda0b66a0d615
Author: Wladimir Palant <trev at adblockplus.org>
Date: Tue Jun 7 18:00:21 2016 +0200
Issue 4129 - Reuse EventEmitter class in messaging module
---
lib/messaging.js | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)
diff --git a/lib/messaging.js b/lib/messaging.js
index 5e2d7f2..36d98a5 100644
--- a/lib/messaging.js
+++ b/lib/messaging.js
@@ -17,6 +17,8 @@
"use strict";
+let {EventEmitter} = require("events");
+
const MESSAGE_NAME = "AdblockPlus:Message";
const RESPONSE_NAME = "AdblockPlus:Response";
@@ -121,8 +123,8 @@ LightWeightPort.prototype =
function Port(messageManager)
{
this._messageManager = messageManager;
+ this._eventEmitter = new EventEmitter();
- this._callbacks = new Map();
this._responseCallbacks = new Map();
this._responseCallbackCounter = 0;
@@ -208,11 +210,7 @@ Port.prototype = {
_dispatch: function(messageName, payload, sender)
{
- let callbacks = this._callbacks.get(messageName);
- if (!callbacks)
- return undefined;
-
- callbacks = callbacks.slice();
+ let callbacks = this._eventEmitter.listeners(messageName);
let processor = new ResponseProcessor(messageName);
for (let callback of callbacks)
{
@@ -246,11 +244,7 @@ Port.prototype = {
*/
on: function(messageName, callback)
{
- let callbacks = this._callbacks.get(messageName);
- if (callbacks)
- callbacks.push(callback);
- else
- this._callbacks.set(messageName, [callback]);
+ this._eventEmitter.on(messageName, callback);
},
/**
@@ -260,13 +254,7 @@ Port.prototype = {
*/
off: function(messageName, callback)
{
- let callbacks = this._callbacks.get(messageName);
- if (!callbacks)
- return;
-
- let index = callbacks.indexOf(callback);
- if (index >= 0)
- callbacks.splice(index, 1);
+ this._eventEmitter.off(messageName, callback);
},
/**
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list