aa-fork
Rich Harris 8 months ago
parent 5294730486
commit 51a3d1e4bd

@ -70,42 +70,45 @@ export function if_block(node, fn, elseif = false) {
active_fork.f ^= FORK_ROOT; active_fork.f ^= FORK_ROOT;
const fragment = document.createDocumentFragment(); const fragment = document.createDocumentFragment();
const offscreen_condition = condition;
const offscreen_anchor = document.createComment(''); const offscreen_anchor = document.createComment('');
fragment.append(offscreen_anchor); fragment.append(offscreen_anchor);
const offscreen_effect = fn && branch(() => fn(offscreen_anchor)); try {
const offscreen_effect = fn && branch(() => fn(offscreen_anchor));
active_fork.branches.push(() => { active_fork.branches.push(() => {
anchor.before(fragment); anchor.before(fragment);
if (condition) { if (condition) {
if (consequent_effect) { if (consequent_effect) {
resume_effect(consequent_effect); resume_effect(consequent_effect);
} else { } else {
consequent_effect = offscreen_effect; consequent_effect = offscreen_effect;
if (alternate_effect) { if (alternate_effect) {
pause_effect(alternate_effect, () => { pause_effect(alternate_effect, () => {
alternate_effect = null; alternate_effect = null;
}); });
}
} }
}
} else {
if (alternate_effect) {
resume_effect(alternate_effect);
} else { } else {
alternate_effect = offscreen_effect; if (alternate_effect) {
resume_effect(alternate_effect);
if (consequent_effect) { } else {
pause_effect(consequent_effect, () => { alternate_effect = offscreen_effect;
consequent_effect = null;
}); if (consequent_effect) {
pause_effect(consequent_effect, () => {
consequent_effect = null;
});
}
} }
} }
} });
}); } finally {
active_fork.f |= FORK_ROOT;
}
return; return;
} }

@ -145,6 +145,10 @@ export function fork(fn) {
flush_sync(); flush_sync();
revert(active_fork); revert(active_fork);
if (f.pending === 0) {
f.callback();
}
}); });
} finally { } finally {
active_fork = null; active_fork = null;

Loading…
Cancel
Save