pull/16197/head
Rich Harris 7 months ago
parent 9b36b6be53
commit 3c350dbb94

@ -12,7 +12,8 @@ import {
set_is_destroying_effect, set_is_destroying_effect,
set_signal_status, set_signal_status,
untrack, untrack,
untracking untracking,
flushSync
} from '../runtime.js'; } from '../runtime.js';
import { import {
DIRTY, DIRTY,
@ -41,6 +42,7 @@ import { get_next_sibling } from '../dom/operations.js';
import { async_derived, derived } from './deriveds.js'; import { async_derived, derived } from './deriveds.js';
import { capture, suspend } from '../dom/blocks/boundary.js'; import { capture, suspend } from '../dom/blocks/boundary.js';
import { component_context, dev_current_component_function } from '../context.js'; import { component_context, dev_current_component_function } from '../context.js';
import { active_fork } from './forks.js';
/** /**
* @param {'$effect' | '$effect.pre' | '$inspect'} rune * @param {'$effect' | '$effect.pre' | '$inspect'} rune
@ -338,19 +340,26 @@ export function render_effect(fn, flags = 0) {
* @param {Array<() => Promise<any>>} async * @param {Array<() => Promise<any>>} async
*/ */
export function template_effect(fn, sync = [], async = [], d = derived) { export function template_effect(fn, sync = [], async = [], d = derived) {
let effect = /** @type {Effect} */ (active_effect); var parent = /** @type {Effect} */ (active_effect);
if (async.length > 0) { if (async.length > 0) {
var fork = active_fork;
var restore = capture(); var restore = capture();
Promise.all(async.map((expression) => async_derived(expression))).then((result) => { Promise.all(async.map((expression) => async_derived(expression))).then((result) => {
restore(); restore();
if ((effect.f & DESTROYED) !== 0) { if ((parent.f & DESTROYED) !== 0) {
return; return;
} }
create_template_effect(fn, [...sync.map(d), ...result]); var effect = create_template_effect(fn, [...sync.map(d), ...result]);
if (fork !== null) {
fork.run(() => {
schedule_effect(effect);
});
}
}); });
} else { } else {
create_template_effect(fn, sync.map(d)); create_template_effect(fn, sync.map(d));
@ -370,7 +379,7 @@ function create_template_effect(fn, deriveds) {
}); });
} }
create_effect(RENDER_EFFECT, effect, true); return create_effect(RENDER_EFFECT, effect, true);
} }
/** /**

@ -751,12 +751,20 @@ export function schedule_effect(signal) {
var flags = effect.f; var flags = effect.f;
if ((flags & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) { if ((flags & (ROOT_EFFECT | BRANCH_EFFECT)) !== 0) {
if ((flags & CLEAN) === 0) return; // TODO reinstate this
effect.f ^= CLEAN; // if ((flags & CLEAN) === 0) return;
// effect.f ^= CLEAN;
if ((flags & CLEAN) !== 0) {
effect.f ^= CLEAN;
}
} }
} }
queued_root_effects.push(effect); // TODO reinstate early bail-out when traversing up the graph
if (!queued_root_effects.includes(effect)) {
queued_root_effects.push(effect);
}
} }
export function queue_flush() { export function queue_flush() {
@ -827,7 +835,8 @@ function process_effects(effect, fork) {
} }
} else if ((flags & RENDER_EFFECT) !== 0) { } else if ((flags & RENDER_EFFECT) !== 0) {
if (is_branch) { if (is_branch) {
current_effect.f ^= CLEAN; // TODO clean branch later, if fork is settled
// current_effect.f ^= CLEAN;
} else { } else {
render_effects.push(current_effect); render_effects.push(current_effect);
} }
@ -848,6 +857,7 @@ function process_effects(effect, fork) {
while (parent !== null) { while (parent !== null) {
if (effect === parent) { if (effect === parent) {
// TODO is this still necessary?
break main_loop; break main_loop;
} }

Loading…
Cancel
Save