|
|
@ -266,12 +266,12 @@ export default class IfBlockWrapper extends Wrapper {
|
|
|
|
/* eslint-disable @typescript-eslint/indent,indent */
|
|
|
|
/* eslint-disable @typescript-eslint/indent,indent */
|
|
|
|
if (this.needs_update) {
|
|
|
|
if (this.needs_update) {
|
|
|
|
block.chunks.init.push(b`
|
|
|
|
block.chunks.init.push(b`
|
|
|
|
function ${select_block_type}(#ctx, #changed) {
|
|
|
|
function ${select_block_type}(#ctx, #dirty) {
|
|
|
|
${this.branches.map(({ dependencies, condition, snippet, block }) => condition
|
|
|
|
${this.branches.map(({ dependencies, condition, snippet, block }) => condition
|
|
|
|
? b`
|
|
|
|
? b`
|
|
|
|
${snippet && (
|
|
|
|
${snippet && (
|
|
|
|
dependencies.length > 0
|
|
|
|
dependencies.length > 0
|
|
|
|
? b`if (${condition} == null || ${block.renderer.changed(dependencies)}) ${condition} = !!${snippet}`
|
|
|
|
? b`if (${condition} == null || ${block.renderer.dirty(dependencies)}) ${condition} = !!${snippet}`
|
|
|
|
: b`if (${condition} == null) ${condition} = !!${snippet}`
|
|
|
|
: b`if (${condition} == null) ${condition} = !!${snippet}`
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
if (${condition}) return ${block.name};`
|
|
|
|
if (${condition}) return ${block.name};`
|
|
|
@ -280,7 +280,7 @@ export default class IfBlockWrapper extends Wrapper {
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
block.chunks.init.push(b`
|
|
|
|
block.chunks.init.push(b`
|
|
|
|
function ${select_block_type}(#ctx, #changed) {
|
|
|
|
function ${select_block_type}(#ctx, #dirty) {
|
|
|
|
${this.branches.map(({ condition, snippet, block }) => condition
|
|
|
|
${this.branches.map(({ condition, snippet, block }) => condition
|
|
|
|
? b`if (${snippet || condition}) return ${block.name};`
|
|
|
|
? b`if (${snippet || condition}) return ${block.name};`
|
|
|
|
: b`return ${block.name};`)}
|
|
|
|
: b`return ${block.name};`)}
|
|
|
@ -322,21 +322,21 @@ export default class IfBlockWrapper extends Wrapper {
|
|
|
|
|
|
|
|
|
|
|
|
if (dynamic) {
|
|
|
|
if (dynamic) {
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
if (${current_block_type} === (${current_block_type} = ${select_block_type}(#ctx, #changed)) && ${name}) {
|
|
|
|
if (${current_block_type} === (${current_block_type} = ${select_block_type}(#ctx, #dirty)) && ${name}) {
|
|
|
|
${name}.p(#ctx, #changed);
|
|
|
|
${name}.p(#ctx, #dirty);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${change_block}
|
|
|
|
${change_block}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
if (${current_block_type} !== (${current_block_type} = ${select_block_type}(#ctx, #changed))) {
|
|
|
|
if (${current_block_type} !== (${current_block_type} = ${select_block_type}(#ctx, #dirty))) {
|
|
|
|
${change_block}
|
|
|
|
${change_block}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (dynamic) {
|
|
|
|
} else if (dynamic) {
|
|
|
|
block.chunks.update.push(b`${name}.p(#ctx, #changed);`);
|
|
|
|
block.chunks.update.push(b`${name}.p(#ctx, #dirty);`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (if_exists_condition) {
|
|
|
|
if (if_exists_condition) {
|
|
|
@ -385,12 +385,12 @@ export default class IfBlockWrapper extends Wrapper {
|
|
|
|
|
|
|
|
|
|
|
|
${this.needs_update
|
|
|
|
${this.needs_update
|
|
|
|
? b`
|
|
|
|
? b`
|
|
|
|
function ${select_block_type}(#ctx, #changed) {
|
|
|
|
function ${select_block_type}(#ctx, #dirty) {
|
|
|
|
${this.branches.map(({ dependencies, condition, snippet }, i) => condition
|
|
|
|
${this.branches.map(({ dependencies, condition, snippet }, i) => condition
|
|
|
|
? b`
|
|
|
|
? b`
|
|
|
|
${snippet && (
|
|
|
|
${snippet && (
|
|
|
|
dependencies.length > 0
|
|
|
|
dependencies.length > 0
|
|
|
|
? b`if (${block.renderer.changed(dependencies)}) ${condition} = !!${snippet}`
|
|
|
|
? b`if (${block.renderer.dirty(dependencies)}) ${condition} = !!${snippet}`
|
|
|
|
: b`if (${condition} == -1) ${condition} = !!${snippet}`
|
|
|
|
: b`if (${condition} == -1) ${condition} = !!${snippet}`
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
if (${condition}) return ${i};`
|
|
|
|
if (${condition}) return ${i};`
|
|
|
@ -399,7 +399,7 @@ export default class IfBlockWrapper extends Wrapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
`
|
|
|
|
: b`
|
|
|
|
: b`
|
|
|
|
function ${select_block_type}(#ctx, #changed) {
|
|
|
|
function ${select_block_type}(#ctx, #dirty) {
|
|
|
|
${this.branches.map(({ condition, snippet }, i) => condition
|
|
|
|
${this.branches.map(({ condition, snippet }, i) => condition
|
|
|
|
? b`if (${snippet || condition}) return ${i};`
|
|
|
|
? b`if (${snippet || condition}) return ${i};`
|
|
|
|
: b`return ${i};`)}
|
|
|
|
: b`return ${i};`)}
|
|
|
@ -473,9 +473,9 @@ export default class IfBlockWrapper extends Wrapper {
|
|
|
|
if (dynamic) {
|
|
|
|
if (dynamic) {
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
let ${previous_block_index} = ${current_block_type_index};
|
|
|
|
let ${previous_block_index} = ${current_block_type_index};
|
|
|
|
${current_block_type_index} = ${select_block_type}(#ctx, #changed);
|
|
|
|
${current_block_type_index} = ${select_block_type}(#ctx, #dirty);
|
|
|
|
if (${current_block_type_index} === ${previous_block_index}) {
|
|
|
|
if (${current_block_type_index} === ${previous_block_index}) {
|
|
|
|
${if_current_block_type_index(b`${if_blocks}[${current_block_type_index}].p(#ctx, #changed);`)}
|
|
|
|
${if_current_block_type_index(b`${if_blocks}[${current_block_type_index}].p(#ctx, #dirty);`)}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${change_block}
|
|
|
|
${change_block}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -483,14 +483,14 @@ export default class IfBlockWrapper extends Wrapper {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
let ${previous_block_index} = ${current_block_type_index};
|
|
|
|
let ${previous_block_index} = ${current_block_type_index};
|
|
|
|
${current_block_type_index} = ${select_block_type}(#ctx, #changed);
|
|
|
|
${current_block_type_index} = ${select_block_type}(#ctx, #dirty);
|
|
|
|
if (${current_block_type_index} !== ${previous_block_index}) {
|
|
|
|
if (${current_block_type_index} !== ${previous_block_index}) {
|
|
|
|
${change_block}
|
|
|
|
${change_block}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (dynamic) {
|
|
|
|
} else if (dynamic) {
|
|
|
|
block.chunks.update.push(b`${name}.p(#ctx, #changed);`);
|
|
|
|
block.chunks.update.push(b`${name}.p(#ctx, #dirty);`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
block.chunks.destroy.push(
|
|
|
|
block.chunks.destroy.push(
|
|
|
@ -527,7 +527,7 @@ export default class IfBlockWrapper extends Wrapper {
|
|
|
|
const enter = dynamic
|
|
|
|
const enter = dynamic
|
|
|
|
? b`
|
|
|
|
? b`
|
|
|
|
if (${name}) {
|
|
|
|
if (${name}) {
|
|
|
|
${name}.p(#ctx, #changed);
|
|
|
|
${name}.p(#ctx, #dirty);
|
|
|
|
${has_transitions && b`@transition_in(${name}, 1);`}
|
|
|
|
${has_transitions && b`@transition_in(${name}, 1);`}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${name} = ${branch.block.name}(#ctx);
|
|
|
|
${name} = ${branch.block.name}(#ctx);
|
|
|
@ -548,7 +548,7 @@ export default class IfBlockWrapper extends Wrapper {
|
|
|
|
`;
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
if (branch.snippet) {
|
|
|
|
if (branch.snippet) {
|
|
|
|
block.chunks.update.push(b`if (${block.renderer.changed(branch.dependencies)}) ${branch.condition} = ${branch.snippet}`);
|
|
|
|
block.chunks.update.push(b`if (${block.renderer.dirty(branch.dependencies)}) ${branch.condition} = ${branch.snippet}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// no `p()` here — we don't want to update outroing nodes,
|
|
|
|
// no `p()` here — we don't want to update outroing nodes,
|
|
|
@ -577,7 +577,7 @@ export default class IfBlockWrapper extends Wrapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (dynamic) {
|
|
|
|
} else if (dynamic) {
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
if (${branch.condition}) ${name}.p(#ctx, #changed);
|
|
|
|
if (${branch.condition}) ${name}.p(#ctx, #dirty);
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|