Skip to content

Commit d8df737

Browse files
committed
WIP
1 parent 739f5fc commit d8df737

File tree

1 file changed

+42
-29
lines changed
  • packages/svelte/src/internal/client/reactivity

1 file changed

+42
-29
lines changed

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

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,17 @@ export class Batch {
143143

144144
this.apply();
145145

146+
/** @type {EffectTarget} */
147+
var target = {
148+
parent: null,
149+
effect: null,
150+
effects: [],
151+
render_effects: [],
152+
block_effects: []
153+
};
154+
146155
for (const root of root_effects) {
147-
this.#traverse_effect_tree(root);
156+
this.#traverse_effect_tree(root, target);
148157
}
149158

150159
// if there is no outstanding async work, commit
@@ -155,42 +164,45 @@ export class Batch {
155164

156165
this.#commit();
157166

158-
// If sources are written to, then work needs to happen in a separate batch, else prior sources would be mixed with
159-
// newly updated sources, which could lead to infinite loops when effects run over and over again.
160-
previous_batch = this;
161-
current_batch = null;
162-
163167
// batch_values = previous_batch_sources;
164168
// flush_queued_effects(target.render_effects);
165169
// flush_queued_effects(target.effects);
166-
167-
previous_batch = null;
168170
} else {
169171
// this.#defer_effects(target.render_effects);
170172
// this.#defer_effects(target.effects);
171173
// this.#defer_effects(target.block_effects);
172174
}
173175

176+
if (this.#blocking_pending > 0) {
177+
this.#defer_effects(target.effects);
178+
this.#defer_effects(target.render_effects);
179+
this.#defer_effects(target.block_effects);
180+
} else {
181+
// TODO append/detach blocks here as well, not in #commit
182+
183+
// If sources are written to, then work needs to happen in a separate batch, else prior sources would be mixed with
184+
// newly updated sources, which could lead to infinite loops when effects run over and over again.
185+
previous_batch = this;
186+
current_batch = null;
187+
188+
flush_queued_effects(target.render_effects);
189+
flush_queued_effects(target.effects);
190+
191+
previous_batch = null;
192+
}
193+
174194
batch_values = null;
175195
}
176196

177197
/**
178198
* Traverse the effect tree, executing effects or stashing
179199
* them for later execution as appropriate
180200
* @param {Effect} root
201+
* @param {EffectTarget} target
181202
*/
182-
#traverse_effect_tree(root) {
203+
#traverse_effect_tree(root, target) {
183204
root.f ^= CLEAN;
184205

185-
/** @type {EffectTarget} */
186-
var target = {
187-
parent: null,
188-
effect: null,
189-
effects: [],
190-
render_effects: [],
191-
block_effects: []
192-
};
193-
194206
var effect = root.first;
195207

196208
while (effect !== null) {
@@ -249,16 +261,6 @@ export class Batch {
249261
parent = parent.parent;
250262
}
251263
}
252-
253-
if (this.#blocking_pending > 0) {
254-
this.#defer_effects(target.effects);
255-
this.#defer_effects(target.render_effects);
256-
this.#defer_effects(target.block_effects);
257-
} else {
258-
// TODO append/detach blocks here as well
259-
flush_queued_effects(target.render_effects);
260-
flush_queued_effects(target.effects);
261-
}
262264
}
263265

264266
/**
@@ -343,6 +345,15 @@ export class Batch {
343345

344346
let is_earlier = true;
345347

348+
/** @type {EffectTarget} */
349+
var dummy_target = {
350+
parent: null,
351+
effect: null,
352+
effects: [],
353+
render_effects: [],
354+
block_effects: []
355+
};
356+
346357
for (const batch of batches) {
347358
if (batch === this) {
348359
is_earlier = false;
@@ -383,9 +394,11 @@ export class Batch {
383394
batch.apply();
384395

385396
for (const root of queued_root_effects) {
386-
batch.#traverse_effect_tree(root);
397+
batch.#traverse_effect_tree(root, dummy_target);
387398
}
388399

400+
// TODO do we need to do anything with `target`? defer block effects?
401+
389402
queued_root_effects = [];
390403
batch.deactivate();
391404
}

0 commit comments

Comments
 (0)