chore: make Batch prev/next/started public (#18982)

converts some private fields to public ones, because on #18880 they are
used outside the class. breaking the change out removes some diff noise
pull/18800/merge
Rich Harris 24 hours ago committed by GitHub
parent e22a67c432
commit 6480a9737f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -98,15 +98,15 @@ export class Batch {
id = uid++; id = uid++;
/** True as soon as `#process` was called */ /** True as soon as `#process` was called */
#started = false; started = false;
linked = true; linked = true;
/** @type {Batch | null} */ /** @type {Batch | null} */
#prev = null; prev = null;
/** @type {Batch | null} */ /** @type {Batch | null} */
#next = null; next = null;
/** @type {Map<Effect, ReturnType<typeof deferred<any>>>} */ /** @type {Map<Effect, ReturnType<typeof deferred<any>>>} */
async_deriveds = new Map(); async_deriveds = new Map();
@ -205,8 +205,8 @@ export class Batch {
if (last_batch === null) { if (last_batch === null) {
first_batch = last_batch = this; first_batch = last_batch = this;
} else { } else {
last_batch.#next = this; last_batch.next = this;
this.#prev = last_batch; this.prev = last_batch;
} }
last_batch = this; last_batch = this;
@ -320,7 +320,7 @@ export class Batch {
} }
#process() { #process() {
this.#started = true; this.started = true;
if (DEV) { if (DEV) {
// track all the values that were updated during this flush, // track all the values that were updated during this flush,
@ -522,7 +522,7 @@ export class Batch {
} }
#find_earlier_batch() { #find_earlier_batch() {
var batch = this.#prev; var batch = this.prev;
while (batch !== null) { while (batch !== null) {
if (!batch.is_fork) { if (!batch.is_fork) {
@ -534,7 +534,7 @@ export class Batch {
} }
} }
batch = batch.#prev; batch = batch.prev;
} }
return null; return null;
@ -705,7 +705,7 @@ export class Batch {
// in other words, we re-run block/async effects with the newly // in other words, we re-run block/async effects with the newly
// committed state, unless the batch in question has a more // committed state, unless the batch in question has a more
// recent value for a given source // recent value for a given source
for (let batch = first_batch; batch !== null; batch = batch.#next) { for (let batch = first_batch; batch !== null; batch = batch.next) {
var is_earlier = batch.id < this.id; var is_earlier = batch.id < this.id;
/** @type {Source[]} */ /** @type {Source[]} */
@ -742,7 +742,7 @@ export class Batch {
); );
// If not started yet or no sources to update (which is e.g. possible for the very first batch) then bail // If not started yet or no sources to update (which is e.g. possible for the very first batch) then bail
if (!batch.#started || current.length === 0) continue; if (!batch.started || current.length === 0) continue;
// Re-run async/block effects that depend on distinct values changed in both batches (ignoring deriveds) // Re-run async/block effects that depend on distinct values changed in both batches (ignoring deriveds)
var others = current.filter((source) => !this.current.has(source)); var others = current.filter((source) => !this.current.has(source));
@ -908,7 +908,7 @@ export class Batch {
if (!is_processing && !is_flushing_sync) { if (!is_processing && !is_flushing_sync) {
queue_micro_task(() => { queue_micro_task(() => {
if (!batch.#started) { if (!batch.started) {
batch.flush(); batch.flush();
} }
}); });
@ -919,7 +919,7 @@ export class Batch {
} }
apply() { apply() {
if (!async_mode_flag || (!this.is_fork && this.#prev === null && this.#next === null)) { if (!async_mode_flag || (!this.is_fork && this.prev === null && this.next === null)) {
batch_values = null; batch_values = null;
return; return;
} }
@ -932,7 +932,7 @@ export class Batch {
} }
// ...and undo changes belonging to other batches unless they intersect // ...and undo changes belonging to other batches unless they intersect
for (let batch = first_batch; batch !== null; batch = batch.#next) { for (let batch = first_batch; batch !== null; batch = batch.next) {
if (batch === this || batch.is_fork) continue; if (batch === this || batch.is_fork) continue;
// If two batches intersect, the latter batch will be merged into the earlier batch, // If two batches intersect, the latter batch will be merged into the earlier batch,
@ -993,19 +993,19 @@ export class Batch {
// running it multiple times to not corrupt the linked list // running it multiple times to not corrupt the linked list
if (!this.linked) return; if (!this.linked) return;
var prev = this.#prev; var prev = this.prev;
var next = this.#next; var next = this.next;
if (prev === null) { if (prev === null) {
first_batch = next; first_batch = next;
} else { } else {
prev.#next = next; prev.next = next;
} }
if (next === null) { if (next === null) {
last_batch = prev; last_batch = prev;
} else { } else {
next.#prev = prev; next.prev = prev;
} }
this.linked = false; this.linked = false;

Loading…
Cancel
Save