Skip to content

Commit 456e50d

Browse files
authored
chore: use effect(...) instead of user_effect(...) (#10927)
1 parent 7a17e21 commit 456e50d

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

packages/svelte/src/internal/client/dom/blocks/each.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import { insert, remove } from '../reconciler.js';
1818
import { untrack } from '../../runtime.js';
1919
import {
2020
destroy_effect,
21+
effect,
2122
pause_effect,
2223
pause_effects,
2324
render_effect,
24-
resume_effect,
25-
user_effect
25+
resume_effect
2626
} from '../../reactivity/effects.js';
2727
import { source, mutable_source, set } from '../../reactivity/sources.js';
2828
import { is_array, is_frozen, map_get, map_set } from '../../utils.js';
@@ -425,7 +425,7 @@ function reconcile_tracked_array(array, state, anchor, render_fn, flags, keys) {
425425
// we can figure out the eventual destination of the animating elements
426426
// - https://github.com/sveltejs/svelte/pull/10798#issuecomment-2013681778
427427
// - https://svelte.dev/repl/6e891305e9644a7ca7065fa95c79d2d2?version=4.2.9
428-
user_effect(() => {
428+
effect(() => {
429429
untrack(() => {
430430
for (item of to_animate) {
431431
item.a?.apply();

packages/svelte/src/internal/client/dom/elements/bindings/input.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DEV } from 'esm-env';
2-
import { render_effect, user_effect } from '../../../reactivity/effects.js';
2+
import { render_effect, effect } from '../../../reactivity/effects.js';
33
import { stringify } from '../../../render.js';
44
import { listen_to_event_and_reset_event } from './shared.js';
55

@@ -103,11 +103,6 @@ export function bind_group(inputs, group_index, input, get_value, update) {
103103
}
104104
});
105105

106-
user_effect(() => {
107-
// necessary to maintain binding group order in all insertion scenarios. TODO optimise
108-
binding_group.sort((a, b) => (a.compareDocumentPosition(b) === 4 ? -1 : 1));
109-
});
110-
111106
render_effect(() => {
112107
return () => {
113108
var index = binding_group.indexOf(input);
@@ -117,6 +112,11 @@ export function bind_group(inputs, group_index, input, get_value, update) {
117112
}
118113
};
119114
});
115+
116+
effect(() => {
117+
// necessary to maintain binding group order in all insertion scenarios. TODO optimise
118+
binding_group.sort((a, b) => (a.compareDocumentPosition(b) === 4 ? -1 : 1));
119+
});
120120
}
121121

122122
/**

packages/svelte/src/internal/client/dom/elements/bindings/media.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { hydrating } from '../../hydration.js';
2-
import { render_effect, user_effect } from '../../../reactivity/effects.js';
2+
import { render_effect, effect } from '../../../reactivity/effects.js';
33
import { listen } from './shared.js';
44

55
/** @param {TimeRanges} ranges */
@@ -117,7 +117,7 @@ export function bind_playback_rate(media, get_value, update) {
117117

118118
// Needs to happen after the element is inserted into the dom, else playback will be set back to 1 by the browser.
119119
// For hydration we could do it immediately but the additional code is not worth the lost microtask.
120-
user_effect(() => {
120+
effect(() => {
121121
var value = get_value();
122122

123123
// through isNaN we also allow number strings, which is more robust

packages/svelte/src/internal/client/dom/elements/misc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { hydrating } from '../hydration.js';
2-
import { user_effect } from '../../reactivity/effects.js';
2+
import { effect } from '../../reactivity/effects.js';
33

44
/**
55
* @param {HTMLElement} dom
@@ -11,7 +11,7 @@ export function autofocus(dom, value) {
1111
const body = document.body;
1212
dom.autofocus = true;
1313

14-
user_effect(() => {
14+
effect(() => {
1515
if (document.activeElement === body) {
1616
dom.focus();
1717
}

packages/svelte/src/internal/client/dom/elements/transitions.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { noop } from '../../../common.js';
2-
import { user_effect } from '../../reactivity/effects.js';
2+
import { effect } from '../../reactivity/effects.js';
33
import { current_effect, untrack } from '../../runtime.js';
44
import { raf } from '../../timing.js';
55
import { loop } from '../../loop.js';
@@ -202,18 +202,18 @@ export function transition(flags, element, get_fn, get_params) {
202202
}
203203
};
204204

205-
var effect = /** @type {import('#client').Effect} */ (current_effect);
205+
var e = /** @type {import('#client').Effect} */ (current_effect);
206206

207-
(effect.transitions ??= []).push(transition);
207+
(e.transitions ??= []).push(transition);
208208

209209
// if this is a local transition, we only want to run it if the parent (block) effect's
210210
// parent (branch) effect is where the state change happened. we can determine that by
211211
// looking at whether the branch effect is currently initializing
212212
if (is_intro && should_intro) {
213-
var parent = /** @type {import('#client').Effect} */ (effect.parent);
213+
var parent = /** @type {import('#client').Effect} */ (e.parent);
214214

215215
if (is_global || (parent.f & EFFECT_RAN) !== 0) {
216-
user_effect(() => {
216+
effect(() => {
217217
untrack(() => transition.in());
218218
});
219219
}
@@ -237,7 +237,7 @@ function animate(element, options, counterpart, t2, callback) {
237237
/** @type {import('#client').Animation} */
238238
var a;
239239

240-
user_effect(() => {
240+
effect(() => {
241241
var o = untrack(() => options({ direction: t2 === 1 ? 'in' : 'out' }));
242242
a = animate(element, o, counterpart, t2, callback);
243243
});

packages/svelte/src/internal/client/reactivity/store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { subscribe_to_store } from '../../../store/utils.js';
22
import { noop } from '../../common.js';
33
import { UNINITIALIZED } from '../constants.js';
44
import { get, untrack } from '../runtime.js';
5-
import { user_effect } from './effects.js';
5+
import { effect } from './effects.js';
66
import { mutable_source, set } from './sources.js';
77

88
/**
@@ -155,5 +155,5 @@ export function update_pre_store(store, store_value, d = 1) {
155155
* @returns {void}
156156
*/
157157
function on_destroy(fn) {
158-
user_effect(() => () => untrack(fn));
158+
effect(() => () => untrack(fn));
159159
}

0 commit comments

Comments
 (0)