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

Commit

Permalink
template.ref must recursive to find the original source template
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelw committed May 31, 2013
1 parent 2767ae3 commit 8604073
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/template_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,6 @@
}
}

function effectiveContent(template) {
var ref = template.ref;
return ref ? ref.content : template.content;
}

var templateModelTable = new SideTable('templateModel');

mixin(HTMLTemplateElement.prototype, {
Expand Down Expand Up @@ -920,8 +915,8 @@
},

createInstance: function(model, syntax) {
var content = effectiveContent(this);
var instance = createDeepCloneAndDecorateTemplates(content, syntax);
var instance = createDeepCloneAndDecorateTemplates(this.ref.content,
syntax);
// TODO(rafaelw): This is a hack, and is neccesary for the polyfil
// because custom elements are not upgraded during cloneNode()
if (typeof HTMLTemplateElement.__instanceCreated == 'function')
Expand Down Expand Up @@ -954,7 +949,11 @@
if (!ref)
ref = templateInstanceRefTable.get(this);

return ref || null;
if (!ref)
return this;

var nextRef = ref.ref;
return nextRef ? nextRef : ref;
}
});

Expand Down
17 changes: 17 additions & 0 deletions tests/template_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,23 @@ suite('Template Element', function() {
assert.strictEqual('Name: Leela', div.childNodes[3].textContent);
});

test('RecursiveRef', function() {
var div = createTestHtml(
'<template bind>' +
'<template id=src>{{ foo }}</template>' +
'<template bind ref=src></template>' +
'</template>');

var m = {
foo: 'bar'
};
recursivelySetTemplateModel(div, m);
Platform.performMicrotaskCheckpoint();

assert.strictEqual(4, div.childNodes.length);
assert.strictEqual('bar', div.childNodes[3].textContent);
});

test('ChangeFromBindToRepeat', function() {
var div = createTestHtml(
'<template bind="{{a}}">' +
Expand Down

0 comments on commit 8604073

Please sign in to comment.