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 | |
5 /** | 4 /** |
6 * @constructor | 5 * @unrestricted |
7 * @extends {WebInspector.VBox} | |
8 * @param {boolean=} isWebComponent | |
9 */ | 6 */ |
10 WebInspector.ThrottledWidget = function(isWebComponent) | 7 WebInspector.ThrottledWidget = class extends WebInspector.VBox { |
11 { | 8 /** |
12 WebInspector.VBox.call(this, isWebComponent); | 9 * @param {boolean=} isWebComponent |
| 10 */ |
| 11 constructor(isWebComponent) { |
| 12 super(isWebComponent); |
13 this._updateThrottler = new WebInspector.Throttler(100); | 13 this._updateThrottler = new WebInspector.Throttler(100); |
14 this._updateWhenVisible = false; | 14 this._updateWhenVisible = false; |
15 }; | 15 } |
16 | 16 |
17 WebInspector.ThrottledWidget.prototype = { | 17 /** |
| 18 * @protected |
| 19 * @return {!Promise<?>} |
| 20 */ |
| 21 doUpdate() { |
| 22 return Promise.resolve(); |
| 23 } |
| 24 |
| 25 update() { |
| 26 this._updateWhenVisible = !this.isShowing(); |
| 27 if (this._updateWhenVisible) |
| 28 return; |
| 29 this._updateThrottler.schedule(innerUpdate.bind(this)); |
| 30 |
18 /** | 31 /** |
19 * @protected | 32 * @this {WebInspector.ThrottledWidget} |
20 * @return {!Promise<?>} | 33 * @return {!Promise<?>} |
21 */ | 34 */ |
22 doUpdate: function() | 35 function innerUpdate() { |
23 { | 36 if (this.isShowing()) |
24 return Promise.resolve(); | 37 return this.doUpdate(); |
25 }, | 38 this._updateWhenVisible = true; |
| 39 return Promise.resolve(); |
| 40 } |
| 41 } |
26 | 42 |
27 update: function() | 43 /** |
28 { | 44 * @override |
29 this._updateWhenVisible = !this.isShowing(); | 45 */ |
30 if (this._updateWhenVisible) | 46 wasShown() { |
31 return; | 47 super.wasShown(); |
32 this._updateThrottler.schedule(innerUpdate.bind(this)); | 48 if (this._updateWhenVisible) |
33 | 49 this.update(); |
34 /** | 50 } |
35 * @this {WebInspector.ThrottledWidget} | |
36 * @return {!Promise<?>} | |
37 */ | |
38 function innerUpdate() | |
39 { | |
40 if (this.isShowing()) | |
41 return this.doUpdate(); | |
42 this._updateWhenVisible = true; | |
43 return Promise.resolve(); | |
44 } | |
45 }, | |
46 | |
47 /** | |
48 * @override | |
49 */ | |
50 wasShown: function() | |
51 { | |
52 WebInspector.VBox.prototype.wasShown.call(this); | |
53 if (this._updateWhenVisible) | |
54 this.update(); | |
55 }, | |
56 | |
57 __proto__: WebInspector.VBox.prototype | |
58 }; | 51 }; |
OLD | NEW |