Skip to content

Commit 9737e02

Browse files
committed
simplify
1 parent c07ca7d commit 9737e02

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ import { remove } from '../dom/reconciler.js';
3434
* @param {import('./types.js').EffectType} type
3535
* @param {(() => void | (() => void))} fn
3636
* @param {boolean} sync
37-
* @param {boolean} init
3837
* @returns {import('#client').Effect}
3938
*/
40-
export function create_effect(type, fn, sync, init = true) {
39+
function create_effect(type, fn, sync) {
4140
var is_root = (type & ROOT_EFFECT) !== 0;
4241
/** @type {import('#client').Effect} */
4342
var effect = {
@@ -61,20 +60,18 @@ export function create_effect(type, fn, sync, init = true) {
6160
}
6261
}
6362

64-
if (init) {
65-
if (sync) {
66-
var previously_flushing_effect = is_flushing_effect;
63+
if (sync) {
64+
var previously_flushing_effect = is_flushing_effect;
6765

68-
try {
69-
set_is_flushing_effect(true);
70-
execute_effect(effect);
71-
effect.f |= EFFECT_RAN;
72-
} finally {
73-
set_is_flushing_effect(previously_flushing_effect);
74-
}
75-
} else {
76-
schedule_effect(effect);
66+
try {
67+
set_is_flushing_effect(true);
68+
execute_effect(effect);
69+
effect.f |= EFFECT_RAN;
70+
} finally {
71+
set_is_flushing_effect(previously_flushing_effect);
7772
}
73+
} else {
74+
schedule_effect(effect);
7875
}
7976

8077
return effect;
@@ -112,7 +109,7 @@ export function user_effect(fn) {
112109
const context = /** @type {import('#client').ComponentContext} */ (current_component_context);
113110
(context.e ??= []).push(fn);
114111
} else {
115-
create_effect(EFFECT, fn, false, true);
112+
effect(fn);
116113
}
117114
}
118115

packages/svelte/src/internal/client/runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
object_prototype
99
} from './utils.js';
1010
import { unstate } from './proxy.js';
11-
import { create_effect, destroy_effect, user_pre_effect } from './reactivity/effects.js';
11+
import { destroy_effect, effect, user_pre_effect } from './reactivity/effects.js';
1212
import {
1313
EFFECT,
1414
RENDER_EFFECT,
@@ -1135,7 +1135,7 @@ export function pop(component) {
11351135
if (effects !== null) {
11361136
context_stack_item.e = null;
11371137
for (let i = 0; i < effects.length; i++) {
1138-
create_effect(EFFECT, effects[i], false, true);
1138+
effect(effects[i]);
11391139
}
11401140
}
11411141
current_component_context = context_stack_item.p;

0 commit comments

Comments
 (0)