From 92c9993d9ed777633e33b96e20eba19ca451f73b Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sun, 6 Oct 2019 10:20:23 +0800 Subject: [PATCH 1/2] fix reactive not updated when handle promise --- src/runtime/internal/await_block.ts | 8 ++++++- .../_config.js | 13 ++++++++++++ .../main.svelte | 21 +++++++++++++++++++ .../promise.js | 7 +++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/await-set-simultaneous-reactive/_config.js create mode 100644 test/runtime/samples/await-set-simultaneous-reactive/main.svelte create mode 100644 test/runtime/samples/await-set-simultaneous-reactive/promise.js diff --git a/src/runtime/internal/await_block.ts b/src/runtime/internal/await_block.ts index 4037caa98e47..0bb7b9273f47 100644 --- a/src/runtime/internal/await_block.ts +++ b/src/runtime/internal/await_block.ts @@ -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 needFlush = 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(); + needFlush = true; } info.block = block; if (info.blocks) info.blocks[index] = block; + + if (needFlush) { + flush(); + } } if (is_promise(promise)) { diff --git a/test/runtime/samples/await-set-simultaneous-reactive/_config.js b/test/runtime/samples/await-set-simultaneous-reactive/_config.js new file mode 100644 index 000000000000..a591bf424fb6 --- /dev/null +++ b/test/runtime/samples/await-set-simultaneous-reactive/_config.js @@ -0,0 +1,13 @@ +export default { + html: `

wait for it...

`, + test({ assert, component, target }) { + + return component.promise + .then(() => { + assert.htmlEqual(target.innerHTML, ` +

the answer is 42!

+

the answer100 is 4200!

+ `); + }); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/await-set-simultaneous-reactive/main.svelte b/test/runtime/samples/await-set-simultaneous-reactive/main.svelte new file mode 100644 index 000000000000..c1bbac66be2b --- /dev/null +++ b/test/runtime/samples/await-set-simultaneous-reactive/main.svelte @@ -0,0 +1,21 @@ + + +{#if promise} + {#await promise} +

wait for it...

+ {:then _} +

the answer is {answer}!

+

the answer100 is {answer100}!

+ {:catch error} +

well that's odd

+ {/await} +{/if} \ No newline at end of file diff --git a/test/runtime/samples/await-set-simultaneous-reactive/promise.js b/test/runtime/samples/await-set-simultaneous-reactive/promise.js new file mode 100644 index 000000000000..1f06582c9ee0 --- /dev/null +++ b/test/runtime/samples/await-set-simultaneous-reactive/promise.js @@ -0,0 +1,7 @@ +let _resolvePromise; + +export const resolvePromise = () => _resolvePromise(); + +export const promise = new Promise(resolve => { + _resolvePromise = resolve(); +}); From 434e4fa04f4f008cb308f635e8d8121ec544ed37 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 9 Oct 2019 12:53:00 -0400 Subject: [PATCH 2/2] tidy --- src/runtime/internal/await_block.ts | 6 +++--- .../samples/await-set-simultaneous-reactive/promise.js | 7 ------- 2 files changed, 3 insertions(+), 10 deletions(-) delete mode 100644 test/runtime/samples/await-set-simultaneous-reactive/promise.js diff --git a/src/runtime/internal/await_block.ts b/src/runtime/internal/await_block.ts index 0bb7b9273f47..6cd7ee5cb454 100644 --- a/src/runtime/internal/await_block.ts +++ b/src/runtime/internal/await_block.ts @@ -14,7 +14,7 @@ export function handle_promise(promise, info) { const child_ctx = assign(assign({}, info.ctx), info.resolved); const block = type && (info.current = type)(child_ctx); - let needFlush = false; + let needs_flush = false; if (info.block) { if (info.blocks) { @@ -35,13 +35,13 @@ export function handle_promise(promise, info) { transition_in(block, 1); block.m(info.mount(), info.anchor); - needFlush = true; + needs_flush = true; } info.block = block; if (info.blocks) info.blocks[index] = block; - if (needFlush) { + if (needs_flush) { flush(); } } diff --git a/test/runtime/samples/await-set-simultaneous-reactive/promise.js b/test/runtime/samples/await-set-simultaneous-reactive/promise.js deleted file mode 100644 index 1f06582c9ee0..000000000000 --- a/test/runtime/samples/await-set-simultaneous-reactive/promise.js +++ /dev/null @@ -1,7 +0,0 @@ -let _resolvePromise; - -export const resolvePromise = () => _resolvePromise(); - -export const promise = new Promise(resolve => { - _resolvePromise = resolve(); -});