Commit eac2c84077f06deea7722e1dc72af19e3a85c7ed
html-element: fix some binding/unbinding issues
- don’t bind to elements that never get added to dom - walk correctly to removeMatt McKegg committed on 9/7/2016, 1:27:17 PM
Parent: 1748dbe94cf36d3a938f65a43ff0cf56abca627a
Files changed
html-element.js | changed |
lib/walk.js | changed |
html-element.js | ||
---|---|---|
@@ -57,21 +57,25 @@ | ||
57 | 57 | appendChild(document, target, data, child) |
58 | 58 | }) |
59 | 59 | } else if (isObservable(node)) { |
60 | 60 | var nodes = getNodes(document, resolve(node)) |
61 | - nodes.forEach(append, target) | |
61 | + nodes.forEach(append, { target: target, document: document }) | |
62 | 62 | data.targets.set(node, nodes) |
63 | 63 | data.bindings.push(new Binding(document, node, data)) |
64 | 64 | } else { |
65 | 65 | node = getNode(document, node) |
66 | 66 | target.appendChild(node) |
67 | - walk(node, rebind) | |
67 | + if (target.rootNode === document) { | |
68 | + walk(node, rebind) | |
69 | + } | |
68 | 70 | } |
69 | 71 | } |
70 | 72 | |
71 | 73 | function append (child) { |
72 | - this.appendChild(child) | |
73 | - walk(child, rebind) | |
74 | + this.target.appendChild(child) | |
75 | + if (this.target.rootNode === this.document) { | |
76 | + walk(child, rebind) | |
77 | + } | |
74 | 78 | } |
75 | 79 | |
76 | 80 | function checkWatcher (document) { |
77 | 81 | if (!watcher && global.MutationObserver) { |
lib/walk.js | ||
---|---|---|
@@ -6,11 +6,11 @@ | ||
6 | 6 | } |
7 | 7 | } |
8 | 8 | |
9 | 9 | function nextNode (current, root) { |
10 | - var result = current.firstChild || current.nextSibling | |
11 | - if (!result && current.parentNode && current.parentNode !== root) { | |
12 | - return current.nextSibling | |
13 | - } else { | |
14 | - return result | |
10 | + var result = current.firstChild | |
11 | + while (current && !result && current !== root) { | |
12 | + result = current.nextSibling | |
13 | + current = current.parentNode | |
15 | 14 | } |
15 | + return result | |
16 | 16 | } |
Built with git-ssb-web