implement remount on individual nodes

pull/1193/head
Rich Harris 8 years ago
parent 7638964fc0
commit f8d6d99930

@ -320,7 +320,7 @@ export default class Component extends Node {
${name} = new ${switch_vars.value}(${switch_vars.props}(state)); ${name} = new ${switch_vars.value}(${switch_vars.props}(state));
${name}._fragment.c(); ${name}._fragment.c();
${this.children.map(child => remount(generator, child, name))} ${this.children.map(child => child.remount(name))}
${name}._mount(${updateMountNode}, ${anchor}); ${name}._mount(${updateMountNode}, ${anchor});
${eventHandlers.map(handler => deindent` ${eventHandlers.map(handler => deindent`
@ -398,6 +398,10 @@ export default class Component extends Node {
`); `);
} }
} }
remount(name: string) {
return `${this.var}._mount(${name}._slotted${this.generator.legacy ? `["default"]` : `.default`}, null);`;
}
} }
function mungeAttribute(attribute: Node, block: Block): Attribute { function mungeAttribute(attribute: Node, block: Block): Attribute {
@ -547,32 +551,4 @@ function isComputed(node: Node) {
} }
return false; return false;
}
function remount(generator: DomGenerator, node: Node, name: string) {
// TODO make this a method of the nodes
if (node.type === 'Component') {
return `${node.var}._mount(${name}._slotted${generator.legacy ? `["default"]` : `.default`}, null);`;
}
if (node.type === 'Element') {
const slot = node.attributes.find(attribute => attribute.name === 'slot');
if (slot) {
return `@appendNode(${node.var}, ${name}._slotted.${node.getStaticAttributeValue('slot')});`;
}
return `@appendNode(${node.var}, ${name}._slotted${generator.legacy ? `["default"]` : `.default`});`;
}
if (node.type === 'Text' || node.type === 'MustacheTag' || node.type === 'RawMustacheTag') {
return `@appendNode(${node.var}, ${name}._slotted${generator.legacy ? `["default"]` : `.default`});`;
}
if (node.type === 'EachBlock') {
// TODO consider keyed blocks
return `for (var #i = 0; #i < ${node.iterations}.length; #i += 1) ${node.iterations}[#i].m(${name}._slotted${generator.legacy ? `["default"]` : `.default`}, null);`;
}
return `${node.var}.m(${name}._slotted${generator.legacy ? `["default"]` : `.default`}, null);`;
} }

@ -594,4 +594,9 @@ export default class EachBlock extends Node {
block.builders.destroy.addBlock(`@destroyEach(${iterations});`); block.builders.destroy.addBlock(`@destroyEach(${iterations});`);
} }
remount(name: string) {
// TODO consider keyed blocks
return `for (var #i = 0; #i < ${this.iterations}.length; #i += 1) ${this.iterations}[#i].m(${name}._slotted${this.generator.legacy ? `["default"]` : `.default`}, null);`;
}
} }

@ -671,6 +671,15 @@ export default class Element extends Node {
isMediaNode() { isMediaNode() {
return this.name === 'audio' || this.name === 'video'; return this.name === 'audio' || this.name === 'video';
} }
remount(name: string) {
const slot = this.attributes.find(attribute => attribute.name === 'slot');
if (slot) {
return `@appendNode(${this.var}, ${name}._slotted.${this.getStaticAttributeValue('slot')});`;
}
return `@appendNode(${this.var}, ${name}._slotted${this.generator.legacy ? `["default"]` : `.default`});`;
}
} }
function getRenderStatement( function getRenderStatement(

@ -26,4 +26,8 @@ export default class MustacheTag extends Tag {
parentNode parentNode
); );
} }
remount(name: string) {
return `@appendNode(${this.var}, ${name}._slotted${this.generator.legacy ? `["default"]` : `.default`});`;
}
} }

@ -89,4 +89,8 @@ export default class RawMustacheTag extends Tag {
addAnchorAfter(); addAnchorAfter();
} }
} }
remount(name: string) {
return `@appendNode(${this.var}, ${name}._slotted${this.generator.legacy ? `["default"]` : `.default`});`;
}
} }

@ -58,4 +58,8 @@ export default class Text extends Node {
parentNode parentNode
); );
} }
remount(name: string) {
return `@appendNode(${this.var}, ${name}._slotted${this.generator.legacy ? `["default"]` : `.default`});`;
}
} }

@ -161,4 +161,8 @@ export default class Node {
getUpdateMountNode(anchor: string) { getUpdateMountNode(anchor: string) {
return this.parent.isDomNode() ? this.parent.var : `${anchor}.parentNode`; return this.parent.isDomNode() ? this.parent.var : `${anchor}.parentNode`;
} }
remount(name: string) {
return `${this.var}.m(${name}._slotted${this.generator.legacy ? `["default"]` : `.default`}, null);`;
}
} }
Loading…
Cancel
Save