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

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

Issue 2669153003: [MD settings] handle being detached on cr-lazy-render and settings-idle-render
Patch Set: only call render_ once 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * settings-idle-render is a simple variant of dom-if designed for lazy 7 * settings-idle-render is a simple variant of dom-if designed for lazy
8 * rendering of elements that are accessed imperatively. 8 * rendering of elements that are accessed imperatively.
9 * If a use for idle time expansion is found outside of settings, this code 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 10 * should be replaced by cr-lazy-render after that feature is merged into
(...skipping 11 matching lines...) Expand all
22 22
23 /** @private {number} */ 23 /** @private {number} */
24 idleCallback_: 0, 24 idleCallback_: 0,
25 25
26 /** @override */ 26 /** @override */
27 attached: function() { 27 attached: function() {
28 this.idleCallback_ = requestIdleCallback(this.render_.bind(this)); 28 this.idleCallback_ = requestIdleCallback(this.render_.bind(this));
29 }, 29 },
30 30
31 /** @override */ 31 /** @override */
32 detached: function() { 32 detached: function() {
Dan Beam 2017/02/08 05:31:36 because you have a detached method, I assume this
dschuyler 2017/02/09 00:42:47 That makes sense. Rather than checking !parentNode
33 // No-op if callback already fired. 33 // No-op if callback already fired.
34 cancelIdleCallback(this.idleCallback_); 34 cancelIdleCallback(this.idleCallback_);
35 }, 35 },
36 36
37 /** 37 /**
38 * Stamp the template into the DOM tree synchronously 38 * Stamp the template into the DOM tree synchronously
39 * @return {Element} Child element which has been stamped into the DOM tree. 39 * @return {Element} Child element which has been stamped into the DOM tree.
40 */ 40 */
41 get: function() { 41 get: function() {
42 if (!this.child_) 42 if (!this.child_)
43 this.render_(); 43 this.render_();
44 return this.child_; 44 return this.child_;
45 }, 45 },
46 46
47 /** @private */ 47 /** @private */
48 render_: function() { 48 render_: function() {
49 if (!this.ctor) 49 // Only initialize once.
50 this.templatize(this); 50 assert(!this.ctor);
51 var parentNode = this.parentNode; 51 cancelIdleCallback(this.idleCallback_);
52 if (parentNode && !this.child_) { 52
53 var instance = this.stamp({}); 53 // Must have a parent and child in order to add child to parent.
54 this.child_ = instance.root.firstElementChild; 54 assert(this.parentNode && !this.child_);
55 parentNode.insertBefore(instance.root, this); 55 this.templatize(this);
56 } 56 var instance = this.stamp({});
57 this.child_ = instance.root.firstElementChild;
58 this.parentNode.insertBefore(instance.root, this);
57 }, 59 },
58 60
59 /** 61 /**
60 * @param {string} prop 62 * @param {string} prop
61 * @param {Object} value 63 * @param {Object} value
62 */ 64 */
63 _forwardParentProp: function(prop, value) { 65 _forwardParentProp: function(prop, value) {
64 if (this.child_) 66 if (this.child_)
65 this.child_._templateInstance[prop] = value; 67 this.child_._templateInstance[prop] = value;
66 }, 68 },
67 69
68 /** 70 /**
69 * @param {string} path 71 * @param {string} path
70 * @param {Object} value 72 * @param {Object} value
71 */ 73 */
72 _forwardParentPath: function(path, value) { 74 _forwardParentPath: function(path, value) {
73 if (this.child_) 75 if (this.child_)
74 this.child_._templateInstance.notifyPath(path, value, true); 76 this.child_._templateInstance.notifyPath(path, value, true);
75 } 77 }
76 }); 78 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698