fix reactive updates not reflected when handle promise (#3660)

pull/3682/head
Tan Li Hau 5 years ago committed by Conduitry
parent 52c086b1b9
commit 7d9262c421

@ -14,6 +14,8 @@ export function handle_promise(promise, info) {
const child_ctx = assign(assign({}, info.ctx), info.resolved);
const block = type && (info.current = type)(child_ctx);
let needs_flush = false;
if (info.block) {
if (info.blocks) {
info.blocks.forEach((block, i) => {
@ -33,11 +35,15 @@ export function handle_promise(promise, info) {
transition_in(block, 1);
block.m(info.mount(), info.anchor);
flush();
needs_flush = true;
}
info.block = block;
if (info.blocks) info.blocks[index] = block;
if (needs_flush) {
flush();
}
}
if (is_promise(promise)) {

@ -0,0 +1,13 @@
export default {
html: `<p>wait for it...</p>`,
test({ assert, component, target }) {
return component.promise
.then(() => {
assert.htmlEqual(target.innerHTML, `
<p>the answer is 42!</p>
<p>the answer100 is 4200!</p>
`);
});
}
};

@ -0,0 +1,21 @@
<script>
let answer = 0;
$: answer100 = answer * 100;
export let promise = new Promise(resolve => {
setTimeout(() => {
resolve();
answer = 42;
}, 0)
});
</script>
{#if promise}
{#await promise}
<p>wait for it...</p>
{:then _}
<p>the answer is {answer}!</p>
<p>the answer100 is {answer100}!</p>
{:catch error}
<p>well that's odd</p>
{/await}
{/if}
Loading…
Cancel
Save