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