From 393c2d5090ed6142405452661e5212876e79cdde Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 23 Feb 2024 21:13:35 -0500 Subject: [PATCH] reduce indirection --- .../client/reactivity/computations.js | 62 ++++++++----------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/computations.js b/packages/svelte/src/internal/client/reactivity/computations.js index a36643e137..c2188792dd 100644 --- a/packages/svelte/src/internal/client/reactivity/computations.js +++ b/packages/svelte/src/internal/client/reactivity/computations.js @@ -20,23 +20,39 @@ import { } from '../constants.js'; /** - * @template V - * @param {import('./types.js').SignalFlags} flags - * @param {V} value + * @param {import('#client').Reaction} target_signal + * @param {import('#client').Reaction} ref_signal + * @returns {void} + */ +export function push_reference(target_signal, ref_signal) { + const references = target_signal.r; + if (references === null) { + target_signal.r = [ref_signal]; + } else { + references.push(ref_signal); + } +} + +/** + * @param {import('./types.js').EffectType} type + * @param {(() => void | (() => void))} fn + * @param {boolean} sync + * @param {boolean} schedule + * @returns {import('#client').Effect} */ -function create_computation_signal(flags, value) { +function internal_create_effect(type, fn, sync, schedule) { /** @type {import('#client').Effect} */ const signal = { c: null, d: null, e: null, - f: flags, + f: type | DIRTY, l: 0, - i: null, + i: fn, r: null, - v: value, + v: null, w: 0, - x: null, + x: current_component_context, y: null, in: null, out: null, @@ -50,41 +66,15 @@ function create_computation_signal(flags, value) { signal.inspect = new Set(); } - return signal; -} - -/** - * @param {import('#client').Reaction} target_signal - * @param {import('#client').Reaction} ref_signal - * @returns {void} - */ -export function push_reference(target_signal, ref_signal) { - const references = target_signal.r; - if (references === null) { - target_signal.r = [ref_signal]; - } else { - references.push(ref_signal); - } -} - -/** - * @param {import('./types.js').EffectType} type - * @param {(() => void | (() => void))} fn - * @param {boolean} sync - * @param {boolean} schedule - * @returns {import('#client').Effect} - */ -function internal_create_effect(type, fn, sync, schedule) { - const signal = create_computation_signal(type | DIRTY, null); - signal.i = fn; - signal.x = current_component_context; if (current_effect !== null) { signal.l = current_effect.l + 1; push_reference(current_effect, signal); } + if (schedule) { schedule_effect(signal, sync); } + return signal; }