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

Commit

Permalink
Fix logic in processSinglePathBinding
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rafaelw committed Dec 17, 2013
1 parent 2c1061c commit 11595a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/TemplateBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,9 @@
function processSinglePathBinding(name, tokens, node, model) {
var delegateFn = tokens[2];
var delegateValue = delegateFn && delegateFn(model, node);
if (Observer.isObservable(delegateValue))
return delegateValue;
var observer = Observer.isObservable(delegateValue) ? delegateValue :
new PathObserver(model, tokens[1]);

var observer = new PathObserver(model, tokens[1]);
return tokens.isSimplePath ? observer :
new ObserverTransform(observer, tokens.combinator);
}
Expand Down
28 changes: 28 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,34 @@ suite('Binding Delegate API', function() {

assert.equal('barValue', div.lastChild.getAttribute('bar'));
});

test('issue-18', function() {

var delegate = {
prepareBinding: function(path, name, node) {
if (name != 'class')
return;

return function(model) {
return new PathObserver(model, path);
}
}
};

var div = createTestHtml(
'<template bind>' +
'<div class="foo: {{ bar }}"></div>' +
'</template>');

var model = {
bar: 2
};

recursivelySetTemplateModel(div, model, delegate);
Platform.performMicrotaskCheckpoint();

assert.equal('foo: 2', div.lastChild.getAttribute('class'));
});
});

suite('Compat', function() {
Expand Down

0 comments on commit 11595a7

Please sign in to comment.