Lint and format src/compiler/compile/render_dom/wrappers/KeyBlock.js

pull/8569/head
Simon Holthausen 3 years ago
parent 4adbb5439b
commit 28564df0b2

@ -5,7 +5,6 @@ import { b, x } from 'code-red';
/** @extends Wrapper */ /** @extends Wrapper */
export default class KeyBlockWrapper extends Wrapper { export default class KeyBlockWrapper extends Wrapper {
/** @type {import('../../nodes/KeyBlock.js').default} */ /** @type {import('../../nodes/KeyBlock.js').default} */
node; node;
@ -42,7 +41,14 @@ export default class KeyBlockWrapper extends Wrapper {
renderer.blocks.push(block); renderer.blocks.push(block);
} }
this.block = block; this.block = block;
this.fragment = new FragmentWrapper(renderer, this.block, node.children, this, strip_whitespace, next_sibling); this.fragment = new FragmentWrapper(
renderer,
this.block,
node.children,
this,
strip_whitespace,
next_sibling
);
} }
/** /**
@ -53,8 +59,7 @@ export default class KeyBlockWrapper extends Wrapper {
render(block, parent_node, parent_nodes) { render(block, parent_node, parent_nodes) {
if (this.dependencies.length === 0) { if (this.dependencies.length === 0) {
this.render_static_key(block, parent_node, parent_nodes); this.render_static_key(block, parent_node, parent_nodes);
} } else {
else {
this.render_dynamic_key(block, parent_node, parent_nodes); this.render_dynamic_key(block, parent_node, parent_nodes);
} }
} }
@ -74,7 +79,11 @@ export default class KeyBlockWrapper extends Wrapper {
* @param {import('estree').Identifier} parent_nodes * @param {import('estree').Identifier} parent_nodes
*/ */
render_dynamic_key(block, parent_node, parent_nodes) { render_dynamic_key(block, parent_node, parent_nodes) {
this.fragment.render(this.block, null, /** @type {unknown} */ /** @type {import('estree').Identifier} */ ((x `#nodes`))); this.fragment.render(
this.block,
null,
/** @type {unknown} */ /** @type {import('estree').Identifier} */ (x`#nodes`)
);
const has_transitions = !!(this.block.has_intro_method || this.block.has_outro_method); const has_transitions = !!(this.block.has_intro_method || this.block.has_outro_method);
const dynamic = this.block.has_update_method; const dynamic = this.block.has_update_method;
const previous_key = block.get_unique_name('previous_key'); const previous_key = block.get_unique_name('previous_key');
@ -83,7 +92,9 @@ export default class KeyBlockWrapper extends Wrapper {
const not_equal = this.renderer.component.component_options.immutable const not_equal = this.renderer.component.component_options.immutable
? x`@not_equal` ? x`@not_equal`
: x`@safe_not_equal`; : x`@safe_not_equal`;
const condition = x `${this.renderer.dirty(this.dependencies)} && ${not_equal}(${previous_key}, ${previous_key} = ${snippet})`; const condition = x`${this.renderer.dirty(
this.dependencies
)} && ${not_equal}(${previous_key}, ${previous_key} = ${snippet})`;
block.chunks.init.push(b` block.chunks.init.push(b`
let ${this.var} = ${this.block.name}(#ctx); let ${this.var} = ${this.block.name}(#ctx);
`); `);
@ -91,16 +102,20 @@ export default class KeyBlockWrapper extends Wrapper {
if (this.renderer.options.hydratable) { if (this.renderer.options.hydratable) {
block.chunks.claim.push(b`${this.var}.l(${parent_nodes});`); block.chunks.claim.push(b`${this.var}.l(${parent_nodes});`);
} }
block.chunks.mount.push(b `${this.var}.m(${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'});`); block.chunks.mount.push(
b`${this.var}.m(${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'});`
);
const anchor = this.get_or_create_anchor(block, parent_node, parent_nodes); const anchor = this.get_or_create_anchor(block, parent_node, parent_nodes);
const body = b` const body = b`
${has_transitions ${
has_transitions
? b` ? b`
@group_outros(); @group_outros();
@transition_out(${this.var}, 1, 1, @noop); @transition_out(${this.var}, 1, 1, @noop);
@check_outros(); @check_outros();
` `
: b `${this.var}.d(1);`} : b`${this.var}.d(1);`
}
${this.var} = ${this.block.name}(#ctx); ${this.var} = ${this.block.name}(#ctx);
${this.var}.c(); ${this.var}.c();
${has_transitions && b`@transition_in(${this.var}, 1)`} ${has_transitions && b`@transition_in(${this.var}, 1)`}
@ -114,8 +129,7 @@ export default class KeyBlockWrapper extends Wrapper {
${this.var}.p(#ctx, #dirty); ${this.var}.p(#ctx, #dirty);
} }
`); `);
} } else {
else {
block.chunks.update.push(b` block.chunks.update.push(b`
if (${condition}) { if (${condition}) {
${body} ${body}
@ -129,7 +143,3 @@ export default class KeyBlockWrapper extends Wrapper {
block.chunks.destroy.push(b`${this.var}.d(detaching)`); block.chunks.destroy.push(b`${this.var}.d(detaching)`);
} }
} }

Loading…
Cancel
Save