|
|
@ -27,10 +27,10 @@ import {
|
|
|
|
set_hydrate_node
|
|
|
|
set_hydrate_node
|
|
|
|
} from '../hydration.js';
|
|
|
|
} from '../hydration.js';
|
|
|
|
import { get_next_sibling } from '../operations.js';
|
|
|
|
import { get_next_sibling } from '../operations.js';
|
|
|
|
import { queue_before_micro_task } from '../task.js';
|
|
|
|
import { queue_boundary_micro_task } from '../task.js';
|
|
|
|
|
|
|
|
|
|
|
|
const SUSPEND_INCREMENT = Symbol();
|
|
|
|
const ASYNC_INCREMENT = Symbol();
|
|
|
|
const SUSPEND_DECREMENT = Symbol();
|
|
|
|
const ASYNC_DECREMENT = Symbol();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {Effect} boundary
|
|
|
|
* @param {Effect} boundary
|
|
|
@ -70,10 +70,10 @@ export function boundary(node, props, boundary_fn) {
|
|
|
|
/** @type {Effect} */
|
|
|
|
/** @type {Effect} */
|
|
|
|
var boundary_effect;
|
|
|
|
var boundary_effect;
|
|
|
|
/** @type {Effect | null} */
|
|
|
|
/** @type {Effect | null} */
|
|
|
|
var suspended_effect = null;
|
|
|
|
var async_effect = null;
|
|
|
|
/** @type {DocumentFragment | null} */
|
|
|
|
/** @type {DocumentFragment | null} */
|
|
|
|
var suspended_fragment = null;
|
|
|
|
var async_fragment = null;
|
|
|
|
var suspend_count = 0;
|
|
|
|
var async_count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
block(() => {
|
|
|
|
block(() => {
|
|
|
|
var boundary = /** @type {Effect} */ (active_effect);
|
|
|
|
var boundary = /** @type {Effect} */ (active_effect);
|
|
|
@ -101,27 +101,27 @@ export function boundary(node, props, boundary_fn) {
|
|
|
|
boundary.fn = (/** @type {unknown} */ input) => {
|
|
|
|
boundary.fn = (/** @type {unknown} */ input) => {
|
|
|
|
let pending = props.pending;
|
|
|
|
let pending = props.pending;
|
|
|
|
|
|
|
|
|
|
|
|
if (input === SUSPEND_INCREMENT) {
|
|
|
|
if (input === ASYNC_INCREMENT) {
|
|
|
|
if (!pending) {
|
|
|
|
if (!pending) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (suspend_count++ === 0) {
|
|
|
|
if (async_count++ === 0) {
|
|
|
|
queue_before_micro_task(() => {
|
|
|
|
queue_boundary_micro_task(() => {
|
|
|
|
if (suspended_effect) {
|
|
|
|
if (async_effect) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var effect = boundary_effect;
|
|
|
|
var effect = boundary_effect;
|
|
|
|
suspended_effect = boundary_effect;
|
|
|
|
async_effect = boundary_effect;
|
|
|
|
|
|
|
|
|
|
|
|
pause_effect(
|
|
|
|
pause_effect(
|
|
|
|
suspended_effect,
|
|
|
|
async_effect,
|
|
|
|
() => {
|
|
|
|
() => {
|
|
|
|
/** @type {TemplateNode | null} */
|
|
|
|
/** @type {TemplateNode | null} */
|
|
|
|
var node = effect.nodes_start;
|
|
|
|
var node = effect.nodes_start;
|
|
|
|
var end = effect.nodes_end;
|
|
|
|
var end = effect.nodes_end;
|
|
|
|
suspended_fragment = document.createDocumentFragment();
|
|
|
|
async_fragment = document.createDocumentFragment();
|
|
|
|
|
|
|
|
|
|
|
|
while (node !== null) {
|
|
|
|
while (node !== null) {
|
|
|
|
/** @type {TemplateNode | null} */
|
|
|
|
/** @type {TemplateNode | null} */
|
|
|
@ -129,7 +129,7 @@ export function boundary(node, props, boundary_fn) {
|
|
|
|
node === end ? null : /** @type {TemplateNode} */ (get_next_sibling(node));
|
|
|
|
node === end ? null : /** @type {TemplateNode} */ (get_next_sibling(node));
|
|
|
|
|
|
|
|
|
|
|
|
node.remove();
|
|
|
|
node.remove();
|
|
|
|
suspended_fragment.append(node);
|
|
|
|
async_fragment.append(node);
|
|
|
|
node = sibling;
|
|
|
|
node = sibling;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -145,22 +145,22 @@ export function boundary(node, props, boundary_fn) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (input === SUSPEND_DECREMENT) {
|
|
|
|
if (input === ASYNC_DECREMENT) {
|
|
|
|
if (!pending) {
|
|
|
|
if (!pending) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (--suspend_count === 0) {
|
|
|
|
if (--async_count === 0) {
|
|
|
|
queue_before_micro_task(() => {
|
|
|
|
queue_boundary_micro_task(() => {
|
|
|
|
if (!suspended_effect) {
|
|
|
|
if (!async_effect) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (boundary_effect) {
|
|
|
|
if (boundary_effect) {
|
|
|
|
destroy_effect(boundary_effect);
|
|
|
|
destroy_effect(boundary_effect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boundary_effect = suspended_effect;
|
|
|
|
boundary_effect = async_effect;
|
|
|
|
suspended_effect = null;
|
|
|
|
async_effect = null;
|
|
|
|
anchor.before(/** @type {DocumentFragment} */ (suspended_fragment));
|
|
|
|
anchor.before(/** @type {DocumentFragment} */ (async_fragment));
|
|
|
|
resume_effect(boundary_effect);
|
|
|
|
resume_effect(boundary_effect);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -199,7 +199,7 @@ export function boundary(node, props, boundary_fn) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (failed) {
|
|
|
|
if (failed) {
|
|
|
|
queue_before_micro_task(() => {
|
|
|
|
queue_boundary_micro_task(() => {
|
|
|
|
render_snippet(() => {
|
|
|
|
render_snippet(() => {
|
|
|
|
failed(
|
|
|
|
failed(
|
|
|
|
anchor,
|
|
|
|
anchor,
|
|
|
@ -226,9 +226,9 @@ export function boundary(node, props, boundary_fn) {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {Effect | null} effect
|
|
|
|
* @param {Effect | null} effect
|
|
|
|
* @param {typeof SUSPEND_INCREMENT | typeof SUSPEND_DECREMENT} trigger
|
|
|
|
* @param {typeof ASYNC_INCREMENT | typeof ASYNC_DECREMENT} trigger
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function trigger_suspense(effect, trigger) {
|
|
|
|
export function trigger_async_boundary(effect, trigger) {
|
|
|
|
var current = effect;
|
|
|
|
var current = effect;
|
|
|
|
|
|
|
|
|
|
|
|
while (current !== null) {
|
|
|
|
while (current !== null) {
|
|
|
@ -241,17 +241,3 @@ function trigger_suspense(effect, trigger) {
|
|
|
|
current = current.parent;
|
|
|
|
current = current.parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function create_suspense() {
|
|
|
|
|
|
|
|
var current = active_effect;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const suspend = () => {
|
|
|
|
|
|
|
|
trigger_suspense(current, SUSPEND_INCREMENT);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const unsuspend = () => {
|
|
|
|
|
|
|
|
trigger_suspense(current, SUSPEND_DECREMENT);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return [suspend, unsuspend];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|