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

Delta Between Two Patch Sets: lib/events.js

Issue 29339038: Issue 3862 - Added EventEmitter.listeners() (Closed)
Left Patch Set: Created March 24, 2016, 11:03 a.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 83 * Returns a copy of the array of listeners for the specified event.
84 * 84 *
85 * @param {string} name
85 * @return {function[]} 86 * @return {function[]}
86 */ 87 */
87 listeners: function(name) 88 listeners: function(name)
Sebastian Noack 2016/03/24 11:07:13 node.js has that method as well. We need it to reu
88 { 89 {
89 let listeners = this._listeners[name]; 90 let listeners = this._listeners[name];
90 return listeners ? listeners.slice() : []; 91 return listeners ? listeners.slice() : [];
91 }, 92 },
92 93
93 /** 94 /**
94 * Calls all previously added listeners for the given event name. 95 * Calls all previously added listeners for the given event name.
95 * 96 *
96 * @param {string} name 97 * @param {string} name
97 * @param {...*} [arg] 98 * @param {...*} [arg]
98 */ 99 */
99 emit: function(name) 100 emit: function(name)
100 { 101 {
101 let args = []; 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
102 for (let i = 1; i < arguments.length; i++) 103 for (let i = 1; i < arguments.length; i++)
103 args.push(arguments[i]); 104 args.push(arguments[i]);
104 105
105 let listeners = this.listeners(name); 106 let listeners = this.listeners(name);
106 for (let listener of listeners) 107 for (let listener of listeners)
107 listener.apply(null, args); 108 listener.apply(null, args);
108 } 109 }
109 }; 110 };
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld