refactor render_dom

pull/6898/head
Yuichiro Yamashita 5 years ago
parent d223df6c23
commit cdd7180306

@ -235,14 +235,6 @@ export default class ElementWrapper extends Wrapper {
}
render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
this.render_element(block, parent_node, parent_nodes);
if (this.node.is_dynamic_element()) {
this.render_dynamic_element(block, parent_node, parent_nodes);
}
}
render_element(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
const { renderer } = this;
if (this.node.name === 'noscript') return;
@ -377,12 +369,11 @@ export default class ElementWrapper extends Wrapper {
}
if (this.node.is_dynamic_element()) {
const dependencies = this.node.tag_expr.dynamic_dependencies();
if (dependencies.length) {
const condition = block.renderer.dirty(
dependencies
this.node.tag_expr.dynamic_dependencies()
);
const render_statement = this.get_render_statement(block);
const mounted: Identifier = { type: 'Identifier', name: '#mounted' };
block.chunks.update.push(b`
if (${condition}) {
@ -394,24 +385,15 @@ export default class ElementWrapper extends Wrapper {
${staticChildren}
}
`);
}
}
}
render_dynamic_element(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
const previous_tag = block.get_unique_name('previous_tag');
const snippet = this.node.tag_expr.manipulate(block);
block.add_variable(previous_tag, snippet);
const has_transitions = !!(
block.has_intro_method || block.has_outro_method
);
const has_transitions = !!(block.has_intro_method || block.has_outro_method);
const anchor = this.get_or_create_anchor(block, parent_node, parent_nodes);
const not_equal = this.renderer.component.component_options.immutable ? x`@not_equal` : x`@safe_not_equal`;
const condition = x`${not_equal}(${previous_tag}, ${previous_tag} = ${snippet})`;
const render_statement = this.get_render_statement(block);
const if_statement = x`${not_equal}(${previous_tag}, ${previous_tag} = ${snippet})`;
if (has_transitions) {
const body = b`
@ -424,18 +406,19 @@ export default class ElementWrapper extends Wrapper {
`;
block.chunks.update.push(b`
if (${condition}) {
if (${if_statement}) {
${body}
}
`);
} else {
block.chunks.update.push(b`
if (${condition}) {
if (${if_statement}) {
this.m(${this.get_update_mount_node(anchor)}, ${anchor});
}
`);
}
}
}
can_use_textcontent() {
return this.is_static_content && this.fragment.nodes.every(node => node.node.type === 'Text' || node.node.type === 'MustacheTag');

Loading…
Cancel
Save