Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: chrome/browser/resources/settings/controls/settings_lazy_render.js

Issue 2660383002: [MD settings] idle load basic and advanced pages (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
7 * settings-lazy-render is a simple variant of dom-if designed for lazy
8 * rendering of elements that are accessed imperatively.
9 * If a use for idle time expansion is found outside of settings, this code
10 * should be replaced by cr-lazy-render after that feature is merged into
11 * ui/webui/resources/cr_elements/cr_lazy_render/cr_lazy_render.js
12 */
13
14 Polymer({
15 is: 'settings-lazy-render',
Dan Beam 2017/01/31 03:19:21 settings-idle-render?
dschuyler 2017/01/31 22:03:53 Done.
16 extends: 'template',
17
18 behaviors: [Polymer.Templatizer],
19
20 properties: {
21 /**
22 * Expand the contents of the template when the JavaScript thread is idle.
23 * This Boolean takes action when it is set to true from the false state.
24 * Setting the value to false doesn't undo the call to |render_|.
25 */
26 renderWhenIdle: {
27 observer: 'renderWhenIdleChanged_',
28 type: Boolean,
29 },
30 },
31
32 /** @private {TemplatizerNode} */
33 child_: null,
34
35 /** @override */
36 attached: function() {
37 this.renderWhenIdleChanged_();
38 },
39
40 /** @override */
41 detached: function() {
42 if (this.idleCallback_)
43 cancelIdleCallback(this.idleCallback_);
44 },
45
46 /** @private */
47 renderWhenIdleChanged_: function() {
48 if (this.renderWhenIdle)
49 this.idleCallback_ = requestIdleCallback(this.render_.bind(this));
50 },
51
52 /**
53 * Stamp the template into the DOM tree synchronously
54 * @return {Element} Child element which has been stamped into the DOM tree.
55 */
56 get: function() {
57 if (!this.child_)
58 this.render_();
59 return this.child_;
60 },
61
62 /**
63 * @return {?Element} The element contained in the template, if it has
64 * already been stamped.
65 */
66 getIfExists: function() {
Dan Beam 2017/01/31 03:19:21 where is this used?
dschuyler 2017/01/31 22:03:53 It was to keep parity with cr_lazy_render; which h
67 return this.child_;
68 },
69
70 /** @private */
71 render_: function() {
72 if (!this.ctor)
73 this.templatize(this);
74 var parentNode = this.parentNode;
75 if (parentNode && !this.child_) {
76 var instance = this.stamp({});
77 this.child_ = instance.root.firstElementChild;
78 parentNode.insertBefore(instance.root, this);
79 }
80 },
81
82 /**
83 * @param {string} prop
84 * @param {Object} value
85 */
86 _forwardParentProp: function(prop, value) {
87 if (this.child_)
88 this.child_._templateInstance[prop] = value;
89 },
90
91 /**
92 * @param {string} path
93 * @param {Object} value
94 */
95 _forwardParentPath: function(path, value) {
96 if (this.child_)
97 this.child_._templateInstance.notifyPath(path, value, true);
98 }
99 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698