|
|
|
|
@ -5,7 +5,6 @@ import { b, x } from 'code-red';
|
|
|
|
|
|
|
|
|
|
/** @extends Wrapper */
|
|
|
|
|
export default class KeyBlockWrapper extends Wrapper {
|
|
|
|
|
|
|
|
|
|
/** @type {import('../../nodes/KeyBlock.js').default} */
|
|
|
|
|
node;
|
|
|
|
|
|
|
|
|
|
@ -42,7 +41,14 @@ export default class KeyBlockWrapper extends Wrapper {
|
|
|
|
|
renderer.blocks.push(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) {
|
|
|
|
|
if (this.dependencies.length === 0) {
|
|
|
|
|
this.render_static_key(block, parent_node, parent_nodes);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
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 dynamic = this.block.has_update_method;
|
|
|
|
|
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
|
|
|
|
|
? x`@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`
|
|
|
|
|
let ${this.var} = ${this.block.name}(#ctx);
|
|
|
|
|
`);
|
|
|
|
|
@ -91,16 +102,20 @@ export default class KeyBlockWrapper extends Wrapper {
|
|
|
|
|
if (this.renderer.options.hydratable) {
|
|
|
|
|
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 body = b`
|
|
|
|
|
${has_transitions
|
|
|
|
|
${
|
|
|
|
|
has_transitions
|
|
|
|
|
? b`
|
|
|
|
|
@group_outros();
|
|
|
|
|
@transition_out(${this.var}, 1, 1, @noop);
|
|
|
|
|
@check_outros();
|
|
|
|
|
`
|
|
|
|
|
: b `${this.var}.d(1);`}
|
|
|
|
|
: b`${this.var}.d(1);`
|
|
|
|
|
}
|
|
|
|
|
${this.var} = ${this.block.name}(#ctx);
|
|
|
|
|
${this.var}.c();
|
|
|
|
|
${has_transitions && b`@transition_in(${this.var}, 1)`}
|
|
|
|
|
@ -114,8 +129,7 @@ export default class KeyBlockWrapper extends Wrapper {
|
|
|
|
|
${this.var}.p(#ctx, #dirty);
|
|
|
|
|
}
|
|
|
|
|
`);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
|
if (${condition}) {
|
|
|
|
|
${body}
|
|
|
|
|
@ -129,7 +143,3 @@ export default class KeyBlockWrapper extends Wrapper {
|
|
|
|
|
block.chunks.destroy.push(b`${this.var}.d(detaching)`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|