Skip to content

Commit

Permalink
add preventDispose property to prevent element unbinding when remove …
Browse files Browse the repository at this point in the history
…from document. Fixes #312
  • Loading branch information
sorvell committed Oct 10, 2013
1 parent 594e7b2 commit 7d26453
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/instance/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
this.enteredViewCallback();
},
leftViewCallback: function() {
this.asyncUnbindAll();
if (!this.preventDispose) {

This comment has been minimized.

Copy link
@ebidel

ebidel Oct 19, 2013

Contributor

Needs a doc comment. Might also think about a better name, something like .keepBindings?

this.asyncUnbindAll();
}
// invoke user action
if (this.leftView) {
this.leftView();
Expand Down
7 changes: 5 additions & 2 deletions src/instance/mdv.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@
this.unbindAllProperties();
this.super();
// unbind shadowRoot
unbindNodeTree(this.shadowRoot);
// TODO(sjmiles): must also unbind inherited shadow roots
var root = this.shadowRoot;
while (root) {
unbindNodeTree(root);
root = root.olderShadowRoot;
}
this._unbound = true;
}
},
Expand Down
9 changes: 7 additions & 2 deletions test/html/unbind.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@
function(node) {
chai.assert.isTrue(node.fooWasChanged, 'node is actually bound');
var n = document.createElement('x-test');
n.cancelUnbindAll();
document.body.appendChild(n);
return [n];
},
function(node) {
node.preventDispose = true;
node.parentNode.removeChild(node);
return [node];
},
function(node) {
chai.assert.ok(!node._unbound,
'element is bound when cancelUnbindAll is called');
'element is bound when preventDispose is true');
node.unbindAll();
chai.assert.isTrue(node._unbound,
'element is unbound when unbindAll is called');
Expand Down

0 comments on commit 7d26453

Please sign in to comment.