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

Side by Side Diff: lib/events.js

Issue 29339038: Issue 3862 - Added EventEmitter.listeners() (Closed)
Patch Set: Added missing documentation for argument Created March 24, 2016, 11:25 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 { 73 {
74 this.off(name, listener); 74 this.off(name, listener);
75 resolve(); 75 resolve();
76 }; 76 };
77 77
78 this.on(name, listener); 78 this.on(name, listener);
79 }); 79 });
80 }, 80 },
81 81
82 /** 82 /**
83 * Returns a copy of the array of listeners for the specified event.
84 *
85 * @param {string} name
86 * @return {function[]}
87 */
88 listeners: function(name)
89 {
90 let listeners = this._listeners[name];
91 return listeners ? listeners.slice() : [];
92 },
93
94 /**
83 * Calls all previously added listeners for the given event name. 95 * Calls all previously added listeners for the given event name.
84 * 96 *
85 * @param {string} name 97 * @param {string} name
86 * @param {...*} [arg] 98 * @param {...*} [arg]
87 */ 99 */
88 emit: function(name) 100 emit: function(name)
89 { 101 {
90 let listeners = this._listeners[name]; 102 let args = [];
kzar 2016/03/24 11:29:53 Any reason why you now create the args array even
Sebastian Noack 2016/03/24 11:33:27 To keep the logic simple. Before we had to handle
kzar 2016/03/24 11:35:58 Fair enough I guess
91 if (listeners) 103 for (let i = 1; i < arguments.length; i++)
92 { 104 args.push(arguments[i]);
93 let args = [];
94 for (let i = 1; i < arguments.length; i++)
95 args.push(arguments[i]);
96 105
97 let currentListeners = listeners.slice(); 106 let listeners = this.listeners(name);
98 for (let listener of currentListeners) 107 for (let listener of listeners)
99 listener.apply(null, args); 108 listener.apply(null, args);
100 }
101 } 109 }
102 }; 110 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld