From 8a758d86eeb6c257d6508e3b956def7cd639fe95 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 28 Mar 2024 15:50:20 -0400 Subject: [PATCH] move some code (#10969) --- .../src/internal/client/dom/legacy/lifecycle.js | 11 ++++++++--- packages/svelte/src/internal/common.js | 5 ----- packages/svelte/src/store/index.js | 10 +--------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/packages/svelte/src/internal/client/dom/legacy/lifecycle.js b/packages/svelte/src/internal/client/dom/legacy/lifecycle.js index f6c79de380..0c0090e1f6 100644 --- a/packages/svelte/src/internal/client/dom/legacy/lifecycle.js +++ b/packages/svelte/src/internal/client/dom/legacy/lifecycle.js @@ -1,4 +1,4 @@ -import { run } from '../../../common.js'; +import { run_all } from '../../../common.js'; import { user_pre_effect, user_effect } from '../../reactivity/effects.js'; import { current_component_context, @@ -9,6 +9,11 @@ import { untrack } from '../../runtime.js'; +/** @param {Function} fn */ +function run(fn) { + return fn(); +} + /** * Legacy-mode only: Call `onMount` callbacks and set up `beforeUpdate`/`afterUpdate` effects */ @@ -22,7 +27,7 @@ export function init() { if (callbacks.b.length) { user_pre_effect(() => { observe_all(context); - callbacks.b.forEach(run); + run_all(callbacks.b); // beforeUpdate might change state that affects rendering, ensure the render effects following from it // are batched up with the current run. Avoids for example child components rerunning when they're // now hidden because beforeUpdate did set an if block to false. @@ -49,7 +54,7 @@ export function init() { if (callbacks.a.length) { user_effect(() => { observe_all(context); - callbacks.a.forEach(run); + run_all(callbacks.a); }); } } diff --git a/packages/svelte/src/internal/common.js b/packages/svelte/src/internal/common.js index 9de82f021e..2a4295f276 100644 --- a/packages/svelte/src/internal/common.js +++ b/packages/svelte/src/internal/common.js @@ -19,8 +19,3 @@ export function run_all(arr) { arr[i](); } } - -/** @param {Function} fn */ -export function run(fn) { - return fn(); -} diff --git a/packages/svelte/src/store/index.js b/packages/svelte/src/store/index.js index 762aa4f912..4cfa1624d6 100644 --- a/packages/svelte/src/store/index.js +++ b/packages/svelte/src/store/index.js @@ -1,4 +1,4 @@ -import { noop, run } from '../internal/common.js'; +import { noop, run_all } from '../internal/common.js'; import { subscribe_to_store } from './utils.js'; /** @@ -106,14 +106,6 @@ export function writable(value, start = noop) { return { set, update, subscribe }; } -/** - * @param {Function[]} fns - * @returns {void} - */ -function run_all(fns) { - fns.forEach(run); -} - /** * Derived value store by synchronizing one or more readable stores and * applying an aggregation function over its input values.