get context at start of {#if} update block instead of at the end (#5531)

pull/5564/head
Jesse Skinner 4 years ago committed by GitHub
parent f038cf75fa
commit a4e4bd0f53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -96,7 +96,7 @@ class AwaitBlockBranch extends Wrapper {
`);
this.block.chunks.declarations.push(b`${get_context}(#ctx)`);
if (this.block.has_update_method) {
this.block.chunks.update.push(b`${get_context}(#ctx)`);
this.block.chunks.update.unshift(b`${get_context}(#ctx)`);
}
}
}

@ -0,0 +1,29 @@
export default {
props: {
thePromise: Promise.resolve({ result: 1 })
},
html: '',
async test({ assert, component, target }) {
await (component.thePromise = Promise.resolve({ result: 1 }));
assert.htmlEqual(
target.innerHTML,
`
<p>result: 1</p>
<p>count: 0</p>
`
);
await new Promise(resolve => setTimeout(resolve, 1));
assert.htmlEqual(
target.innerHTML,
`
<p>result: 1</p>
<p>count: 1</p>
`
);
}
};

@ -0,0 +1,19 @@
<script>
export let thePromise;
let count = 0;
setTimeout(() => {
count++;
}, 0);
</script>
{#await thePromise then { result }}
{#if result}
<p>result: {result}</p>
<p>count: {count}</p>
{:else}
<p>result: {result}</p>
<p>count: {count}</p>
{/if}
{/await}
Loading…
Cancel
Save