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

Unified Diff: lib/messaging.js

Issue 29723558: Issue 6482 - Use ES6 classes (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created March 15, 2018, 7:46 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/filterValidation.js ('K') | « lib/filterValidation.js ('k') | no next file » | 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
@@ -18,27 +18,26 @@
/** @module messaging */
"use strict";
const {EventEmitter} = require("events");
/**
* Communication port wrapping ext.onMessage to receive messages.
- *
- * @constructor
*/
-function Port()
+class Port
{
- this._eventEmitter = new EventEmitter();
- this._onMessage = this._onMessage.bind(this);
- ext.onMessage.addListener(this._onMessage);
-}
+ constructor()
+ {
+ this._eventEmitter = new EventEmitter();
+ this._onMessage = this._onMessage.bind(this);
+ ext.onMessage.addListener(this._onMessage);
+ }
-Port.prototype = {
_onMessage(message, sender, sendResponse)
{
let async = false;
let callbacks = this._eventEmitter.listeners(message.type);
for (let callback of callbacks)
{
let response = callback(message, sender);
@@ -57,17 +56,17 @@
}
else if (typeof response != "undefined")
{
sendResponse(response);
}
}
return async;
- },
+ }
/**
* Function to be called when a particular message is received.
*
* @callback Port~messageCallback
* @param {object} message
* @param {object} sender
* @return The callback can return undefined (no response),
@@ -80,37 +79,37 @@
*
* The return value of the callback (if not undefined) is sent as response.
* @param {string} name
* @param {Port~messageCallback} callback
*/
on(name, callback)
{
this._eventEmitter.on(name, callback);
- },
+ }
/**
* Removes a callback for the specified message.
*
* @param {string} name
* @param {Port~messageCallback} callback
*/
off(name, callback)
{
this._eventEmitter.off(name, callback);
- },
+ }
/**
* Disables the port and makes it stop listening to incoming messages.
*/
disconnect()
{
ext.onMessage.removeListener(this._onMessage);
}
-};
+}
/**
* The default port to receive messages.
*
* @type {Port}
*/
exports.port = new Port();
« lib/filterValidation.js ('K') | « lib/filterValidation.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld