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,28 +111,34 @@ export function boundary(node, props, boundary_fn) {
suspend_count++; suspend_count++;
if (suspended_effect === null) { if (suspended_effect === null) {
var effect = boundary_effect; queue_micro_task(() => {
suspended_effect = boundary_effect; var effect = boundary_effect;
suspended_effect = boundary_effect;
pause_effect(suspended_effect, () => {
/** @type {TemplateNode | null} */ pause_effect(
var node = effect.nodes_start; suspended_effect,
var end = effect.nodes_end; () => {
suspended_fragment = document.createDocumentFragment(); /** @type {TemplateNode | null} */
var node = effect.nodes_start;
while (node !== null) { var end = effect.nodes_end;
/** @type {TemplateNode | null} */ suspended_fragment = document.createDocumentFragment();
var sibling =
node === end ? null : /** @type {TemplateNode} */ (get_next_sibling(node)); while (node !== null) {
/** @type {TemplateNode | null} */
node.remove(); var sibling =
suspended_fragment.append(node); node === end ? null : /** @type {TemplateNode} */ (get_next_sibling(node));
node = sibling;
} node.remove();
}, false); suspended_fragment.append(node);
node = sibling;
render_snippet(() => { }
pending(anchor); },
false
);
render_snippet(() => {
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