mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
update await-block to use on_outro and check_outros - fixes #1995
This commit is contained in:
parent
3ec5ff77eb
commit
33a2b54881
@ -1,5 +1,5 @@
|
||||
import { assign, isPromise } from './utils.js';
|
||||
import { group_outros } from './transitions.js';
|
||||
import { check_outros, group_outros, on_outro } from './transitions.js';
|
||||
import { flush } from '../internal/scheduler.js';
|
||||
|
||||
export function handlePromise(promise, info) {
|
||||
@ -18,10 +18,12 @@ export function handlePromise(promise, info) {
|
||||
info.blocks.forEach((block, i) => {
|
||||
if (i !== index && block) {
|
||||
group_outros();
|
||||
block.o(() => {
|
||||
on_outro(() => {
|
||||
block.d(1);
|
||||
info.blocks[i] = null;
|
||||
});
|
||||
block.o();
|
||||
check_outros();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
5
test/runtime/samples/await-with-components/Widget.html
Normal file
5
test/runtime/samples/await-with-components/Widget.html
Normal file
@ -0,0 +1,5 @@
|
||||
{value}
|
||||
|
||||
<script>
|
||||
export let value = 'Loading...';
|
||||
</script>
|
29
test/runtime/samples/await-with-components/_config.js
Normal file
29
test/runtime/samples/await-with-components/_config.js
Normal file
@ -0,0 +1,29 @@
|
||||
export default {
|
||||
async test({ assert, component, target }) {
|
||||
let resolve, reject;
|
||||
let promise = new Promise(ok => resolve = ok);
|
||||
|
||||
component.promise = promise;
|
||||
assert.htmlEqual(target.innerHTML, 'Loading...');
|
||||
|
||||
resolve(42);
|
||||
await promise;
|
||||
assert.htmlEqual(target.innerHTML, '42');
|
||||
|
||||
promise = new Promise((ok, fail) => reject = fail);
|
||||
component.promise = promise;
|
||||
assert.htmlEqual(target.innerHTML, 'Loading...');
|
||||
|
||||
reject(99);
|
||||
await promise.then(null, () => {});
|
||||
assert.htmlEqual(target.innerHTML, '99');
|
||||
|
||||
promise = new Promise(ok => resolve = ok);
|
||||
component.promise = promise;
|
||||
assert.htmlEqual(target.innerHTML, 'Loading...');
|
||||
|
||||
resolve(1);
|
||||
await promise;
|
||||
assert.htmlEqual(target.innerHTML, '1');
|
||||
}
|
||||
};
|
12
test/runtime/samples/await-with-components/main.html
Normal file
12
test/runtime/samples/await-with-components/main.html
Normal file
@ -0,0 +1,12 @@
|
||||
{#await promise}
|
||||
<Widget />
|
||||
{:then result}
|
||||
<Widget value="{result}" />
|
||||
{:catch err}
|
||||
<Widget value="{err}" />
|
||||
{/await}
|
||||
|
||||
<script>
|
||||
import Widget from './Widget.html';
|
||||
export let promise = Promise.resolve();
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user