fix some each block stuff

pull/1864/head
Rich Harris 7 years ago
parent 681c1acd1f
commit ed83c00f88

@ -213,7 +213,7 @@ export default class EachBlockWrapper extends Wrapper {
// TODO neaten this up... will end up with an empty line in the block
block.builders.init.addBlock(deindent`
if (!${this.vars.each_block_value}.${length}) {
${each_block_else} = ${this.else.block.name}(ctx);
${each_block_else} = ${this.else.block.name}(#component, ctx);
${each_block_else}.c();
}
`);
@ -231,7 +231,7 @@ export default class EachBlockWrapper extends Wrapper {
if (!${this.vars.each_block_value}.${length} && ${each_block_else}) {
${each_block_else}.p(changed, ctx);
} else if (!${this.vars.each_block_value}.${length}) {
${each_block_else} = ${this.else.block.name}(ctx);
${each_block_else} = ${this.else.block.name}(#component, ctx);
${each_block_else}.c();
${each_block_else}.${mountOrIntro}(${initialMountNode}, ${this.vars.anchor});
} else if (${each_block_else}) {
@ -247,7 +247,7 @@ export default class EachBlockWrapper extends Wrapper {
${each_block_else} = null;
}
} else if (!${each_block_else}) {
${each_block_else} = ${this.else.block.name}(ctx);
${each_block_else} = ${this.else.block.name}(#component, ctx);
${each_block_else}.c();
${each_block_else}.${mountOrIntro}(${initialMountNode}, ${this.vars.anchor});
}
@ -340,7 +340,7 @@ export default class EachBlockWrapper extends Wrapper {
${this.block.hasOutros && `@groupOutros();`}
${this.node.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].r();`}
${blocks} = @updateKeyedEach(${blocks}, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.vars.each_block_value}, ${lookup}, ${updateMountNode}, ${destroy}, ${create_each_block}, "${mountOrIntro}", ${anchor}, ${this.vars.get_each_context});
${blocks} = @updateKeyedEach(${blocks}, #component, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.vars.each_block_value}, ${lookup}, ${updateMountNode}, ${destroy}, ${create_each_block}, "${mountOrIntro}", ${anchor}, ${this.vars.get_each_context});
${this.node.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].a();`}
`);

@ -14,7 +14,7 @@ export function fixAndOutroAndDestroyBlock(block, lookup) {
outroAndDestroyBlock(block, lookup);
}
export function updateKeyedEach(old_blocks, changed, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block, intro_method, next, get_context) {
export function updateKeyedEach(old_blocks, component, changed, get_key, dynamic, ctx, list, lookup, node, destroy, create_each_block, intro_method, next, get_context) {
var o = old_blocks.length;
var n = list.length;
@ -33,7 +33,7 @@ export function updateKeyedEach(old_blocks, changed, get_key, dynamic, ctx, list
var block = lookup[key];
if (!block) {
block = create_each_block(key, child_ctx);
block = create_each_block(component, key, child_ctx);
block.c();
} else if (dynamic) {
block.p(changed, child_ctx);

@ -23,10 +23,8 @@ export default {
inputs[1].value = 'w';
inputs[1].dispatchEvent(new window.MouseEvent('input'));
assert.deepEqual(component, {
foo: {
assert.deepEqual(component.foo, {
bar: ['x', 'w', 'z']
}
});
}
};

@ -15,11 +15,11 @@ export default {
<p>Doctor Who</p>
`,
test(assert, component, target, window) {
async test(assert, component, target, window) {
const inputs = target.querySelectorAll('input');
inputs[1].value = 'Oz';
inputs[1].dispatchEvent(new window.Event('input'));
await inputs[1].dispatchEvent(new window.Event('input'));
const { people } = component;

Loading…
Cancel
Save