Format src/runtime/internal/await_block.js

pull/8569/head
S. Elliott Johnson 3 years ago
parent 5a93b97f5f
commit d5761c85c5

@ -1,21 +1,23 @@
import { is_promise } from './utils';
import { check_outros, group_outros, transition_in, transition_out } from './transitions';
import { flush } from './scheduler';
import { get_current_component, set_current_component } from './lifecycle';
/** @param {Promise<T>} promise
import { is_promise } from './utils.js';
import { check_outros, group_outros, transition_in, transition_out } from './transitions.js';
import { flush } from './scheduler.js';
import { get_current_component, set_current_component } from './lifecycle.js';
/**
* @param {Promise<T>} promise
* @param {PromiseInfo<T>} info
* @returns {boolean}
*/
export function handle_promise(promise, info) {
const token = (info.token = {});
/** @param {FragmentFactory} type
/**
* @param {FragmentFactory} type
* @param {0 | 1 | 2} index
* @param {number} key
* @returns {void}
*/
function update(type, index, key, value) {
if (info.token !== token)
return;
if (info.token !== token) return;
info.resolved = value;
let child_ctx = info.ctx;
if (key !== undefined) {
@ -37,8 +39,7 @@ export function handle_promise(promise, info) {
check_outros();
}
});
}
else {
} else {
info.block.d(1);
}
block.c();
@ -47,33 +48,34 @@ export function handle_promise(promise, info) {
needs_flush = true;
}
info.block = block;
if (info.blocks)
info.blocks[index] = block;
if (info.blocks) info.blocks[index] = block;
if (needs_flush) {
flush();
}
}
if (is_promise(promise)) {
const current_component = get_current_component();
promise.then((value) => {
promise.then(
(value) => {
set_current_component(current_component);
update(info.then, 1, info.value, value);
set_current_component(null);
}, (error) => {
},
(error) => {
set_current_component(current_component);
update(info.catch, 2, info.error, error);
set_current_component(null);
if (!info.hasCatch) {
throw error;
}
});
}
);
// if we previously had a then/catch block, destroy it
if (info.current !== info.pending) {
update(info.pending, 0);
return true;
}
}
else {
} else {
if (info.current !== info.then) {
update(info.then, 1, info.value, promise);
return true;
@ -81,6 +83,7 @@ export function handle_promise(promise, info) {
info.resolved = promise;
}
}
/** @returns {void} */
export function update_await_block_branch(info, ctx, dirty) {
const child_ctx = ctx.slice();
@ -94,9 +97,6 @@ export function update_await_block_branch(info, ctx, dirty) {
info.block.p(child_ctx, dirty);
}
/** @typedef {Object} PromiseInfo
* @property {null|any} ctx
* @property {{}} token

Loading…
Cancel
Save