From 0cc74e46fd6e87abc1c7584dcca2afb18c53b864 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 4 Mar 2024 18:44:51 -0700 Subject: [PATCH] remove some needless indirection (#10697) Co-authored-by: Rich Harris --- .../src/internal/client/dom/blocks/each.js | 6 +++--- packages/svelte/src/internal/client/proxy.js | 4 ++-- .../src/internal/client/reactivity/sources.js | 19 +++++-------------- .../svelte/src/internal/client/runtime.js | 7 +++---- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/packages/svelte/src/internal/client/dom/blocks/each.js b/packages/svelte/src/internal/client/dom/blocks/each.js index 59bf93319c..c0acf7cefe 100644 --- a/packages/svelte/src/internal/client/dom/blocks/each.js +++ b/packages/svelte/src/internal/client/dom/blocks/each.js @@ -18,7 +18,7 @@ import { clear_text_content, empty, map_get, map_set } from '../../operations.js import { insert, remove } from '../../reconciler.js'; import { current_block, destroy_signal, execute_effect, push_destroy_fn } from '../../runtime.js'; import { render_effect } from '../../reactivity/effects.js'; -import { source, mutable_source, set_signal_value } from '../../reactivity/sources.js'; +import { source, mutable_source, set } from '../../reactivity/sources.js'; import { trigger_transitions } from '../../transitions.js'; import { is_array } from '../../utils.js'; import { EACH_BLOCK, EACH_ITEM_BLOCK } from '../../constants.js'; @@ -838,7 +838,7 @@ export function get_first_element(block) { function update_each_item_block(block, item, index, type) { const block_v = block.v; if ((type & EACH_ITEM_REACTIVE) !== 0) { - set_signal_value(block_v, item); + set(block_v, item); } const transitions = block.s; const index_is_reactive = (type & EACH_INDEX_REACTIVE) !== 0; @@ -848,7 +848,7 @@ function update_each_item_block(block, item, index, type) { each_animation(block, transitions); } if (index_is_reactive) { - set_signal_value(/** @type {import('../../types.js').Signal} */ (block.i), index); + set(/** @type {import('../../types.js').Signal} */ (block.i), index); } else { block.i = index; } diff --git a/packages/svelte/src/internal/client/proxy.js b/packages/svelte/src/internal/client/proxy.js index 8627fc1f4a..f09f20eaed 100644 --- a/packages/svelte/src/internal/client/proxy.js +++ b/packages/svelte/src/internal/client/proxy.js @@ -18,7 +18,7 @@ import { object_prototype } from './utils.js'; import { add_owner, check_ownership, strip_owner } from './dev/ownership.js'; -import { mutable_source, source, set, set_signal_value } from './reactivity/sources.js'; +import { mutable_source, source, set } from './reactivity/sources.js'; import { STATE_SYMBOL, UNINITIALIZED } from './constants.js'; /** @@ -153,7 +153,7 @@ export function unstate(value) { */ function update_version(signal, d = 1) { const value = untrack(() => get(signal)); - set_signal_value(signal, value + d); + set(signal, value + d); } /** @type {ProxyHandler>} */ diff --git a/packages/svelte/src/internal/client/reactivity/sources.js b/packages/svelte/src/internal/client/reactivity/sources.js index 050b7faac6..e641db4083 100644 --- a/packages/svelte/src/internal/client/reactivity/sources.js +++ b/packages/svelte/src/internal/client/reactivity/sources.js @@ -87,17 +87,6 @@ function create_source_signal(flags, value) { }; } -/** - * @template V - * @param {import('./types.js').Signal} signal - * @param {V} value - * @returns {V} - */ -export function set(signal, value) { - set_signal_value(signal, value); - return value; -} - /** * @template V * @param {import('./types.js').Signal} signal @@ -114,7 +103,7 @@ export function set_sync(signal, value) { * @param {V} value */ export function mutate(source, value) { - set_signal_value( + set( source, untrack(() => get(source)) ); @@ -125,9 +114,9 @@ export function mutate(source, value) { * @template V * @param {import('./types.js').Signal} signal * @param {V} value - * @returns {void} + * @returns {V} */ -export function set_signal_value(signal, value) { +export function set(signal, value) { if ( !current_untracking && !ignore_mutation_validation && @@ -191,4 +180,6 @@ export function set_signal_value(signal, value) { } } } + + return value; } diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index ed8d76f6f8..758b7252f4 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -26,12 +26,11 @@ import { DESTROYED, INERT, MANAGED, - SOURCE, STATE_SYMBOL } from './constants.js'; import { flush_tasks } from './dom/task.js'; import { add_owner } from './dev/ownership.js'; -import { mutate, set_signal_value } from './reactivity/sources.js'; +import { mutate, set } from './reactivity/sources.js'; const IS_EFFECT = EFFECT | PRE_EFFECT | RENDER_EFFECT; @@ -1111,7 +1110,7 @@ function get_parent_context(component_context) { */ export function update(signal, d = 1) { const value = get(signal); - set_signal_value(signal, value + d); + set(signal, value + d); return value; } @@ -1122,7 +1121,7 @@ export function update(signal, d = 1) { */ export function update_pre(signal, d = 1) { const value = get(signal) + d; - set_signal_value(signal, value); + set(signal, value); return value; }