|
|
@ -41,10 +41,6 @@ class ElseBlockWrapper extends Wrapper {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
this.isDynamic = this.block.dependencies.size > 0;
|
|
|
|
this.isDynamic = this.block.dependencies.size > 0;
|
|
|
|
if (this.isDynamic) {
|
|
|
|
|
|
|
|
// TODO this can't be right
|
|
|
|
|
|
|
|
this.block.hasUpdateMethod = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -149,7 +145,6 @@ export default class EachBlockWrapper extends Wrapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
block.addDependencies(this.block.dependencies);
|
|
|
|
block.addDependencies(this.block.dependencies);
|
|
|
|
this.block.hasUpdateMethod = this.block.dependencies.size > 0; // TODO should this logic be in Block?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.block.hasOutros || (this.else && this.else.block.hasOutros)) {
|
|
|
|
if (this.block.hasOutros || (this.else && this.else.block.hasOutros)) {
|
|
|
|
block.addOutro();
|
|
|
|
block.addOutro();
|
|
|
@ -216,7 +211,7 @@ export default class EachBlockWrapper extends Wrapper {
|
|
|
|
// TODO neaten this up... will end up with an empty line in the block
|
|
|
|
// TODO neaten this up... will end up with an empty line in the block
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
if (!${this.vars.each_block_value}.${this.vars.length}) {
|
|
|
|
if (!${this.vars.each_block_value}.${this.vars.length}) {
|
|
|
|
${each_block_else} = ${this.else.block.name}($$, ctx);
|
|
|
|
${each_block_else} = ${this.else.block.name}(ctx);
|
|
|
|
${each_block_else}.c();
|
|
|
|
${each_block_else}.c();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
@ -234,7 +229,7 @@ export default class EachBlockWrapper extends Wrapper {
|
|
|
|
if (!${this.vars.each_block_value}.${this.vars.length} && ${each_block_else}) {
|
|
|
|
if (!${this.vars.each_block_value}.${this.vars.length} && ${each_block_else}) {
|
|
|
|
${each_block_else}.p(changed, ctx);
|
|
|
|
${each_block_else}.p(changed, ctx);
|
|
|
|
} else if (!${this.vars.each_block_value}.${this.vars.length}) {
|
|
|
|
} else if (!${this.vars.each_block_value}.${this.vars.length}) {
|
|
|
|
${each_block_else} = ${this.else.block.name}($$, ctx);
|
|
|
|
${each_block_else} = ${this.else.block.name}(ctx);
|
|
|
|
${each_block_else}.c();
|
|
|
|
${each_block_else}.c();
|
|
|
|
${each_block_else}.m(${initialMountNode}, ${this.vars.anchor});
|
|
|
|
${each_block_else}.m(${initialMountNode}, ${this.vars.anchor});
|
|
|
|
} else if (${each_block_else}) {
|
|
|
|
} else if (${each_block_else}) {
|
|
|
@ -250,7 +245,7 @@ export default class EachBlockWrapper extends Wrapper {
|
|
|
|
${each_block_else} = null;
|
|
|
|
${each_block_else} = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!${each_block_else}) {
|
|
|
|
} else if (!${each_block_else}) {
|
|
|
|
${each_block_else} = ${this.else.block.name}($$, ctx);
|
|
|
|
${each_block_else} = ${this.else.block.name}(ctx);
|
|
|
|
${each_block_else}.c();
|
|
|
|
${each_block_else}.c();
|
|
|
|
${each_block_else}.m(${initialMountNode}, ${this.vars.anchor});
|
|
|
|
${each_block_else}.m(${initialMountNode}, ${this.vars.anchor});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -306,7 +301,7 @@ export default class EachBlockWrapper extends Wrapper {
|
|
|
|
for (var #i = 0; #i < ${this.vars.each_block_value}.${length}; #i += 1) {
|
|
|
|
for (var #i = 0; #i < ${this.vars.each_block_value}.${length}; #i += 1) {
|
|
|
|
let child_ctx = ${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i);
|
|
|
|
let child_ctx = ${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i);
|
|
|
|
let key = ${get_key}(child_ctx);
|
|
|
|
let key = ${get_key}(child_ctx);
|
|
|
|
${iterations}[#i] = ${lookup}[key] = ${create_each_block}($$, key, child_ctx);
|
|
|
|
${iterations}[#i] = ${lookup}[key] = ${create_each_block}(key, child_ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
@ -342,7 +337,7 @@ export default class EachBlockWrapper extends Wrapper {
|
|
|
|
|
|
|
|
|
|
|
|
${this.block.hasOutros && `@group_outros();`}
|
|
|
|
${this.block.hasOutros && `@group_outros();`}
|
|
|
|
${this.node.hasAnimation && `for (let #i = 0; #i < ${iterations}.length; #i += 1) ${iterations}[#i].r();`}
|
|
|
|
${this.node.hasAnimation && `for (let #i = 0; #i < ${iterations}.length; #i += 1) ${iterations}[#i].r();`}
|
|
|
|
${iterations} = @updateKeyedEach(${iterations}, $$, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.vars.each_block_value}, ${lookup}, ${updateMountNode}, ${destroy}, ${create_each_block}, ${anchor}, ${this.vars.get_each_context});
|
|
|
|
${iterations} = @updateKeyedEach(${iterations}, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.vars.each_block_value}, ${lookup}, ${updateMountNode}, ${destroy}, ${create_each_block}, ${anchor}, ${this.vars.get_each_context});
|
|
|
|
${this.node.hasAnimation && `for (let #i = 0; #i < ${iterations}.length; #i += 1) ${iterations}[#i].a();`}
|
|
|
|
${this.node.hasAnimation && `for (let #i = 0; #i < ${iterations}.length; #i += 1) ${iterations}[#i].a();`}
|
|
|
|
${this.block.hasOutros && `@check_outros();`}
|
|
|
|
${this.block.hasOutros && `@check_outros();`}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
@ -375,7 +370,7 @@ export default class EachBlockWrapper extends Wrapper {
|
|
|
|
var ${iterations} = [];
|
|
|
|
var ${iterations} = [];
|
|
|
|
|
|
|
|
|
|
|
|
for (var #i = 0; #i < ${this.vars.each_block_value}.${length}; #i += 1) {
|
|
|
|
for (var #i = 0; #i < ${this.vars.each_block_value}.${length}; #i += 1) {
|
|
|
|
${iterations}[#i] = ${create_each_block}($$, ${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i));
|
|
|
|
${iterations}[#i] = ${create_each_block}(${this.vars.get_each_context}(ctx, ${this.vars.each_block_value}, #i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
@ -439,14 +434,14 @@ export default class EachBlockWrapper extends Wrapper {
|
|
|
|
if (${iterations}[#i]) {
|
|
|
|
if (${iterations}[#i]) {
|
|
|
|
${iterations}[#i].p(changed, child_ctx);
|
|
|
|
${iterations}[#i].p(changed, child_ctx);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${iterations}[#i] = ${create_each_block}($$, child_ctx);
|
|
|
|
${iterations}[#i] = ${create_each_block}(child_ctx);
|
|
|
|
${iterations}[#i].c();
|
|
|
|
${iterations}[#i].c();
|
|
|
|
${iterations}[#i].m(${updateMountNode}, ${anchor});
|
|
|
|
${iterations}[#i].m(${updateMountNode}, ${anchor});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
${has_transitions && `${iterations}[#i].i();`}
|
|
|
|
${has_transitions && `${iterations}[#i].i();`}
|
|
|
|
`
|
|
|
|
`
|
|
|
|
: deindent`
|
|
|
|
: deindent`
|
|
|
|
${iterations}[#i] = ${create_each_block}($$, child_ctx);
|
|
|
|
${iterations}[#i] = ${create_each_block}(child_ctx);
|
|
|
|
${iterations}[#i].c();
|
|
|
|
${iterations}[#i].c();
|
|
|
|
${iterations}[#i].m(${updateMountNode}, ${anchor});
|
|
|
|
${iterations}[#i].m(${updateMountNode}, ${anchor});
|
|
|
|
${has_transitions && `${iterations}[#i].i();`}
|
|
|
|
${has_transitions && `${iterations}[#i].i();`}
|
|
|
@ -499,9 +494,4 @@ export default class EachBlockWrapper extends Wrapper {
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.destroy.addBlock(`@destroyEach(${iterations}, detach);`);
|
|
|
|
block.builders.destroy.addBlock(`@destroyEach(${iterations}, detach);`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
remount(name: string) {
|
|
|
|
|
|
|
|
// TODO consider keyed blocks
|
|
|
|
|
|
|
|
return `for (var #i = 0; #i < ${this.vars.iterations}.length; #i += 1) ${this.vars.iterations}[#i].m(${name}.$$.slotted.default, null);`;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|