Skip to content

Commit 18a790c

Browse files
committed
simplify
1 parent dce2563 commit 18a790c

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
187187
}
188188
}
189189

190-
var b = block(() => {
190+
block(() => {
191191
// store a reference to the effect so that we can update the start/end nodes in reconciliation
192192
each_effect ??= /** @type {Effect} */ (active_effect);
193193

@@ -310,7 +310,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
310310
}
311311
}
312312

313-
batch.add_callback(() => b, commit);
313+
batch.add_callback(commit);
314314
} else {
315315
commit();
316316
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function if_block(node, fn, elseif = false) {
124124
if (active) batch.skipped_effects.delete(active);
125125
if (inactive) batch.skipped_effects.add(inactive);
126126

127-
batch.add_callback(() => b, commit);
127+
batch.add_callback(commit);
128128
} else {
129129
commit();
130130
}
@@ -135,7 +135,7 @@ export function if_block(node, fn, elseif = false) {
135135
}
136136
};
137137

138-
var b = block(() => {
138+
block(() => {
139139
has_branch = false;
140140
fn(set_branch);
141141
if (!has_branch) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function key(node, get_key, render_fn) {
5252
effect = pending_effect;
5353
}
5454

55-
var b = block(() => {
55+
block(() => {
5656
if (changed(key, (key = get_key()))) {
5757
var target = anchor;
5858

@@ -66,7 +66,7 @@ export function key(node, get_key, render_fn) {
6666
pending_effect = branch(() => render_fn(target));
6767

6868
if (defer) {
69-
/** @type {Batch} */ (current_batch).add_callback(() => b, commit);
69+
/** @type {Batch} */ (current_batch).add_callback(commit);
7070
} else {
7171
commit();
7272
}

packages/svelte/src/internal/client/dom/blocks/svelte-component.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function component(node, get_component, render_fn) {
5151
pending_effect = null;
5252
}
5353

54-
var b = block(() => {
54+
block(() => {
5555
if (component === (component = get_component())) return;
5656

5757
var defer = should_defer_append();
@@ -70,7 +70,7 @@ export function component(node, get_component, render_fn) {
7070
}
7171

7272
if (defer) {
73-
/** @type {Batch} */ (current_batch).add_callback(() => b, commit);
73+
/** @type {Batch} */ (current_batch).add_callback(commit);
7474
} else {
7575
commit();
7676
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class Batch {
9797
* and append new ones by calling the functions added inside (if/each/key/etc) blocks.
9898
* Key is a function that returns the block effect because #callbacks will be called before
9999
* the block effect reference exists, so we need to capture it in a closure.
100-
* @type {Map<() => Effect, () => void>}
100+
* @type {Map<Effect, () => void>}
101101
*/
102102
#callbacks = new Map();
103103

@@ -229,17 +229,17 @@ export class Batch {
229229
// is outstanding from a previous flush, commit
230230
if (this.#async_effects.length === 0 && this.#pending === 0) {
231231
if (superseded_batches.length > 0) {
232-
const own = [...this.#callbacks.keys()].map((c) => c());
232+
const own = [...this.#callbacks.keys()];
233233
// A superseded batch could have callbacks for e.g. destroying if blocks
234234
// that are not part of the current batch because it already happened in the prior one,
235235
// and the corresponding block effect therefore returning early because nothing was changed from its
236236
// point of view, therefore not adding a callback to the current batch, so we gotta call them here.
237237
// We do it from newest to oldest to ensure the correct callback is applied.
238238
for (const batch of superseded_batches.reverse()) {
239239
for (const [effect, cb] of batch.#callbacks) {
240-
if (!own.includes(effect())) {
240+
if (!own.includes(effect)) {
241241
cb();
242-
own.push(effect());
242+
own.push(effect);
243243
}
244244
}
245245
batch.remove();
@@ -475,11 +475,10 @@ export class Batch {
475475
}
476476

477477
/**
478-
* @param {() => Effect} effect
479478
* @param {() => void} fn
480479
*/
481-
add_callback(effect, fn) {
482-
this.#callbacks.set(effect, fn);
480+
add_callback(fn) {
481+
this.#callbacks.set(/** @type {Effect} */ (active_effect), fn);
483482
}
484483

485484
settled() {

0 commit comments

Comments
 (0)