Skip to content

Commit

Permalink
Assemble effect strings at prototype time.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Oct 20, 2015
1 parent d3c4611 commit 4745e8f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
12 changes: 3 additions & 9 deletions src/lib/bind/accessors.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@

_modelApi: {

_notifyChange: function(property) {
var eventName = Polymer.CaseMap.camelToDashCase(property) + '-changed';
Polymer.Base.fire(eventName, {
value: this[property]
}, {bubbles: false, node: this});
_notifyChange: function(event, value) {
Polymer.Base.fire(event, {value: value}, {bubbles: false, node: this});
},

// TODO(sjmiles): removing _notifyListener from here breaks accessors.html
Expand Down Expand Up @@ -80,10 +77,7 @@

_effectEffects: function(property, value, effects, old, fromAbove) {
for (var i=0, l=effects.length, fx; (i<l) && (fx=effects[i]); i++) {
var fn = fx.fn || Polymer.Bind['_' + fx.kind + 'Effect'];
if (fn) {
fn.call(this, property, value, fx.effect, old, fromAbove);
}
fx.fn.call(this, property, value, fx.effect, old, fromAbove);
}
},

Expand Down
6 changes: 3 additions & 3 deletions src/lib/bind/effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
}
},

_reflectEffect: function(source) {
this.reflectPropertyToAttribute(source);
_reflectEffect: function(source, value, effect) {
this.reflectPropertyToAttribute(source, effect.attribute, value);
},

_notifyEffect: function(source, value, effect, old, fromAbove) {
if (!fromAbove) {
this._notifyChange(source);
this._notifyChange(effect.event, value);
}
},

Expand Down
10 changes: 8 additions & 2 deletions src/lib/template/templatizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,17 @@
// that should be implemented by Templatizer users
for (prop in parentProps) {
var parentProp = this._parentPropPrefix + prop;
// TODO(sorvell): remove reference Bind library functions here.
// Needed for effect optimization.
var effects = [{
kind: 'function',
effect: this._createForwardPropEffector(prop)
effect: this._createForwardPropEffector(prop),
fn: Polymer.Bind._functionEffect
}, {
kind: 'notify'
kind: 'notify',
fn: Polymer.Bind._notifyEffect,
effect: {event:
Polymer.CaseMap.camelToDashCase(parentProp) + '-changed'}
}];
Polymer.Bind._createAccessors(proto, parentProp, effects);
}
Expand Down
11 changes: 7 additions & 4 deletions src/micro/attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,15 @@
* `properties` configuration to achieve automatic attribute reflection.
*
* @method reflectPropertyToAttribute
* @param {string} name Property name to reflect.
* @param {string} property Property name to reflect.
* @param {*=} attribute Attribute name to reflect.
* @param {*=} value Property value to refect.
*/
reflectPropertyToAttribute: function(name) {
reflectPropertyToAttribute: function(property, attribute, value) {
this._serializing = true;
this.serializeValueToAttribute(this[name],
Polymer.CaseMap.camelToDashCase(name));
value = (value === undefined) ? this[property] : value;
this.serializeValueToAttribute(value,
attribute || Polymer.CaseMap.camelToDashCase(property));
this._serializing = false;
},

Expand Down
7 changes: 5 additions & 2 deletions src/standard/effectBuilder.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@
this._addComputedEffect(p, prop.computed);
}
if (prop.notify) {
this._addPropertyEffect(p, 'notify');
this._addPropertyEffect(p, 'notify', {
event: Polymer.CaseMap.camelToDashCase(p) + '-changed'});
}
if (prop.reflectToAttribute) {
this._addPropertyEffect(p, 'reflect');
this._addPropertyEffect(p, 'reflect', {
attribute: Polymer.CaseMap.camelToDashCase(p)
});
}
if (prop.readOnly) {
// Ensure accessor is created
Expand Down

0 comments on commit 4745e8f

Please sign in to comment.