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

Delta Between Two Patch Sets: lib/events.js

Issue 29338969: Issue 3862 - Add EventEmitter class and implement in the FilterNotifier (Closed)
Left Patch Set: Fixed typo in comment Created March 23, 2016, 4:23 p.m.
Right Patch Set: Use arrow functions Created March 23, 2016, 5:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/filterNotifier.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 }, 60 },
61 61
62 /** 62 /**
63 * Adds a one time listener and returns a promise that 63 * Adds a one time listener and returns a promise that
64 * is resolved the next time the specified event is emitted. 64 * is resolved the next time the specified event is emitted.
65 * 65 *
66 * @return {Promise} 66 * @return {Promise}
67 */ 67 */
68 once: function(name) 68 once: function(name)
69 { 69 {
70 return new Promise(function(resolve) 70 return new Promise(resolve =>
71 { 71 {
72 let listener = function() 72 let listener = () =>
73 { 73 {
74 this.off(name, listener); 74 this.off(name, listener);
75 resolve(); 75 resolve();
76 }.bind(this); 76 };
77 77
78 this.on(name, listener); 78 this.on(name, listener);
79 }.bind(this)); 79 });
80 }, 80 },
81 81
82 /** 82 /**
83 * Calls all previously added listeners for the given event name. 83 * Calls all previously added listeners for the given event name.
84 * 84 *
85 * @param {string} name 85 * @param {string} name
86 * @param {...*} [arg] 86 * @param {...*} [arg]
87 */ 87 */
88 emit: function(name) 88 emit: function(name)
89 { 89 {
90 let listeners = this._listeners[name]; 90 let listeners = this._listeners[name];
91 if (listeners) 91 if (listeners)
92 { 92 {
93 let args = []; 93 let args = [];
94 for (let i = 1; i < arguments.length; i++) 94 for (let i = 1; i < arguments.length; i++)
95 args.push(arguments[i]); 95 args.push(arguments[i]);
96 96
97 let currentListeners = listeners.slice(); 97 let currentListeners = listeners.slice();
98 for (let listener of currentListeners) 98 for (let listener of currentListeners)
99 listener.apply(null, args); 99 listener.apply(null, args);
100 } 100 }
101 } 101 }
102 }; 102 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld