|
|
@ -63,7 +63,7 @@ export default class EachBlock extends Node {
|
|
|
|
|
|
|
|
|
|
|
|
this.var = block.getUniqueName(`each`);
|
|
|
|
this.var = block.getUniqueName(`each`);
|
|
|
|
this.iterations = block.getUniqueName(`${this.var}_blocks`);
|
|
|
|
this.iterations = block.getUniqueName(`${this.var}_blocks`);
|
|
|
|
this.each_context = block.getUniqueName(`${this.var}_context`);
|
|
|
|
this.get_each_context = block.getUniqueName(`get_${this.var}_context`);
|
|
|
|
|
|
|
|
|
|
|
|
const { dependencies } = this.expression;
|
|
|
|
const { dependencies } = this.expression;
|
|
|
|
block.addDependencies(dependencies);
|
|
|
|
block.addDependencies(dependencies);
|
|
|
@ -88,14 +88,14 @@ export default class EachBlock extends Node {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.contextProps = [
|
|
|
|
this.contextProps = [
|
|
|
|
`${listName}: ${listName}`,
|
|
|
|
`${listName}: list`,
|
|
|
|
`${this.context}: ${listName}[#i]`,
|
|
|
|
`${this.context}: list[i]`,
|
|
|
|
`${indexName}: #i`
|
|
|
|
`${indexName}: i`
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
if (this.destructuredContexts) {
|
|
|
|
if (this.destructuredContexts) {
|
|
|
|
for (let i = 0; i < this.destructuredContexts.length; i += 1) {
|
|
|
|
for (let i = 0; i < this.destructuredContexts.length; i += 1) {
|
|
|
|
this.contextProps.push(`${this.destructuredContexts[i]}: ${listName}[#i][${i}]`);
|
|
|
|
this.contextProps.push(`${this.destructuredContexts[i]}: list[i][${i}]`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -162,6 +162,14 @@ export default class EachBlock extends Node {
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.init.addLine(`var ${each_block_value} = ${snippet};`);
|
|
|
|
block.builders.init.addLine(`var ${each_block_value} = ${snippet};`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.compiler.target.blocks.push(deindent`
|
|
|
|
|
|
|
|
function ${this.get_each_context}(ctx, list, i) {
|
|
|
|
|
|
|
|
return @assign(@assign({}, ctx), {
|
|
|
|
|
|
|
|
${this.contextProps.join(',\n')}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
if (this.key) {
|
|
|
|
if (this.key) {
|
|
|
|
this.buildKeyed(block, parentNode, parentNodes, snippet, vars);
|
|
|
|
this.buildKeyed(block, parentNode, parentNodes, snippet, vars);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -349,9 +357,7 @@ export default class EachBlock extends Node {
|
|
|
|
var ${iterations} = [];
|
|
|
|
var ${iterations} = [];
|
|
|
|
|
|
|
|
|
|
|
|
for (var #i = 0; #i < ${each_block_value}.${length}; #i += 1) {
|
|
|
|
for (var #i = 0; #i < ${each_block_value}.${length}; #i += 1) {
|
|
|
|
${iterations}[#i] = ${create_each_block}(#component, @assign(@assign({}, ctx), {
|
|
|
|
${iterations}[#i] = ${create_each_block}(#component, ${this.get_each_context}(ctx, ${each_block_value}, #i));
|
|
|
|
${this.contextProps.join(',\n')}
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
@ -395,24 +401,24 @@ export default class EachBlock extends Node {
|
|
|
|
? this.block.hasIntroMethod
|
|
|
|
? this.block.hasIntroMethod
|
|
|
|
? deindent`
|
|
|
|
? deindent`
|
|
|
|
if (${iterations}[#i]) {
|
|
|
|
if (${iterations}[#i]) {
|
|
|
|
${iterations}[#i].p(changed, ${this.each_context});
|
|
|
|
${iterations}[#i].p(changed, child_ctx);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${iterations}[#i] = ${create_each_block}(#component, ${this.each_context});
|
|
|
|
${iterations}[#i] = ${create_each_block}(#component, child_ctx);
|
|
|
|
${iterations}[#i].c();
|
|
|
|
${iterations}[#i].c();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
${iterations}[#i].i(${updateMountNode}, ${anchor});
|
|
|
|
${iterations}[#i].i(${updateMountNode}, ${anchor});
|
|
|
|
`
|
|
|
|
`
|
|
|
|
: deindent`
|
|
|
|
: deindent`
|
|
|
|
if (${iterations}[#i]) {
|
|
|
|
if (${iterations}[#i]) {
|
|
|
|
${iterations}[#i].p(changed, ${this.each_context});
|
|
|
|
${iterations}[#i].p(changed, child_ctx);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${iterations}[#i] = ${create_each_block}(#component, ${this.each_context});
|
|
|
|
${iterations}[#i] = ${create_each_block}(#component, child_ctx);
|
|
|
|
${iterations}[#i].c();
|
|
|
|
${iterations}[#i].c();
|
|
|
|
${iterations}[#i].m(${updateMountNode}, ${anchor});
|
|
|
|
${iterations}[#i].m(${updateMountNode}, ${anchor});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
`
|
|
|
|
: deindent`
|
|
|
|
: deindent`
|
|
|
|
${iterations}[#i] = ${create_each_block}(#component, ${this.each_context});
|
|
|
|
${iterations}[#i] = ${create_each_block}(#component, child_ctx);
|
|
|
|
${iterations}[#i].c();
|
|
|
|
${iterations}[#i].c();
|
|
|
|
${iterations}[#i].${mountOrIntro}(${updateMountNode}, ${anchor});
|
|
|
|
${iterations}[#i].${mountOrIntro}(${updateMountNode}, ${anchor});
|
|
|
|
`;
|
|
|
|
`;
|
|
|
@ -447,9 +453,7 @@ export default class EachBlock extends Node {
|
|
|
|
${each_block_value} = ${snippet};
|
|
|
|
${each_block_value} = ${snippet};
|
|
|
|
|
|
|
|
|
|
|
|
for (var #i = ${start}; #i < ${each_block_value}.${length}; #i += 1) {
|
|
|
|
for (var #i = ${start}; #i < ${each_block_value}.${length}; #i += 1) {
|
|
|
|
var ${this.each_context} = @assign(@assign({}, ctx), {
|
|
|
|
const child_ctx = ${this.get_each_context}(ctx, ${each_block_value}, #i);
|
|
|
|
${this.contextProps.join(',\n')}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
${forLoopBody}
|
|
|
|
${forLoopBody}
|
|
|
|
}
|
|
|
|
}
|
|
|
|