Skip to content

Get context at start of if update block instead of at the end #5531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/AwaitBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)`);
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions test/runtime/samples/await-then-destruct-object-if/_config.js
Original file line number Diff line number Diff line change
@@ -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>
`
);
}
};
19 changes: 19 additions & 0 deletions test/runtime/samples/await-then-destruct-object-if/main.svelte
Original file line number Diff line number Diff line change
@@ -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}