unify append/appendAll

pull/1799/head
Rich Harris 8 years ago
parent 1a92b76a4a
commit 54af7fc620

@ -11,17 +11,9 @@ export default function mountChildren(node: Node, parentNode?: string) {
if (consecutiveNodes.length === 0) return;
if (parentNode) {
if (consecutiveNodes.length === 1) {
builder.addLine(`@append(${parentNode}, ${consecutiveNodes[0]});`);
} else {
builder.addLine(`@appendAll(${parentNode}, [${consecutiveNodes.join(', ')}]);`);
}
builder.addLine(`@append(${parentNode}, ${consecutiveNodes.join(', ')});`);
} else {
if (consecutiveNodes.length === 1) {
builder.addLine(`@insert(#target, anchor, ${consecutiveNodes[0]});`);
} else {
builder.addLine(`@insertAll(#target, anchor, [${consecutiveNodes.join(', ')}]);`);
}
builder.addLine(`@insert(#target, anchor, ${consecutiveNodes.join(', ')});`);
}
consecutiveNodes = [];

@ -1,32 +1,15 @@
export function append(parent, child) {
parent.appendChild(child);
}
export function appendAll(parent, children) {
for (var i = 0; i < children.length; i += 1) {
parent.appendChild(children[i]);
export function append(parent) {
for (var i = 1; i < arguments.length; i += 1) {
parent.appendChild(arguments[i]);
}
}
// TODO remove
export function appendNode(node, target) {
target.appendChild(node);
}
export function insert(parent, next, child) {
parent.insertBefore(child, next);
}
export function insertAll(parent, next, children) {
for (var i = 0; i < children.length; i += 1) {
parent.insertBefore(children[i], next);
export function insert(parent, next) {
for (var i = 2; i < arguments.length; i += 1) {
parent.insertBefore(arguments[i], next);
}
}
export function insertNode(node, target, anchor) {
target.insertBefore(node, anchor);
}
export function detachNode(node) {
node.parentNode.removeChild(node);
}

Loading…
Cancel
Save