diff --git a/src/polymer-expressions.js b/src/polymer-expressions.js
index 3f20943..c5faaaf 100644
--- a/src/polymer-expressions.js
+++ b/src/polymer-expressions.js
@@ -286,6 +286,21 @@
left = getFn(left);
right = getFn(right);
+ switch (op) {
+ case '||':
+ this.dynamicDeps = true;
+ return function(model, observer, filterRegistry) {
+ return left(model, observer, filterRegistry) ||
+ right(model, observer, filterRegistry);
+ };
+ case '&&':
+ this.dynamicDeps = true;
+ return function(model, observer, filterRegistry) {
+ return left(model, observer, filterRegistry) &&
+ right(model, observer, filterRegistry);
+ };
+ }
+
return function(model, observer, filterRegistry) {
return binaryOperators[op](left(model, observer, filterRegistry),
right(model, observer, filterRegistry));
@@ -297,6 +312,8 @@
consequent = getFn(consequent);
alternate = getFn(alternate);
+ this.dynamicDeps = true;
+
return function(model, observer, filterRegistry) {
return test(model, observer, filterRegistry) ?
consequent(model, observer, filterRegistry) :
diff --git a/tests/tests.js b/tests/tests.js
index 2e417ec..ec59a47 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -749,6 +749,44 @@ suite('PolymerExpressions', function() {
});
});
+ test('Expressions Conditional 2', function(done) {
+ var div = createTestHtml(
+ '' +
+ '{{ checked ? a : b }}' +
+ '');
+ var model = {
+ checked: false,
+ a: 'A',
+ b: 'B'
+ };
+
+ recursivelySetTemplateModel(div, model);
+
+ then(function() {
+ assert.strictEqual('B', div.childNodes[1].textContent);
+
+ model.checked = true;
+
+ }).then(function() {
+ assert.strictEqual('A', div.childNodes[1].textContent);
+
+ model.a = 'AAA';
+ }).then(function() {
+ assert.strictEqual('AAA', div.childNodes[1].textContent);
+
+ model.checked = false;
+
+ }).then(function() {
+ assert.strictEqual('B', div.childNodes[1].textContent);
+
+ model.b = 'BBB';
+ }).then(function() {
+ assert.strictEqual('BBB', div.childNodes[1].textContent);
+
+ done();
+ });
+ });
+
test('Expressions Literals', function(done) {
var div = createTestHtml(
'' +
@@ -2076,4 +2114,122 @@ suite('PolymerExpressions', function() {
});
});
+ test('lazy conditional', function(done) {
+ var div = createTestHtml(
+ '' +
+ '{{ a ? b : c }}' +
+ '');
+ var count = 0;
+ var model = {
+ a: true,
+ b: 'B',
+ get c() {
+ count++;
+ }
+ };
+
+ recursivelySetTemplateModel(div, model);
+
+ then(function() {
+ assert.equal('B', div.childNodes[1].textContent);
+ assert.equal(0, count);
+
+ model.b = 'BB';
+
+ }).then(function() {
+ assert.equal('BB', div.childNodes[1].textContent);
+ assert.equal(0, count);
+
+ done();
+ });
+ });
+
+ test('lazy conditional 2', function(done) {
+ var div = createTestHtml(
+ '' +
+ '{{ a ? b : c }}' +
+ '');
+ var count = 0;
+ var model = {
+ a: false,
+ get b() {
+ count++;
+ },
+ c: 'C'
+ };
+
+ recursivelySetTemplateModel(div, model);
+
+ then(function() {
+ assert.equal('C', div.childNodes[1].textContent);
+ assert.equal(0, count);
+
+ model.c = 'CC';
+
+ }).then(function() {
+ assert.equal('CC', div.childNodes[1].textContent);
+ assert.equal(0, count);
+
+ done();
+ });
+ });
+
+ test('lazy or', function(done) {
+ var div = createTestHtml(
+ '' +
+ '{{ a || b }}' +
+ '');
+ var count = 0;
+ var model = {
+ a: 'A',
+ get b() {
+ count++;
+ },
+ };
+
+ recursivelySetTemplateModel(div, model);
+
+ then(function() {
+ assert.equal('A', div.childNodes[1].textContent);
+ assert.equal(0, count);
+
+ model.a = 'AA';
+
+ }).then(function() {
+ assert.equal('AA', div.childNodes[1].textContent);
+ assert.equal(0, count);
+
+ done();
+ });
+ });
+
+ test('lazy and', function(done) {
+ var div = createTestHtml(
+ '' +
+ '{{ a && b }}' +
+ '');
+ var count = 0;
+ var model = {
+ a: false,
+ get b() {
+ count++;
+ },
+ };
+
+ recursivelySetTemplateModel(div, model);
+
+ then(function() {
+ assert.equal('false', div.childNodes[1].textContent);
+ assert.equal(0, count);
+
+ model.a = 0;
+
+ }).then(function() {
+ assert.equal('0', div.childNodes[1].textContent);
+ assert.equal(0, count);
+
+ done();
+ });
+ });
+
});