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

Commit

Permalink
createInstance should use assigned binding delegate if none is provid…
Browse files Browse the repository at this point in the history
…ed to call

R=arv
BUG=

Review URL: https://codereview.appspot.com/87110043
  • Loading branch information
rafaelw committed Apr 11, 2014
1 parent 4c1e779 commit ab7bb51
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/TemplateBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@
createInstance: function(model, bindingDelegate, delegate_) {
if (bindingDelegate)
delegate_ = this.newDelegate_(bindingDelegate);
else if (!delegate_)
delegate_ = this.delegate_;

if (!this.refContent_)
this.refContent_ = this.ref_.content;
Expand Down
43 changes: 43 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3264,6 +3264,49 @@ suite('Binding Delegate API', function() {
});
});

test('CreateInstance', function(done) {
var delegateFoo = {
prepareBinding: function(path, name, node) {
if (name == 'textContent') {
return function(model) {
return 'foo';
};
}
}
};

var delegateBar = {
prepareBinding: function(path, name, node) {
if (name == 'textContent') {
return function(model) {
return 'bar';
};
}
}
};

var div = createTestHtml(
'<template bind>[[ 2x: bar ]]</template>');
var template = div.firstChild;
template.bindingDelegate = delegateFoo;
template.model = {};

then(function() {
assert.strictEqual(2, div.childNodes.length);
assert.strictEqual('foo', div.lastChild.textContent);

var fragment = template.createInstance({});
assert.strictEqual(1, fragment.childNodes.length);
assert.strictEqual('foo', fragment.lastChild.textContent);

var fragment = template.createInstance({}, delegateBar);
assert.strictEqual(1, fragment.childNodes.length);
assert.strictEqual('bar', fragment.lastChild.textContent);

done();
});
});

test('issue-141', function(done) {
var div = createTestHtml(
'<template bind>' +
Expand Down

0 comments on commit ab7bb51

Please sign in to comment.