Skip to content

Commit 4745e8f

Browse files
author
Steven Orvell
committed
Assemble effect strings at prototype time.
1 parent d3c4611 commit 4745e8f

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

src/lib/bind/accessors.html

+3-9
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121

2222
_modelApi: {
2323

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

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

8178
_effectEffects: function(property, value, effects, old, fromAbove) {
8279
for (var i=0, l=effects.length, fx; (i<l) && (fx=effects[i]); i++) {
83-
var fn = fx.fn || Polymer.Bind['_' + fx.kind + 'Effect'];
84-
if (fn) {
85-
fn.call(this, property, value, fx.effect, old, fromAbove);
86-
}
80+
fx.fn.call(this, property, value, fx.effect, old, fromAbove);
8781
}
8882
},
8983

src/lib/bind/effects.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
}
3636
},
3737

38-
_reflectEffect: function(source) {
39-
this.reflectPropertyToAttribute(source);
38+
_reflectEffect: function(source, value, effect) {
39+
this.reflectPropertyToAttribute(source, effect.attribute, value);
4040
},
4141

4242
_notifyEffect: function(source, value, effect, old, fromAbove) {
4343
if (!fromAbove) {
44-
this._notifyChange(source);
44+
this._notifyChange(effect.event, value);
4545
}
4646
},
4747

src/lib/template/templatizer.html

+8-2
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,17 @@
231231
// that should be implemented by Templatizer users
232232
for (prop in parentProps) {
233233
var parentProp = this._parentPropPrefix + prop;
234+
// TODO(sorvell): remove reference Bind library functions here.
235+
// Needed for effect optimization.
234236
var effects = [{
235237
kind: 'function',
236-
effect: this._createForwardPropEffector(prop)
238+
effect: this._createForwardPropEffector(prop),
239+
fn: Polymer.Bind._functionEffect
237240
}, {
238-
kind: 'notify'
241+
kind: 'notify',
242+
fn: Polymer.Bind._notifyEffect,
243+
effect: {event:
244+
Polymer.CaseMap.camelToDashCase(parentProp) + '-changed'}
239245
}];
240246
Polymer.Bind._createAccessors(proto, parentProp, effects);
241247
}

src/micro/attributes.html

+7-4
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,15 @@
118118
* `properties` configuration to achieve automatic attribute reflection.
119119
*
120120
* @method reflectPropertyToAttribute
121-
* @param {string} name Property name to reflect.
121+
* @param {string} property Property name to reflect.
122+
* @param {*=} attribute Attribute name to reflect.
123+
* @param {*=} value Property value to refect.
122124
*/
123-
reflectPropertyToAttribute: function(name) {
125+
reflectPropertyToAttribute: function(property, attribute, value) {
124126
this._serializing = true;
125-
this.serializeValueToAttribute(this[name],
126-
Polymer.CaseMap.camelToDashCase(name));
127+
value = (value === undefined) ? this[property] : value;
128+
this.serializeValueToAttribute(value,
129+
attribute || Polymer.CaseMap.camelToDashCase(property));
127130
this._serializing = false;
128131
},
129132

src/standard/effectBuilder.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@
6060
this._addComputedEffect(p, prop.computed);
6161
}
6262
if (prop.notify) {
63-
this._addPropertyEffect(p, 'notify');
63+
this._addPropertyEffect(p, 'notify', {
64+
event: Polymer.CaseMap.camelToDashCase(p) + '-changed'});
6465
}
6566
if (prop.reflectToAttribute) {
66-
this._addPropertyEffect(p, 'reflect');
67+
this._addPropertyEffect(p, 'reflect', {
68+
attribute: Polymer.CaseMap.camelToDashCase(p)
69+
});
6770
}
6871
if (prop.readOnly) {
6972
// Ensure accessor is created

0 commit comments

Comments
 (0)