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

Unified Diff: lib/events.js

Issue 29855595: Issue 6741 - Use ES2015 classes in lib/events.js (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Address PS3 Comment Created Aug. 17, 2018, 5:26 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 | 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
@@ -14,94 +14,96 @@
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
/**
* Registers and emits named events.
- *
- * @constructor
*/
-exports.EventEmitter = function()
+class EventEmitter
{
- this._listeners = new Map();
-};
+ constructor()
+ {
+ this._listeners = new Map();
+ }
-exports.EventEmitter.prototype = {
/**
* Adds a listener for the specified event name.
*
* @param {string} name
* @param {function} listener
*/
on(name, listener)
{
let listeners = this._listeners.get(name);
if (listeners)
listeners.push(listener);
else
this._listeners.set(name, [listener]);
- },
+ }
/**
* Removes a listener for the specified event name.
*
* @param {string} name
* @param {function} listener
*/
off(name, listener)
{
let listeners = this._listeners.get(name);
if (listeners)
{
let idx = listeners.indexOf(listener);
if (idx != -1)
listeners.splice(idx, 1);
}
- },
+ }
/**
* Adds a one time listener and returns a promise that
* is resolved the next time the specified event is emitted.
+ *
* @param {string} name
- * @return {Promise}
+ * @returns {Promise}
*/
once(name)
{
return new Promise(resolve =>
{
let listener = () =>
{
this.off(name, listener);
resolve();
};
this.on(name, listener);
});
- },
+ }
/**
* Returns a copy of the array of listeners for the specified event.
*
* @param {string} name
- * @return {function[]}
+ * @returns {Array.<function>}
*/
listeners(name)
{
let listeners = this._listeners.get(name);
return listeners ? listeners.slice() : [];
- },
+ }
/**
* Calls all previously added listeners for the given event name.
*
* @param {string} name
- * @param {...*} [arg]
+ * @param {...*} [args]
*/
emit(name, ...args)
{
let listeners = this.listeners(name);
for (let listener of listeners)
listener(...args);
}
-};
+}
+
+exports.EventEmitter = EventEmitter;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld