git ssb

1+

Matt McKegg / mutant



Commit eac2c84077f06deea7722e1dc72af19e3a85c7ed

html-element: fix some binding/unbinding issues

- don’t bind to elements that never get added to dom
- walk correctly to remove
Matt McKegg committed on 9/7/2016, 1:27:17 PM
Parent: 1748dbe94cf36d3a938f65a43ff0cf56abca627a

Files changed

html-element.jschanged
lib/walk.jschanged
html-element.jsView
@@ -57,21 +57,25 @@
5757 appendChild(document, target, data, child)
5858 })
5959 } else if (isObservable(node)) {
6060 var nodes = getNodes(document, resolve(node))
61- nodes.forEach(append, target)
61+ nodes.forEach(append, { target: target, document: document })
6262 data.targets.set(node, nodes)
6363 data.bindings.push(new Binding(document, node, data))
6464 } else {
6565 node = getNode(document, node)
6666 target.appendChild(node)
67- walk(node, rebind)
67+ if (target.rootNode === document) {
68+ walk(node, rebind)
69+ }
6870 }
6971 }
7072
7173 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+ }
7478 }
7579
7680 function checkWatcher (document) {
7781 if (!watcher && global.MutationObserver) {
lib/walk.jsView
@@ -6,11 +6,11 @@
66 }
77 }
88
99 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
1514 }
15+ return result
1616 }

Built with git-ssb-web