Skip to content

Commit

Permalink
Eliminate creating accessors for parent props; use Bind API directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Jan 29, 2016
1 parent 905a63c commit 9a4a8b8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/lib/bind/accessors.html
Original file line number Diff line number Diff line change
Expand Up @@ -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});
},

Expand Down Expand Up @@ -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 {
Expand Down
45 changes: 23 additions & 22 deletions src/lib/template/templatizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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);
};
},

Expand All @@ -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<n$.length) && (n=n$[i]); i++) {
var val = template[n];
var pd = Object.getOwnPropertyDescriptor(proto, n);
Object.defineProperty(template, n, pd);
if (val !== undefined) {
template._propertySetter(n, val);
}
template._propertyEffects = proto._propertyEffects;
template._propertyInfo = proto._propertyInfo;
var prefixedParentProps = proto.prefixedParentProps;
for (var p in prefixedParentProps) {
var val = template[p];
template.__data__[p] = val;
}
},

Expand All @@ -323,7 +324,7 @@
// Call extension point for Templatizer sub-classes
dataHost._forwardInstancePath.call(dataHost, this, path, value);
if (root in dataHost._parentProps) {
dataHost._templatized.notifyPath(dataHost._parentPropPrefix + path, value);
dataHost._templatized._notifyPath(dataHost._parentPropPrefix + path, value);
}
},

Expand Down Expand Up @@ -416,7 +417,7 @@
if (this._parentProps) {
var templatized = this._templatized;
for (var prop in this._parentProps) {
model[prop] = templatized[this._parentPropPrefix + prop];
model[prop] = templatized.__data__[this._parentPropPrefix + prop];
}
}
return new this.ctor(model, this);
Expand Down

0 comments on commit 9a4a8b8

Please sign in to comment.