Dominic Gannaway 10 months ago
parent a4bf5e3981
commit e6cd4265eb

@ -192,4 +192,4 @@ export {
export { createRawSnippet } from './internal/client/dom/blocks/snippet.js'; export { createRawSnippet } from './internal/client/dom/blocks/snippet.js';
export { suspend, unsuspend } from './internal/client/dom/blocks/boundary.js'; export { create_suspense } from './internal/client/dom/blocks/boundary.js';

@ -111,10 +111,13 @@ export function boundary(node, props, boundary_fn) {
suspend_count++; suspend_count++;
if (suspended_effect === null) { if (suspended_effect === null) {
queue_micro_task(() => {
var effect = boundary_effect; var effect = boundary_effect;
suspended_effect = boundary_effect; suspended_effect = boundary_effect;
pause_effect(suspended_effect, () => { pause_effect(
suspended_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;
@ -129,11 +132,14 @@ export function boundary(node, props, boundary_fn) {
suspended_fragment.append(node); suspended_fragment.append(node);
node = sibling; node = sibling;
} }
}, false); },
false
);
render_snippet(() => { render_snippet(() => {
pending(anchor); pending(anchor);
}); });
});
} }
return true; return true;
} }
@ -211,13 +217,17 @@ export function boundary(node, props, boundary_fn) {
} }
} }
export function suspend() { /**
var current = active_effect; * @param {Effect | null} effect
* @param {typeof SUSPEND_INCREMENT | typeof SUSPEND_DECREMENT} trigger
*/
function trigger_suspense(effect, trigger) {
var current = effect;
while (current !== null) { while (current !== null) {
if ((current.f & BOUNDARY_EFFECT) !== 0) { if ((current.f & BOUNDARY_EFFECT) !== 0) {
// @ts-ignore // @ts-ignore
if (current.fn(SUSPEND_INCREMENT)) { if (current.fn(trigger)) {
return; return;
} }
} }
@ -225,16 +235,16 @@ export function suspend() {
} }
} }
export function unsuspend() { export function create_suspense() {
var current = active_effect; var current = active_effect;
while (current !== null) { const suspend = () => {
if ((current.f & BOUNDARY_EFFECT) !== 0) { trigger_suspense(current, SUSPEND_INCREMENT);
// @ts-ignore };
if (current.fn(SUSPEND_DECREMENT)) {
return; const unsuspend = () => {
} trigger_suspense(current, SUSPEND_DECREMENT);
} };
current = current.parent;
} return [suspend, unsuspend];
} }

@ -129,7 +129,7 @@ export {
update_store, update_store,
mark_store_binding mark_store_binding
} from './reactivity/store.js'; } from './reactivity/store.js';
export { boundary, suspend } from './dom/blocks/boundary.js'; export { boundary } from './dom/blocks/boundary.js';
export { set_text } from './render.js'; export { set_text } from './render.js';
export { export {
get, get,

Loading…
Cancel
Save