Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / ui / ThrottledWidget.js
blob5f49e8cc4f27d6ad6a227d56b320be7a5c1c0e24
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.
5 /**
6 * @constructor
7 * @extends {WebInspector.Widget}
8 */
9 WebInspector.ThrottledWidget = function()
11 WebInspector.Widget.call(this);
12 this._updateThrottler = new WebInspector.Throttler(100);
13 this._updateWhenVisible = false;
16 WebInspector.ThrottledWidget.prototype = {
17 /**
18 * @protected
19 * @return {!Promise.<?>}
21 doUpdate: function()
23 return Promise.resolve();
26 update: function()
28 this._updateWhenVisible = !this.isShowing();
29 if (this._updateWhenVisible)
30 return;
31 this._updateThrottler.schedule(innerUpdate.bind(this));
33 /**
34 * @this {WebInspector.ThrottledWidget}
35 * @return {!Promise.<?>}
37 function innerUpdate()
39 if (this.isShowing()) {
40 return this.doUpdate();
41 } else {
42 this._updateWhenVisible = true;
43 return Promise.resolve();
48 /**
49 * @override
51 wasShown: function()
53 WebInspector.Widget.prototype.wasShown.call(this);
54 if (this._updateWhenVisible)
55 this.update();
58 __proto__: WebInspector.Widget.prototype