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

Commit

Permalink
Add Template.clear
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelw committed Aug 6, 2013
1 parent dc7a0e9 commit 60d98f1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/template_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,12 @@

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

clear: function() {
this.unbind('bind');
this.unbind('if');
this.unbind('repeat');
}
});

Expand Down
21 changes: 21 additions & 0 deletions tests/template_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ suite('Template Element', function() {
Platform.performMicrotaskCheckpoint();
assert.strictEqual(2, div.childNodes.length);
assert.strictEqual('text', div.lastChild.textContent);

div.firstChild.clear();
Platform.performMicrotaskCheckpoint();
assert.strictEqual(1, div.childNodes.length);
});

test('Template bind, no parent', function() {
Expand Down Expand Up @@ -132,6 +136,10 @@ suite('Template Element', function() {
Platform.performMicrotaskCheckpoint();
assert.strictEqual(2, div.childNodes.length);
assert.strictEqual('text', div.lastChild.textContent);

div.firstChild.clear();
Platform.performMicrotaskCheckpoint();
assert.strictEqual(1, div.childNodes.length);
});

test('Template Bind If, 2', function() {
Expand Down Expand Up @@ -160,6 +168,10 @@ suite('Template Element', function() {
Platform.performMicrotaskCheckpoint();
assert.strictEqual(2, div.childNodes.length);
assert.strictEqual('foo', div.lastChild.textContent);

div.firstChild.clear();
Platform.performMicrotaskCheckpoint();
assert.strictEqual(1, div.childNodes.length);
});

test('Template-Empty If', function() {
Expand Down Expand Up @@ -190,6 +202,10 @@ suite('Template Element', function() {
assert.strictEqual('1', div.childNodes[1].textContent);
assert.strictEqual('2', div.childNodes[2].textContent);
assert.strictEqual('3', div.childNodes[3].textContent);

div.firstChild.clear();
Platform.performMicrotaskCheckpoint();
assert.strictEqual(1, div.childNodes.length);
});

test('TextTemplateWithNullStringBinding', function() {
Expand Down Expand Up @@ -342,6 +358,11 @@ suite('Template Element', function() {
model.splice(1, 1);
Platform.performMicrotaskCheckpoint();
assert.strictEqual(3, div.childNodes.length);


div.firstChild.clear();
Platform.performMicrotaskCheckpoint();
assert.strictEqual(1, div.childNodes.length);
});

test('Repeat - Reuse Instances', function() {
Expand Down

0 comments on commit 60d98f1

Please sign in to comment.