chore: make versioning more consistent (#12058)

pull/12062/head
Rich Harris 5 months ago committed by GitHub
parent 7a0ce2dfea
commit 0ef906c569
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -103,8 +103,9 @@ export function update_derived(derived, force_schedule) {
set_signal_status(derived, status); set_signal_status(derived, status);
if (!derived.equals(value)) { if (!derived.equals(value)) {
derived.version = increment_version();
derived.v = value; derived.v = value;
derived.version = increment_version();
mark_reactions(derived, DIRTY, force_schedule); mark_reactions(derived, DIRTY, force_schedule);
if (DEV && force_schedule) { if (DEV && force_schedule) {

@ -78,12 +78,12 @@ export function mutate(source, value) {
/** /**
* @template V * @template V
* @param {import('#client').Source<V>} signal * @param {import('#client').Source<V>} source
* @param {V} value * @param {V} value
* @returns {V} * @returns {V}
*/ */
export function set(signal, value) { export function set(source, value) {
var initialized = signal.v !== UNINITIALIZED; var initialized = source.v !== UNINITIALIZED;
if ( if (
initialized && initialized &&
@ -94,11 +94,11 @@ export function set(signal, value) {
e.state_unsafe_mutation(); e.state_unsafe_mutation();
} }
if (!signal.equals(value)) { if (!source.equals(value)) {
signal.v = value; source.v = value;
source.version = increment_version();
// Increment write version so that unowned signals can properly track dirtiness mark_reactions(source, DIRTY, true);
signal.version = increment_version();
// If the current signal is running for the first time, it won't have any // If the current signal is running for the first time, it won't have any
// reactions as we only allocate and assign the reactions after the signal // reactions as we only allocate and assign the reactions after the signal
@ -116,25 +116,23 @@ export function set(signal, value) {
(current_effect.f & CLEAN) !== 0 && (current_effect.f & CLEAN) !== 0 &&
(current_effect.f & BRANCH_EFFECT) === 0 (current_effect.f & BRANCH_EFFECT) === 0
) { ) {
if (current_dependencies !== null && current_dependencies.includes(signal)) { if (current_dependencies !== null && current_dependencies.includes(source)) {
set_signal_status(current_effect, DIRTY); set_signal_status(current_effect, DIRTY);
schedule_effect(current_effect); schedule_effect(current_effect);
} else { } else {
if (current_untracked_writes === null) { if (current_untracked_writes === null) {
set_current_untracked_writes([signal]); set_current_untracked_writes([source]);
} else { } else {
current_untracked_writes.push(signal); current_untracked_writes.push(source);
} }
} }
} }
mark_reactions(signal, DIRTY, true);
if (DEV) { if (DEV) {
if (is_batching_effect) { if (is_batching_effect) {
set_last_inspected_signal(/** @type {import('#client').ValueDebug} */ (signal)); set_last_inspected_signal(/** @type {import('#client').ValueDebug} */ (source));
} else { } else {
for (const fn of /** @type {import('#client').ValueDebug} */ (signal).inspect) fn(); for (const fn of /** @type {import('#client').ValueDebug} */ (source).inspect) fn();
} }
} }
} }

Loading…
Cancel
Save