From 20b7b54b22b37e1b6cb1a46875ad090eecf50979 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 24 Feb 2024 00:43:38 -0500 Subject: [PATCH] tidy up --- .../src/internal/client/reactivity/deriveds.js | 10 +++++----- .../svelte/src/internal/client/reactivity/effects.js | 2 +- .../svelte/src/internal/client/reactivity/types.d.ts | 6 ++---- packages/svelte/src/internal/client/runtime.js | 12 ++++++------ packages/svelte/tests/signals/test.ts | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/deriveds.js b/packages/svelte/src/internal/client/reactivity/deriveds.js index 28d78bff2a..75f3736964 100644 --- a/packages/svelte/src/internal/client/reactivity/deriveds.js +++ b/packages/svelte/src/internal/client/reactivity/deriveds.js @@ -16,11 +16,10 @@ export function derived(fn) { /** @type {import('#client').Derived} */ const signal = { consumers: null, - d: null, + deps: null, eq: default_equals, f: flags, fn: fn, - r: null, // @ts-expect-error v: UNINITIALIZED, w: 0, @@ -33,10 +32,11 @@ export function derived(fn) { } if (current_consumer !== null) { - if (current_consumer.r === null) { - current_consumer.r = [signal]; + const effect = /** @type {import('#client').Effect} */ (current_consumer); + if (effect.r === null) { + effect.r = [signal]; } else { - current_consumer.r.push(signal); + effect.r.push(signal); } } diff --git a/packages/svelte/src/internal/client/reactivity/effects.js b/packages/svelte/src/internal/client/reactivity/effects.js index 06add13e59..c6224fb648 100644 --- a/packages/svelte/src/internal/client/reactivity/effects.js +++ b/packages/svelte/src/internal/client/reactivity/effects.js @@ -28,7 +28,7 @@ import { function create_effect(type, fn, sync, schedule) { /** @type {import('#client').Effect} */ const signal = { - d: null, + deps: null, f: type | DIRTY, l: 0, fn: fn, diff --git a/packages/svelte/src/internal/client/reactivity/types.d.ts b/packages/svelte/src/internal/client/reactivity/types.d.ts index 856625bd95..3995f5095b 100644 --- a/packages/svelte/src/internal/client/reactivity/types.d.ts +++ b/packages/svelte/src/internal/client/reactivity/types.d.ts @@ -29,11 +29,9 @@ export interface SourceDebug extends Source { export interface Derived extends Source { /** dependencies: Signals that this signal reads from */ - d: null | ValueSignal[]; + deps: null | ValueSignal[]; /** init: The function that we invoke for effects and computeds */ fn: () => V; - /** references: Anything that a signal owns */ - r: null | Reaction[]; } export interface DerivedDebug extends Derived { @@ -44,7 +42,7 @@ export interface Effect { /** context: The associated component if this signal is an effect/computed */ ctx: null | ComponentContext; /** dependencies: Signals that this signal reads from */ - d: null | ValueSignal[]; + deps: null | ValueSignal[]; /** destroy: Thing(s) that need destroying */ y: null | (() => void); /** The types that the signal represent, as a bitwise value */ diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index d29bc143c8..47b9dac584 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -163,7 +163,7 @@ function is_signal_dirty(signal) { } if ((flags & MAYBE_DIRTY) !== 0) { - const dependencies = /** @type {import('#client').Reaction} **/ (signal).d; + const dependencies = /** @type {import('#client').Reaction} **/ (signal).deps; if (dependencies !== null) { const length = dependencies.length; @@ -230,7 +230,7 @@ function execute_reaction(signal) { try { const res = /** @type {() => V} */ (init)(); - let dependencies = /** @type {import('#client').ValueSignal[]} **/ (signal.d); + let dependencies = /** @type {import('#client').ValueSignal[]} **/ (signal.deps); if (current_dependencies !== null) { let i; if (dependencies !== null) { @@ -265,7 +265,7 @@ function execute_reaction(signal) { dependencies[current_dependencies_index + i] = current_dependencies[i]; } } else { - signal.d = /** @type {import('#client').ValueSignal[]} **/ ( + signal.deps = /** @type {import('#client').ValueSignal[]} **/ ( dependencies = current_dependencies ); } @@ -336,7 +336,7 @@ function remove_consumer(signal, dependency) { * @returns {void} */ function remove_consumers(signal, start_index) { - const dependencies = signal.d; + const dependencies = signal.deps; if (dependencies !== null) { const active_dependencies = start_index === 0 ? null : dependencies.slice(0, start_index); let i; @@ -664,7 +664,7 @@ function update_derived(signal, force_schedule) { updating_derived = previous_updating_derived; const status = - (current_skip_consumer || (signal.f & UNOWNED) !== 0) && signal.d !== null + (current_skip_consumer || (signal.f & UNOWNED) !== 0) && signal.deps !== null ? MAYBE_DIRTY : CLEAN; @@ -706,7 +706,7 @@ export function get(signal) { // Register the dependency on the current consumer signal. if (current_consumer !== null && (current_consumer.f & MANAGED) === 0 && !current_untracking) { const unowned = (current_consumer.f & UNOWNED) !== 0; - const dependencies = current_consumer.d; + const dependencies = current_consumer.deps; if ( current_dependencies === null && dependencies !== null && diff --git a/packages/svelte/tests/signals/test.ts b/packages/svelte/tests/signals/test.ts index c81c99e937..de5ca18fde 100644 --- a/packages/svelte/tests/signals/test.ts +++ b/packages/svelte/tests/signals/test.ts @@ -229,7 +229,7 @@ describe('signals', () => { // Ensure we're not leaking dependencies assert.deepEqual( - nested.slice(0, -2).map((s) => s.d), + nested.slice(0, -2).map((s) => s.deps), [null, null] ); };