make things marginally more self-explanatory

pull/3478/head
Richard Harris 5 years ago
parent bb5dc8b25f
commit c5e117a640

@ -39,7 +39,7 @@ class IfBlockBranch extends Wrapper {
const is_else = !expression; const is_else = !expression;
if (expression) { if (expression) {
const dependencies = expression.dynamic_dependencies(); this.dependencies = expression.dynamic_dependencies();
// TODO is this the right rule? or should any non-reference count? // TODO is this the right rule? or should any non-reference count?
// const should_cache = !is_reference(expression.node, null) && dependencies.length > 0; // const should_cache = !is_reference(expression.node, null) && dependencies.length > 0;
@ -55,7 +55,6 @@ class IfBlockBranch extends Wrapper {
if (should_cache) { if (should_cache) {
this.condition = block.get_unique_name(`show_if`); this.condition = block.get_unique_name(`show_if`);
this.snippet = expression.render(block); this.snippet = expression.render(block);
this.dependencies = dependencies;
} else { } else {
this.condition = expression.render(block); this.condition = expression.render(block);
} }
@ -244,7 +243,7 @@ export default class IfBlockWrapper extends Wrapper {
function ${select_block_type}(changed, ctx) { function ${select_block_type}(changed, ctx) {
${this.branches.map(({ dependencies, condition, snippet, block }) => condition ${this.branches.map(({ dependencies, condition, snippet, block }) => condition
? deindent` ? deindent`
${dependencies && `if ((${condition} == null) || ${dependencies.map(n => `changed.${n}`).join(' || ')}) ${condition} = !!(${snippet})`} ${snippet && `if ((${condition} == null) || ${dependencies.map(n => `changed.${n}`).join(' || ')}) ${condition} = !!(${snippet})`}
if (${condition}) return ${block.name};` if (${condition}) return ${block.name};`
: `return ${block.name};`)} : `return ${block.name};`)}
} }
@ -327,7 +326,7 @@ export default class IfBlockWrapper extends Wrapper {
function ${select_block_type}(changed, ctx) { function ${select_block_type}(changed, ctx) {
${this.branches.map(({ dependencies, condition, snippet }, i) => condition ${this.branches.map(({ dependencies, condition, snippet }, i) => condition
? deindent` ? deindent`
${dependencies && `if ((${condition} == null) || ${dependencies.map(n => `changed.${n}`).join(' || ')}) ${condition} = !!(${snippet})`} ${snippet && `if ((${condition} == null) || ${dependencies.map(n => `changed.${n}`).join(' || ')}) ${condition} = !!(${snippet})`}
if (${condition}) return ${String(i)};` if (${condition}) return ${String(i)};`
: `return ${i};`)} : `return ${i};`)}
${!has_else && `return -1;`} ${!has_else && `return -1;`}
@ -441,7 +440,7 @@ export default class IfBlockWrapper extends Wrapper {
`if (${name}) ${name}.m(${initial_mount_node}, ${anchor_node});` `if (${name}) ${name}.m(${initial_mount_node}, ${anchor_node});`
); );
if (!branch.dependencies || branch.dependencies.length > 0) { if (branch.dependencies.length > 0) {
const update_mount_node = this.get_update_mount_node(anchor); const update_mount_node = this.get_update_mount_node(anchor);
const enter = dynamic const enter = dynamic

Loading…
Cancel
Save