make dep-less derived behaviour more explicit, move it above is_destroying_effect handling

pull/17362/head
Rich Harris 2 weeks ago
parent df7ea6c488
commit ede14ccae3

@ -9,7 +9,8 @@ import {
STALE_REACTION,
ASYNC,
WAS_MARKED,
DESTROYED
DESTROYED,
CLEAN
} from '#client/constants';
import {
active_reaction,
@ -33,7 +34,7 @@ import { UNINITIALIZED } from '../../../constants.js';
import { batch_values, current_batch } from './batch.js';
import { unset_context } from './async.js';
import { deferred } from '../../shared/utils.js';
import { update_derived_status } from './status.js';
import { set_signal_status, update_derived_status } from './status.js';
/** @type {Effect | null} */
export let current_async_effect = null;
@ -356,18 +357,21 @@ export function update_derived(derived) {
var value = execute_derived(derived);
if (!derived.equals(value)) {
derived.wv = increment_write_version();
// in a fork, we don't update the underlying value, just `batch_values`.
// the underlying value will be updated when the fork is committed.
// otherwise, the next time we get here after a 'real world' state
// change, `derived.equals` may incorrectly return `true`
//
// deriveds with no deps should always update `derived.v`
// since they will never change and need the value after fork commits
if (!current_batch?.is_fork || derived.deps === null) {
derived.v = value;
}
derived.wv = increment_write_version();
// deriveds without dependencies should never be recomputed
if (derived.deps === null) {
set_signal_status(derived, CLEAN);
return;
}
}
}
// don't mark derived clean if we're reading it inside a
@ -384,9 +388,7 @@ export function update_derived(derived) {
if (effect_tracking() || current_batch?.is_fork) {
batch_values.set(derived, value);
}
}
if (batch_values === null || derived.deps === null) {
} else {
update_derived_status(derived);
}
}

Loading…
Cancel
Save