OLD | NEW |
| (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-idle-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-idle-render', | |
16 extends: 'template', | |
17 | |
18 behaviors: [Polymer.Templatizer], | |
19 | |
20 /** @private {TemplatizerNode} */ | |
21 child_: null, | |
22 | |
23 /** @private {number} */ | |
24 idleCallback_: 0, | |
25 | |
26 /** @override */ | |
27 attached: function() { | |
28 this.idleCallback_ = requestIdleCallback(this.render_.bind(this)); | |
29 }, | |
30 | |
31 /** @override */ | |
32 detached: function() { | |
33 // No-op if callback already fired. | |
34 cancelIdleCallback(this.idleCallback_); | |
35 }, | |
36 | |
37 /** | |
38 * Stamp the template into the DOM tree synchronously | |
39 * @return {Element} Child element which has been stamped into the DOM tree. | |
40 */ | |
41 get: function() { | |
42 if (!this.child_) | |
43 this.render_(); | |
44 return this.child_; | |
45 }, | |
46 | |
47 /** @private */ | |
48 render_: function() { | |
49 if (!this.ctor) | |
50 this.templatize(this); | |
51 var parentNode = this.parentNode; | |
52 if (parentNode && !this.child_) { | |
53 var instance = this.stamp({}); | |
54 this.child_ = instance.root.firstElementChild; | |
55 parentNode.insertBefore(instance.root, this); | |
56 } | |
57 }, | |
58 | |
59 /** | |
60 * @param {string} prop | |
61 * @param {Object} value | |
62 */ | |
63 _forwardParentProp: function(prop, value) { | |
64 if (this.child_) | |
65 this.child_._templateInstance[prop] = value; | |
66 }, | |
67 | |
68 /** | |
69 * @param {string} path | |
70 * @param {Object} value | |
71 */ | |
72 _forwardParentPath: function(path, value) { | |
73 if (this.child_) | |
74 this.child_._templateInstance.notifyPath(path, value, true); | |
75 } | |
76 }); | |
OLD | NEW |