From 0ef906c5694a1dc0342f9ee23899ab17297bf2fa Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 17 Jun 2024 07:16:44 -0700 Subject: [PATCH] chore: make versioning more consistent (#12058) --- .../internal/client/reactivity/deriveds.js | 3 ++- .../src/internal/client/reactivity/sources.js | 26 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/deriveds.js b/packages/svelte/src/internal/client/reactivity/deriveds.js index 7894ea9f0c..dbcffe1797 100644 --- a/packages/svelte/src/internal/client/reactivity/deriveds.js +++ b/packages/svelte/src/internal/client/reactivity/deriveds.js @@ -103,8 +103,9 @@ export function update_derived(derived, force_schedule) { set_signal_status(derived, status); if (!derived.equals(value)) { - derived.version = increment_version(); derived.v = value; + derived.version = increment_version(); + mark_reactions(derived, DIRTY, force_schedule); if (DEV && force_schedule) { diff --git a/packages/svelte/src/internal/client/reactivity/sources.js b/packages/svelte/src/internal/client/reactivity/sources.js index c22915ceea..12d95d400b 100644 --- a/packages/svelte/src/internal/client/reactivity/sources.js +++ b/packages/svelte/src/internal/client/reactivity/sources.js @@ -78,12 +78,12 @@ export function mutate(source, value) { /** * @template V - * @param {import('#client').Source} signal + * @param {import('#client').Source} source * @param {V} value * @returns {V} */ -export function set(signal, value) { - var initialized = signal.v !== UNINITIALIZED; +export function set(source, value) { + var initialized = source.v !== UNINITIALIZED; if ( initialized && @@ -94,11 +94,11 @@ export function set(signal, value) { e.state_unsafe_mutation(); } - if (!signal.equals(value)) { - signal.v = value; + if (!source.equals(value)) { + source.v = value; + source.version = increment_version(); - // Increment write version so that unowned signals can properly track dirtiness - signal.version = increment_version(); + mark_reactions(source, DIRTY, true); // 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 @@ -116,25 +116,23 @@ export function set(signal, value) { (current_effect.f & CLEAN) !== 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); schedule_effect(current_effect); } else { if (current_untracked_writes === null) { - set_current_untracked_writes([signal]); + set_current_untracked_writes([source]); } else { - current_untracked_writes.push(signal); + current_untracked_writes.push(source); } } } - mark_reactions(signal, DIRTY, true); - if (DEV) { if (is_batching_effect) { - set_last_inspected_signal(/** @type {import('#client').ValueDebug} */ (signal)); + set_last_inspected_signal(/** @type {import('#client').ValueDebug} */ (source)); } else { - for (const fn of /** @type {import('#client').ValueDebug} */ (signal).inspect) fn(); + for (const fn of /** @type {import('#client').ValueDebug} */ (source).inspect) fn(); } } }