Skip to content

Commit

Permalink
memoize pathFn on effect (note: notifyPath change made in previous co…
Browse files Browse the repository at this point in the history
…mmit); avoid forEach.
  • Loading branch information
Steven Orvell committed Nov 3, 2015
1 parent d2c02a9 commit d93340a
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/standard/effectBuilder.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<link rel="import" href="../lib/bind/effects.html">

<script>

/**
* Support for property side effects.
*
Expand All @@ -33,7 +32,9 @@
Polymer.Base._addFeature({

_addPropertyEffect: function(property, kind, effect) {
Polymer.Bind.addPropertyEffect(this, property, kind, effect);
var prop = Polymer.Bind.addPropertyEffect(this, property, kind, effect);
// memoize path function for faster lookup.
prop.pathFn = this['_' + prop.kind + 'PathEffect'];
},

// prototyping
Expand Down Expand Up @@ -78,14 +79,14 @@

_addComputedEffect: function(name, expression) {
var sig = this._parseMethod(expression);
sig.args.forEach(function(arg) {
for (var i=0, arg; (i<sig.args.length) && (arg=sig.args[i]); i++) {
this._addPropertyEffect(arg.model, 'compute', {
method: sig.method,
args: sig.args,
trigger: arg,
name: name
});
}, this);
}
},

_addObserverEffect: function(property, observer) {
Expand All @@ -97,34 +98,35 @@

_addComplexObserverEffects: function(observers) {
if (observers) {
observers.forEach(function(observer) {
this._addComplexObserverEffect(observer);
}, this);
for (var i=0, o; (i<observers.length) && (o=observers[i]); i++) {
this._addComplexObserverEffect(o);
}
}
},

_addComplexObserverEffect: function(observer) {
var sig = this._parseMethod(observer);
sig.args.forEach(function(arg) {
for (var i=0, arg; (i<sig.args.length) && (arg=sig.args[i]); i++) {
this._addPropertyEffect(arg.model, 'complexObserver', {
method: sig.method,
args: sig.args,
trigger: arg
});
}, this);
}
},

_addAnnotationEffects: function(notes) {
// create a virtual annotation list, must be concretized at instance time
this._nodes = [];
// process annotations that have been parsed from template
notes.forEach(function(note) {
for (var i=0, note; (i<notes.length) && (note=notes[i]); i++) {
// where to find the node in the concretized list
var index = this._nodes.push(note) - 1;
note.bindings.forEach(function(binding) {
var b$ = note.bindings;
for (var j=0, binding; (j<b$.length) && (binding=b$[j]); j++) {
this._addAnnotationEffect(binding, index);
}, this);
}, this);
}
}
},

_addAnnotationEffect: function(note, index) {
Expand Down Expand Up @@ -160,11 +162,12 @@
if (sig.static) {
this.__addAnnotatedComputationEffect('__static__', index, note, part, null);
} else {
sig.args.forEach(function(arg) {
for (var i=0, arg; (i<sig.args.length) && (arg=sig.args[i]); i++) {
if (!arg.literal) {
this.__addAnnotatedComputationEffect(arg.model, index, note, part, arg);
this.__addAnnotatedComputationEffect(arg.model, index, note, part,
arg);
}
}, this);
}
}
},

Expand Down Expand Up @@ -259,10 +262,11 @@
},

// instancing

_marshalInstanceEffects: function() {
Polymer.Bind.prepareInstance(this);
Polymer.Bind.setupBindListeners(this);
if (this._bindListeners) {
Polymer.Bind.setupBindListeners(this);
}
},

_applyEffectValue: function(info, value) {
Expand Down Expand Up @@ -296,11 +300,10 @@
},

_executeStaticEffects: function() {
if (this._propertyEffects.__static__) {
if (this._propertyEffects && this._propertyEffects.__static__) {
this._effectEffects('__static__', null, this._propertyEffects.__static__);
}
}

});

</script>

0 comments on commit d93340a

Please sign in to comment.