Skip to content

Commit 7d26453

Browse files
committed
add preventDispose property to prevent element unbinding when remove from document. Fixes #312
1 parent 594e7b2 commit 7d26453

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/instance/base.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
this.enteredViewCallback();
6868
},
6969
leftViewCallback: function() {
70-
this.asyncUnbindAll();
70+
if (!this.preventDispose) {
71+
this.asyncUnbindAll();
72+
}
7173
// invoke user action
7274
if (this.leftView) {
7375
this.leftView();

src/instance/mdv.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@
5252
this.unbindAllProperties();
5353
this.super();
5454
// unbind shadowRoot
55-
unbindNodeTree(this.shadowRoot);
56-
// TODO(sjmiles): must also unbind inherited shadow roots
55+
var root = this.shadowRoot;
56+
while (root) {
57+
unbindNodeTree(root);
58+
root = root.olderShadowRoot;
59+
}
5760
this._unbound = true;
5861
}
5962
},

test/html/unbind.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,17 @@
7272
function(node) {
7373
chai.assert.isTrue(node.fooWasChanged, 'node is actually bound');
7474
var n = document.createElement('x-test');
75-
n.cancelUnbindAll();
75+
document.body.appendChild(n);
7676
return [n];
7777
},
78+
function(node) {
79+
node.preventDispose = true;
80+
node.parentNode.removeChild(node);
81+
return [node];
82+
},
7883
function(node) {
7984
chai.assert.ok(!node._unbound,
80-
'element is bound when cancelUnbindAll is called');
85+
'element is bound when preventDispose is true');
8186
node.unbindAll();
8287
chai.assert.isTrue(node._unbound,
8388
'element is unbound when unbindAll is called');

0 commit comments

Comments
 (0)