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

Commit

Permalink
cr cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelw committed Jan 14, 2014
1 parent 2de2db3 commit 080d12f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
39 changes: 18 additions & 21 deletions src/polymer-expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

function Literal(value) {
this.value = value;
this.valueFn_ = undefined;
}

Literal.prototype = {
Expand Down Expand Up @@ -119,21 +120,15 @@
};

function MemberExpression(object, property, accessor) {
if (typeof object == 'function' || object.dynamic)
this.nonModelPath = true;

if (typeof property == 'function' || property.dynamic ||
(accessor == '[' && (!(property instanceof Literal)))) {
this.dynamic = true;
}

this.dynamicDeps = typeof object == 'function' || object.dynamic;
this.dynamic =
typeof property == 'function' || property.dynamic ||
(accessor == '[' && !(property instanceof Literal));
this.object = getFn(object);
this.property = accessor == '.' ? property : getFn(property);
}

MemberExpression.prototype = {
dynamic: false,
nonModelPath: false,
valueFn: function() {
if (!this.valueFn_) {
var object = this.object;
Expand Down Expand Up @@ -250,10 +245,10 @@
this.currentPath = undefined;
this.scopeIdent = undefined;
this.indexIdent = undefined;
this.dynamicDeps = false;
}

ASTDelegate.prototype = {
nonModelPath: false,
createUnaryExpression: function(op, argument) {
if (!unaryOperators[op])
throw Error('Disallowed operator: ' + op);
Expand All @@ -273,7 +268,8 @@
right = getFn(right);

return function(model, observer) {
return binaryOperators[op](left(model, observer), right(model, observer));
return binaryOperators[op](left(model, observer),
right(model, observer));
};
},

Expand All @@ -296,8 +292,8 @@

createMemberExpression: function(accessor, object, property) {
var ex = new MemberExpression(object, property, accessor);
if (ex.nonModelPath)
this.nonModelPath = true;
if (ex.dynamicDeps)
this.dynamicDeps = true;
return ex;
},

Expand Down Expand Up @@ -380,25 +376,26 @@
getFn(this.expression); // forces enumeration of path dependencies

this.filters = delegate.filters;
this.nonModelPath = delegate.nonModelPath;
this.dynamicDeps = delegate.dynamicDeps;
}

Expression.prototype = {
getBinding: function(model, filterRegistry, oneTime) {
if (oneTime)
return this.getValue(model, undefined, filterRegistry);

var observer = oneTime ? undefined : new CompoundObserver();
var value = this.getValue(model, observer, filterRegistry);
var observer = new CompoundObserver();
this.getValue(model, observer, filterRegistry); // captures deps.
var self = this;

function valueFn() {
if (self.nonModelPath)
if (self.dynamicDeps)
observer.startReset();

value = self.getValue(model, self.nonModelPath ? observer : undefined,
filterRegistry);
if (self.nonModelPath)
var value = self.getValue(model,
self.dynamicDeps ? observer : undefined,
filterRegistry);
if (self.dynamicDeps)
observer.finishReset();

return value;
Expand Down
26 changes: 13 additions & 13 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1624,18 +1624,18 @@ suite('PolymerExpressions', function() {
});
});

test('Non-model path expressions', function() {
assert.isFalse(getExpression_('a + b').nonModelPath);
assert.isFalse(getExpression_('a + b > 3 + hello["kitty"]').nonModelPath);
assert.isFalse(getExpression_('a[a.b]').nonModelPath);
assert.isFalse(getExpression_('a[a.b] + d[e]').nonModelPath);
assert.isFalse(getExpression_('a[0].c').nonModelPath);
assert.isFalse(getExpression_('a[1][0]').nonModelPath);

assert.isTrue(getExpression_('a[b].c').nonModelPath);
assert.isTrue(getExpression_('(a + 1).c').nonModelPath);
assert.isTrue(getExpression_('a[a.b].c').nonModelPath);
assert.isTrue(getExpression_('a[a][0]').nonModelPath);
assert.isTrue(getExpression_('a[a.b] + d[e].f').nonModelPath);
test('Dynamic deps path expressions', function() {
assert.isFalse(getExpression_('a + b').dynamicDeps);
assert.isFalse(getExpression_('a + b > 3 + hello["kitty"]').dynamicDeps);
assert.isFalse(getExpression_('a[a.b]').dynamicDeps);
assert.isFalse(getExpression_('a[a.b] + d[e]').dynamicDeps);
assert.isFalse(getExpression_('a[0].c').dynamicDeps);
assert.isFalse(getExpression_('a[1][0]').dynamicDeps);

assert.isTrue(getExpression_('a[b].c').dynamicDeps);
assert.isTrue(getExpression_('(a + 1).c').dynamicDeps);
assert.isTrue(getExpression_('a[a.b].c').dynamicDeps);
assert.isTrue(getExpression_('a[a][0]').dynamicDeps);
assert.isTrue(getExpression_('a[a.b] + d[e].f').dynamicDeps);
});
});

0 comments on commit 080d12f

Please sign in to comment.