Skip to content

Commit

Permalink
delegate must be correctly scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelw committed Sep 25, 2013
1 parent 90379d6 commit dbbd7e7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/TemplateBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,13 +1006,14 @@
return;

var template = this.templateElement_;
var delegate = template.bindingDelegate;

if (!template.parentNode || !template.ownerDocument.defaultView) {
this.close();
return;
}

if (this.instanceModelFn_ === undefined) {
var delegate = template.bindingDelegate;
if (delegate && typeof delegate.prepareInstanceModel === 'function')
this.instanceModelFn_ = delegate.prepareInstanceModel(template);
if (typeof this.instanceModelFn_ !== 'function')
Expand Down
37 changes: 36 additions & 1 deletion tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1846,8 +1846,43 @@ suite('Template Instantiation', function() {
assert.strictEqual(1, template3.content.childNodes.length);
assert.strictEqual('Hello', template3.content.firstChild.textContent);
});
});

test('issue-285', function() {
var div = createTestHtml(
'<template>' +
'<template bind if="{{show}}">' +
'<template id=del repeat="{{items}}">' +
'{{}}' +
'</template>' +
'</template>' +
'</template>');

var template = div.firstChild;

var model = {
show: true,
items: [1]
};

div.appendChild(template.createInstance(model, {
prepareInstanceModel: function(template) {
if (template.id == 'del') {
return function(val) {
return val*2;
};
}
}
}));

Platform.performMicrotaskCheckpoint();
assert.equal('2', template.nextSibling.nextSibling.nextSibling.textContent);
model.show = false;
Platform.performMicrotaskCheckpoint();
model.show = true;
Platform.performMicrotaskCheckpoint();
assert.equal('2', template.nextSibling.nextSibling.nextSibling.textContent);
});
});

suite('Binding Delegate API', function() {

Expand Down

0 comments on commit dbbd7e7

Please sign in to comment.