From 9a4a8b8bf24fd460bbbbf55725853c8e01be7dfc Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Mon, 23 Nov 2015 11:29:38 -0500 Subject: [PATCH] Eliminate creating accessors for parent props; use Bind API directly. --- src/lib/bind/accessors.html | 8 +++--- src/lib/template/templatizer.html | 45 ++++++++++++++++--------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/lib/bind/accessors.html b/src/lib/bind/accessors.html index 66175deae6..9d5033abd2 100644 --- a/src/lib/bind/accessors.html +++ b/src/lib/bind/accessors.html @@ -23,7 +23,7 @@ _notifyChange: function(source, event, value) { value = value === undefined ? this[source] : value; event = event || Polymer.CaseMap.camelToDashCase(source) + '-changed'; - this.fire(event, {value: value}, + this.fire(event, {value: value}, {bubbles: false, cancelable: false, _useCache: true}); }, @@ -221,10 +221,10 @@ } else { // TODO(sorvell): even though we have a `value` argument, we *must* // lookup the current value of the property. Multiple listeners and - // queued events during configuration can theoretically lead to - // divergence of the passed value from the current value, but we + // queued events during configuration can theoretically lead to + // divergence of the passed value from the current value, but we // really need to track down a specific case where this happens. - value = target[property]; + value = target.__data__ ? target.__data__[property] : target[property]; if (!isStructured) { this[path] = value; } else { diff --git a/src/lib/template/templatizer.html b/src/lib/template/templatizer.html index b76fcc463a..6640920c64 100644 --- a/src/lib/template/templatizer.html +++ b/src/lib/template/templatizer.html @@ -229,17 +229,12 @@ for (prop in this._instanceProps) { delete parentProps[prop]; } - proto = archetype._parentPropProto = Object.create(null); - if (template != this) { - // Assumption: if `this` isn't the template being templatized, - // assume that the template is not a Poylmer.Base, so prep it - // for binding - Polymer.Bind.prepareModel(proto); - Polymer.Base.prepareModelNotifyPath(proto); - } // Create accessors for each parent prop that forward the property // to template instances through abstract _forwardParentProp API // that should be implemented by Templatizer users + var propertyEffects = this.mixin({}, this._propertyEffects); + var propertyInfo = this.mixin({}, this._propertyInfo); + var prefixedParentProps = {}; for (prop in parentProps) { var parentProp = this._parentPropPrefix + prop; // TODO(sorvell): remove reference Bind library functions here. @@ -254,13 +249,22 @@ effect: {event: Polymer.CaseMap.camelToDashCase(parentProp) + '-changed'} }]; - Polymer.Bind._createAccessors(proto, parentProp, effects); + propertyEffects[parentProp] = effects; + propertyInfo[parentProp] = {}; + prefixedParentProps[parentProp] = true; } + proto = archetype._parentPropProto = { + _propertyEffects: propertyEffects, + _propertyInfo: propertyInfo, + prefixedParentProps: prefixedParentProps + }; } // capture this reference for use below var self = this; // Instance setup if (template != this) { + Polymer.Bind.prepareModel(template); + Polymer.Base.prepareModelNotifyPath(template); Polymer.Bind.prepareInstance(template); template._forwardParentProp = function(source, value) { self._forwardParentProp(source, value); @@ -282,7 +286,7 @@ _createHostPropEffector: function(prop) { var prefix = this._parentPropPrefix; return function(source, value) { - this.dataHost._templatized[prefix + prop] = value; + this.dataHost._templatized.__setProperty(prefix + prop, value); }; }, @@ -294,17 +298,14 @@ }; }, - // Similar to Polymer.Base.extend, but retains any previously set instance - // values (_propertySetter back on instance once accessor is installed) + // Extends template with parent property info & effects and seed pre-bound data _extendTemplate: function(template, proto) { - var n$ = Object.getOwnPropertyNames(proto); - for (var i=0, n; (i