OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 Class that manages the addition and removal of WebUI |
| 7 * listeners. |
| 8 */ |
| 9 |
| 10 /** |
| 11 * Create a WebUIListenerTracker to track a set of Web UI listeners. |
| 12 * @constructor |
| 13 */ |
| 14 function WebUIListenerTracker() { |
| 15 /** |
| 16 * The Web UI listeners being tracked. |
| 17 * @private {!Array<!WebUIListener>} |
| 18 */ |
| 19 this.listeners_ = []; |
| 20 } |
| 21 |
| 22 WebUIListenerTracker.prototype = { |
| 23 /** |
| 24 * Adds a WebUI listener to the array of listeners being tracked, which |
| 25 * will be removed when removeAll() is called. |
| 26 * Do not use this method if the listener will be removed manually. |
| 27 * @param {string} eventName The event to listen to. |
| 28 * @param {!Function} callback The callback to run when the event is fired. |
| 29 */ |
| 30 add: function(eventName, callback) { |
| 31 this.listeners_.push(cr.addWebUIListener(eventName, callback)); |
| 32 }, |
| 33 |
| 34 /** |
| 35 * Removes all Web UI listeners that are currently being tracked. |
| 36 */ |
| 37 removeAll: function() { |
| 38 while (this.listeners_.length > 0) { |
| 39 cr.removeWebUIListener(this.listeners_.pop()); |
| 40 } |
| 41 }, |
| 42 }; |
OLD | NEW |