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

Commit 11595a7

Browse files
committed
Fix logic in processSinglePathBinding
If the delegate returns an observer, it still must use the ObserverTransform if the binding is compound (has non-empty string tokens outside the mustache) R=arv BUG= Review URL: https://codereview.appspot.com/43060044
1 parent 2c1061c commit 11595a7

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/TemplateBinding.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,10 +653,9 @@
653653
function processSinglePathBinding(name, tokens, node, model) {
654654
var delegateFn = tokens[2];
655655
var delegateValue = delegateFn && delegateFn(model, node);
656-
if (Observer.isObservable(delegateValue))
657-
return delegateValue;
656+
var observer = Observer.isObservable(delegateValue) ? delegateValue :
657+
new PathObserver(model, tokens[1]);
658658

659-
var observer = new PathObserver(model, tokens[1]);
660659
return tokens.isSimplePath ? observer :
661660
new ObserverTransform(observer, tokens.combinator);
662661
}

tests/tests.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,34 @@ suite('Binding Delegate API', function() {
21662166

21672167
assert.equal('barValue', div.lastChild.getAttribute('bar'));
21682168
});
2169+
2170+
test('issue-18', function() {
2171+
2172+
var delegate = {
2173+
prepareBinding: function(path, name, node) {
2174+
if (name != 'class')
2175+
return;
2176+
2177+
return function(model) {
2178+
return new PathObserver(model, path);
2179+
}
2180+
}
2181+
};
2182+
2183+
var div = createTestHtml(
2184+
'<template bind>' +
2185+
'<div class="foo: {{ bar }}"></div>' +
2186+
'</template>');
2187+
2188+
var model = {
2189+
bar: 2
2190+
};
2191+
2192+
recursivelySetTemplateModel(div, model, delegate);
2193+
Platform.performMicrotaskCheckpoint();
2194+
2195+
assert.equal('foo: 2', div.lastChild.getAttribute('class'));
2196+
});
21692197
});
21702198

21712199
suite('Compat', function() {

0 commit comments

Comments
 (0)