| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** | 4 /** |
| 5 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 WebInspector.ThrottledWidget = class extends WebInspector.VBox { | 7 UI.ThrottledWidget = class extends UI.VBox { |
| 8 /** | 8 /** |
| 9 * @param {boolean=} isWebComponent | 9 * @param {boolean=} isWebComponent |
| 10 */ | 10 */ |
| 11 constructor(isWebComponent) { | 11 constructor(isWebComponent) { |
| 12 super(isWebComponent); | 12 super(isWebComponent); |
| 13 this._updateThrottler = new WebInspector.Throttler(100); | 13 this._updateThrottler = new Common.Throttler(100); |
| 14 this._updateWhenVisible = false; | 14 this._updateWhenVisible = false; |
| 15 } | 15 } |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * @protected | 18 * @protected |
| 19 * @return {!Promise<?>} | 19 * @return {!Promise<?>} |
| 20 */ | 20 */ |
| 21 doUpdate() { | 21 doUpdate() { |
| 22 return Promise.resolve(); | 22 return Promise.resolve(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 update() { | 25 update() { |
| 26 this._updateWhenVisible = !this.isShowing(); | 26 this._updateWhenVisible = !this.isShowing(); |
| 27 if (this._updateWhenVisible) | 27 if (this._updateWhenVisible) |
| 28 return; | 28 return; |
| 29 this._updateThrottler.schedule(innerUpdate.bind(this)); | 29 this._updateThrottler.schedule(innerUpdate.bind(this)); |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @this {WebInspector.ThrottledWidget} | 32 * @this {UI.ThrottledWidget} |
| 33 * @return {!Promise<?>} | 33 * @return {!Promise<?>} |
| 34 */ | 34 */ |
| 35 function innerUpdate() { | 35 function innerUpdate() { |
| 36 if (this.isShowing()) | 36 if (this.isShowing()) |
| 37 return this.doUpdate(); | 37 return this.doUpdate(); |
| 38 this._updateWhenVisible = true; | 38 this._updateWhenVisible = true; |
| 39 return Promise.resolve(); | 39 return Promise.resolve(); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * @override | 44 * @override |
| 45 */ | 45 */ |
| 46 wasShown() { | 46 wasShown() { |
| 47 super.wasShown(); | 47 super.wasShown(); |
| 48 if (this._updateWhenVisible) | 48 if (this._updateWhenVisible) |
| 49 this.update(); | 49 this.update(); |
| 50 } | 50 } |
| 51 }; | 51 }; |
| OLD | NEW |