OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * @fileoverview Fake implementations of ChromeEvent. | |
7 */ | |
8 | |
9 /** | |
10 * @constructor | |
11 * @extends {ChromeEvent} | |
12 */ | |
13 function FakeChromeEvent() { | |
14 /** @type {!Array<!Function>} */ | |
15 this.listeners_ = []; | |
16 } | |
17 | |
18 FakeChromeEvent.prototype = { | |
19 /** @param {Function} listener */ | |
20 addListener: function(listener) { | |
21 this.listeners_.push(listener); | |
22 }, | |
23 | |
24 /** @param {Function} listener */ | |
25 removeListener: function(listener) { | |
26 var index = this.listeners_.indexOf(listener); | |
dpapad
2015/12/16 21:18:07
Can you use a native Javascript Set instead of an
stevenjb
2015/12/16 22:20:57
Done.
| |
27 if (index < 0) { | |
28 console.error('removeListener: not found'); | |
29 return; | |
30 } | |
31 this.listeners_.slice(index, 1); | |
32 }, | |
33 | |
34 /** @param {...} args */ | |
35 callListeners: function(...args) { | |
36 for (var l of this.listeners_) | |
37 l.apply(null, args); | |
38 } | |
39 }; | |
OLD | NEW |