Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit e0a6646

Browse files
committed
avoid extraneous first-time expression eval
R=arv BUG= Review URL: https://codereview.appspot.com/73050044
1 parent 470cced commit e0a6646

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/polymer-expressions.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,18 @@
437437
return this.getValue(model, undefined, filterRegistry);
438438

439439
var observer = new CompoundObserver();
440-
this.getValue(model, observer, filterRegistry); // captures deps.
440+
// captures deps.
441+
var firstValue = this.getValue(model, observer, filterRegistry);
442+
var firstTime = true;
441443
var self = this;
442444

443445
function valueFn() {
446+
// deps cannot have changed on first value retrieval.
447+
if (firstTime) {
448+
firstTime = false;
449+
return firstValue;
450+
}
451+
444452
if (self.dynamicDeps)
445453
observer.startReset();
446454

tests/tests.js

+28
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ suite('PolymerExpressions', function() {
106106
delegate.upperCase = function(value) {
107107
return String(value).toUpperCase();
108108
};
109+
delegate.incrProp = function(value, obj, propName) {
110+
obj[propName]++;
111+
};
109112
// filter as full object with toDOM and toModel properties
110113
delegate.plusN = {
111114
toDOM: function(value, n) {
@@ -918,6 +921,31 @@ suite('PolymerExpressions', function() {
918921
});
919922
});
920923

924+
test('Expression execution count', function(done) {
925+
var div = createTestHtml(
926+
'<template bind>' +
927+
'{{ dep | incrProp(obj, "count") }}' +
928+
'</template>');
929+
930+
var model = {
931+
dep: 1,
932+
obj: { count: 0 }
933+
};
934+
935+
recursivelySetTemplateModel(div, model);
936+
937+
then(function() {
938+
assert.equal(1, model.obj.count);
939+
model.dep++;
940+
941+
}).then(function() {
942+
assert.equal(2, model.obj.count);
943+
944+
done();
945+
});
946+
});
947+
948+
921949
test('chained filters', function(done) {
922950
var div = createTestHtml(
923951
'<template bind="{{ }}">' +

0 commit comments

Comments
 (0)