| OLD | NEW |
| 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-load is a simple variant of dom-if designed for lazy | 7 * settings-idle-load is a simple variant of dom-if designed for lazy |
| 8 * loading and rendering of elements that are accessed imperatively. A URL is | 8 * loading and rendering of elements that are accessed imperatively. A URL is |
| 9 * given that holds the elements to be loaded lazily. | 9 * given that holds the elements to be loaded lazily. |
| 10 */ | 10 */ |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 }, | 40 }, |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * @return {!Promise<Element>} Child element which has been stamped into the | 43 * @return {!Promise<Element>} Child element which has been stamped into the |
| 44 * DOM tree. | 44 * DOM tree. |
| 45 */ | 45 */ |
| 46 get: function() { | 46 get: function() { |
| 47 if (this.loading_) | 47 if (this.loading_) |
| 48 return this.loading_; | 48 return this.loading_; |
| 49 | 49 |
| 50 this.loading_ = new Promise(function(resolve, reject) { | 50 this.loading_ = new Promise((resolve, reject) => { |
| 51 this.importHref(this.url, function() { | 51 this.importHref(this.url, () => { |
| 52 assert(!this.ctor); | 52 assert(!this.ctor); |
| 53 this.templatize(this); | 53 this.templatize(this); |
| 54 assert(this.ctor); | 54 assert(this.ctor); |
| 55 | 55 |
| 56 var instance = this.stamp({}); | 56 var instance = this.stamp({}); |
| 57 | 57 |
| 58 assert(!this.child_); | 58 assert(!this.child_); |
| 59 this.child_ = instance.root.firstElementChild; | 59 this.child_ = instance.root.firstElementChild; |
| 60 | 60 |
| 61 this.parentNode.insertBefore(instance.root, this); | 61 this.parentNode.insertBefore(instance.root, this); |
| 62 resolve(this.child_); | 62 resolve(this.child_); |
| 63 | 63 |
| 64 this.fire('lazy-loaded'); | 64 this.fire('lazy-loaded'); |
| 65 }.bind(this), reject, true); | 65 }, reject, true); |
| 66 }.bind(this)); | 66 }); |
| 67 | 67 |
| 68 return this.loading_; | 68 return this.loading_; |
| 69 }, | 69 }, |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * @param {string} prop | 72 * @param {string} prop |
| 73 * @param {Object} value | 73 * @param {Object} value |
| 74 */ | 74 */ |
| 75 _forwardParentProp: function(prop, value) { | 75 _forwardParentProp: function(prop, value) { |
| 76 if (this.child_) | 76 if (this.child_) |
| 77 this.child_._templateInstance[prop] = value; | 77 this.child_._templateInstance[prop] = value; |
| 78 }, | 78 }, |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * @param {string} path | 81 * @param {string} path |
| 82 * @param {Object} value | 82 * @param {Object} value |
| 83 */ | 83 */ |
| 84 _forwardParentPath: function(path, value) { | 84 _forwardParentPath: function(path, value) { |
| 85 if (this.child_) | 85 if (this.child_) |
| 86 this.child_._templateInstance.notifyPath(path, value, true); | 86 this.child_._templateInstance.notifyPath(path, value, true); |
| 87 } | 87 } |
| 88 }); | 88 }); |
| OLD | NEW |