diff --git a/src/compile/render-dom/wrappers/EachBlock.ts b/src/compile/render-dom/wrappers/EachBlock.ts index 519e0ac933..2857b7cb62 100644 --- a/src/compile/render-dom/wrappers/EachBlock.ts +++ b/src/compile/render-dom/wrappers/EachBlock.ts @@ -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();`} `); diff --git a/src/internal/keyed-each.js b/src/internal/keyed-each.js index b68a40e11d..d3afde60fb 100644 --- a/src/internal/keyed-each.js +++ b/src/internal/keyed-each.js @@ -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); diff --git a/test/runtime/samples/each-block-deconflict-name-context/_config.js b/test/runtime/samples/each-block-deconflict-name-context/_config.js index c99416a9cf..d6e9c168fe 100644 --- a/test/runtime/samples/each-block-deconflict-name-context/_config.js +++ b/test/runtime/samples/each-block-deconflict-name-context/_config.js @@ -23,10 +23,8 @@ export default { inputs[1].value = 'w'; inputs[1].dispatchEvent(new window.MouseEvent('input')); - assert.deepEqual(component, { - foo: { - bar: ['x', 'w', 'z'] - } + assert.deepEqual(component.foo, { + bar: ['x', 'w', 'z'] }); } }; diff --git a/test/runtime/samples/each-block-destructured-object-binding/_config.js b/test/runtime/samples/each-block-destructured-object-binding/_config.js index d08a3472ab..704c742830 100644 --- a/test/runtime/samples/each-block-destructured-object-binding/_config.js +++ b/test/runtime/samples/each-block-destructured-object-binding/_config.js @@ -15,11 +15,11 @@ export default {

Doctor Who

`, - 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; diff --git a/test/runtime/samples/each-block-else/_config.js b/test/runtime/samples/each-block-else/_config.js index 7e3a4181ba..22776d492f 100644 --- a/test/runtime/samples/each-block-else/_config.js +++ b/test/runtime/samples/each-block-else/_config.js @@ -1,6 +1,6 @@ export default { props: { - animals: [ 'alpaca', 'baboon', 'capybara' ], + animals: ['alpaca', 'baboon', 'capybara'], foo: 'something else' }, @@ -12,26 +12,26 @@ export default { after `, - test ( assert, component, target ) { + test(assert, component, target) { component.animals = []; - assert.htmlEqual( target.innerHTML, ` + assert.htmlEqual(target.innerHTML, ` before

no animals, but rather something else

after - ` ); + `); component.foo = 'something other'; - assert.htmlEqual( target.innerHTML, ` + assert.htmlEqual(target.innerHTML, ` before

no animals, but rather something other

after - ` ); + `); component.animals = ['wombat']; - assert.htmlEqual( target.innerHTML, ` + assert.htmlEqual(target.innerHTML, ` before

wombat

after - ` ); + `); } };