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 {!Set<!Function>} */ | |
15 this.listeners_ = new Set; | |
dpapad
2015/12/17 00:04:18
Nit: Can we use the following syntax?
this.listen
stevenjb
2015/12/17 00:18:11
Sure. That's just my C background (and newness to
| |
16 } | |
17 | |
18 FakeChromeEvent.prototype = { | |
19 /** @param {Function} listener */ | |
20 addListener: function(listener) { | |
dschuyler
2015/12/16 22:27:03
Maybe: since this is now a Set and therefore shoul
stevenjb
2015/12/17 00:18:11
Done.
| |
21 this.listeners_.add(listener); | |
22 }, | |
23 | |
24 /** @param {Function} listener */ | |
25 removeListener: function(listener) { | |
26 if (!this.listeners_.has(listener)) { | |
27 console.error('removeListener: not found'); | |
28 return; | |
29 } | |
30 this.listeners_.delete(listener); | |
31 }, | |
32 | |
33 /** @param {...} args */ | |
34 callListeners: function(...args) { | |
35 this.listeners_.forEach(function(l) { | |
36 l.apply(null, args); | |
37 }); | |
38 } | |
39 }; | |
OLD | NEW |