Skip to content

Commit

Permalink
try to make sure added() is only called once() per node lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
ceymard committed Mar 8, 2019
1 parent 89b3de7 commit d3bdb0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/elt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,16 @@ export function e(elt: any, _attrs: Attrs | null, ...children: o.RO<Renderable>[
var ns = NS[elt] || attrs.xmlns
node = ns ? document.createElementNS(ns, elt) : document.createElement(elt)

// Append children to the node.
// Save the children into an array so that we can add them
// If we iterate them, we risk adding nodes created by
// const arr = Array.from(fragment.childNodes)
var _child = fragment.firstChild as Node | null
while (_child) {
add(_child)
_child = _child.nextSibling
}

// Append children to the node.
node.appendChild(fragment)

} else if (isComponent(elt)) {
Expand Down
14 changes: 9 additions & 5 deletions src/verbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ export class Displayer extends Mixin<Comment> {

const new_node = getSingleNode(value)
this.current_node = new_node
parent.insertBefore(new_node, this.node)
add(new_node)
if (this.mounted)
parent.insertBefore(new_node, this.node.nextSibling)
if (this.mounted) {
add(new_node)
mount(new_node, parent)
}
}

added() {
Expand Down Expand Up @@ -281,12 +282,15 @@ export class Repeater<T> extends Mixin<Comment> {
fr.appendChild(next)
}

add(fr)
parent.insertBefore(fr, this.end)
if (this.mounted) {
add(fr)
parent.insertBefore(fr, this.end)
for (var n of to_mount) {
mount(n, parent)
}
} else {
// We're being added already, probably by e() or a variant, so no need to manually add()
parent.insertBefore(fr, this.end)
}

}
Expand Down

0 comments on commit d3bdb0f

Please sign in to comment.