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

Unified Diff: ui/webui/resources/cr_elements/cr_lazy_render/cr_lazy_render.js

Issue 2344803002: MD WebUI: Simplify usage of Templatizer in cr-lazy-render (Closed)
Patch Set: _render -> render_ Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/md_history/app.crisper.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/cr_elements/cr_lazy_render/cr_lazy_render.js
diff --git a/ui/webui/resources/cr_elements/cr_lazy_render/cr_lazy_render.js b/ui/webui/resources/cr_elements/cr_lazy_render/cr_lazy_render.js
index 0c4fb80e935048c9ad1682e0c448c2e9d5f6179e..b7c58f7d4980de51c97eb028e3be72dd36ff784a 100644
--- a/ui/webui/resources/cr_elements/cr_lazy_render/cr_lazy_render.js
+++ b/ui/webui/resources/cr_elements/cr_lazy_render/cr_lazy_render.js
@@ -16,30 +16,6 @@
* });
*/
-/**
- * A template instance created by Polymer.Templatizer.
- * @constructor
- * @extends {PolymerElement}
- */
-var TemplateInstance = function() {};
-
-/** @type {Array<Element>} */
-TemplateInstance.prototype._children;
-
-/**
- * @param {string} prop
- * @param {Object} value
- * @param {boolean} quiet
- */
-TemplateInstance.prototype.__setProperty = function(prop, value, quiet) {};
-
-/**
- * @param {string} path
- * @param {Object} value
- * @param {boolean} quiet
- */
-TemplateInstance.prototype._notifyPath = function(path, value, quiet) {};
-
Polymer({
is: 'cr-lazy-render',
extends: 'template',
@@ -49,10 +25,10 @@ Polymer({
],
/** @private {Promise<Element>} */
- _renderPromise: null,
+ renderPromise_: null,
- /** @private {TemplateInstance} */
- _instance: null,
+ /** @private {TemplatizerNode} */
+ child_: null,
/**
* Stamp the template into the DOM tree asynchronously
@@ -60,16 +36,16 @@ Polymer({
* been stamped.
*/
get: function() {
- if (!this._renderPromise) {
- this._renderPromise = new Promise(function(resolve) {
+ if (!this.renderPromise_) {
+ this.renderPromise_ = new Promise(function(resolve) {
this._debounceTemplate(function() {
- this._render();
- this._renderPromise = null;
+ this.render_();
+ this.renderPromise_ = null;
resolve(this.getIfExists());
}.bind(this));
}.bind(this));
}
- return this._renderPromise;
+ return this.renderPromise_;
},
/**
@@ -77,25 +53,18 @@ Polymer({
* already been stamped.
*/
getIfExists: function() {
- if (this._instance) {
- var children = this._instance._children;
-
- for (var i = 0; i < children.length; i++) {
- if (children[i].nodeType == Node.ELEMENT_NODE)
- return children[i];
- }
- }
- return null;
+ return this.child_;
},
- _render: function() {
+ /** @private */
+ render_: function() {
if (!this.ctor)
this.templatize(this);
var parentNode = this.parentNode;
- if (parentNode && !this._instance) {
- this._instance = /** @type {TemplateInstance} */(this.stamp({}));
- var root = this._instance.root;
- parentNode.insertBefore(root, this);
+ if (parentNode && !this.child_) {
+ var instance = this.stamp({});
+ this.child_ = instance.root.firstElementChild;
+ parentNode.insertBefore(instance.root, this);
}
},
@@ -104,8 +73,8 @@ Polymer({
* @param {Object} value
*/
_forwardParentProp: function(prop, value) {
- if (this._instance)
- this._instance.__setProperty(prop, value, true);
+ if (this.child_)
+ this.child_._templateInstance[prop] = value;
},
/**
@@ -113,7 +82,7 @@ Polymer({
* @param {Object} value
*/
_forwardParentPath: function(path, value) {
- if (this._instance)
- this._instance._notifyPath(path, value, true);
+ if (this.child_)
+ this.child_._templateInstance.notifyPath(path, value, true);
}
});
« no previous file with comments | « chrome/browser/resources/md_history/app.crisper.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698