code gold / remove obsolete code (e.g. the "outside reactivity" code is no longer needed because we now mark these deriveds clean if they show the latest value)

async-another-try-pt-3
Simon Holthausen 11 hours ago
parent d654c969d3
commit 799b1096fa
No known key found for this signature in database

@ -387,22 +387,12 @@ export class Batch {
if (this.is_fork) return true; if (this.is_fork) return true;
if (this.#blocking_pending === null) return false; if (this.#blocking_pending === null) return false;
for (const effect of this.#blocking_pending.keys()) { for (let e of this.#blocking_pending.keys()) {
var e = effect; // pending work inside a skipped branch doesn't block, the branch is going to be destroyed
var skipped = false; while (e.parent !== null && !this.#skipped_branches.has(e)) {
while (e.parent !== null) {
if (this.#skipped_branches.has(e)) {
skipped = true;
break;
}
e = e.parent; e = e.parent;
} }
if (e.parent === null) return true;
if (!skipped) {
return true;
}
} }
return false; return false;
@ -786,9 +776,6 @@ export class Batch {
? !this.seen_effects?.has(effect) && !this.#dirty_reactions.has(effect) ? !this.seen_effects?.has(effect) && !this.#dirty_reactions.has(effect)
: (flags & (ASYNC | BLOCK_EFFECT)) === 0 || this.seen_effects?.has(effect) : (flags & (ASYNC | BLOCK_EFFECT)) === 0 || this.seen_effects?.has(effect)
) { ) {
if (this.#dirty_reactions.get(effect) === MAYBE_DIRTY) {
this.#dirty_reactions.delete(effect);
}
this.schedule(effect, status); this.schedule(effect, status);
marked = true; marked = true;
} }
@ -949,7 +936,7 @@ export class Batch {
// so comparing what was read against the real value could not attribute the value to the right // so comparing what was read against the real value could not attribute the value to the right
// batch, see `async-dont-rebase-new-batch-4`. We only need to look one level deep: `is_dirty` // batch, see `async-dont-rebase-new-batch-4`. We only need to look one level deep: `is_dirty`
// evaluates the top-most deriveds first, so a dependency derived that was itself not the latest // evaluates the top-most deriveds first, so a dependency derived that was itself not the latest
// value was not written to the real world, and differs from our value for it. // value was not written to the real world, which the check above already catches.
for (let batch = this.next; batch !== null && is_latest_value; batch = batch.next) { for (let batch = this.next; batch !== null && is_latest_value; batch = batch.next) {
if (batch.is_fork) continue; if (batch.is_fork) continue;
@ -957,10 +944,8 @@ export class Batch {
if ( if (
batch.current.has(source) || batch.current.has(source) ||
((source.f & DERIVED) !== 0 && ((source.f & DERIVED) !== 0 &&
/** @type {Derived} */ (source).deps?.some( /** @type {Derived} */ (source).deps?.some((d) =>
(d) => /** @type {Batch} */ (batch).current.has(d)
/** @type {Batch} */ (batch).current.has(d) ||
(this.current.has(d) && /** @type {{ v: any }} */ (this.current.get(d)).v !== d.v)
)) ))
) { ) {
is_latest_value = false; is_latest_value = false;
@ -1018,7 +1003,9 @@ export class Batch {
) { ) {
if (current !== undefined) this.current.set(source, current); if (current !== undefined) this.current.set(source, current);
} else { } else {
this.queue_revalidation(source); queue_micro_task(() => {
if (this.linked && this.mark(source, DIRTY)) this.flush();
});
} }
} }
} }
@ -1042,15 +1029,6 @@ export class Batch {
}); });
} }
/** @param {Value} source */
queue_revalidation(source) {
queue_micro_task(() => {
if (this.linked && this.mark(source, DIRTY)) {
this.flush();
}
});
}
/** /**
* Activate batch - could be merged into another batch in the meantime, * Activate batch - could be merged into another batch in the meantime,
* in which case that other batch becomes the active batch. * in which case that other batch becomes the active batch.

@ -195,8 +195,7 @@ export function async_derived(fn, label, location) {
// If an earlier batch has a run of this async effect in flight, the two batches // If an earlier batch has a run of this async effect in flight, the two batches
// are related and this one has to wait for (i.e. merge into) the earlier one. // are related and this one has to wait for (i.e. merge into) the earlier one.
// Same for forks, though the other way around (the fork has to wait for this batch). // Same for forks, though the other way around (the fork has to wait for this batch).
let other = first_batch; for (let other = first_batch; other !== null; other = other.next) {
while (other) {
if (other !== batch && other.async_deriveds.has(effect)) { if (other !== batch && other.async_deriveds.has(effect)) {
if (other.id < batch.id) { if (other.id < batch.id) {
batch.dependent.add(other); batch.dependent.add(other);
@ -204,7 +203,6 @@ export function async_derived(fn, label, location) {
other.dependent.add(batch); other.dependent.add(batch);
} }
} }
other = other.next;
} }
if (should_suspend) { if (should_suspend) {
@ -425,9 +423,7 @@ export function execute_derived(derived) {
*/ */
export function update_derived(derived) { export function update_derived(derived) {
var value = execute_derived(derived); var value = execute_derived(derived);
var d = own_value(derived); if (!derived.equals.call(own_value(derived), value)) {
if (d === derived ? !derived.equals(value) : !derived.equals.call(d, value)) {
if (current_batch !== null || previous_batch !== null) { if (current_batch !== null || previous_batch !== null) {
// `capture` decides whether the underlying value is updated (it isn't in a fork, // `capture` decides whether the underlying value is updated (it isn't in a fork,
// or if a later batch holds a newer value) and records it in the batch either way. // or if a later batch holds a newer value) and records it in the batch either way.
@ -460,11 +456,7 @@ export function update_derived(derived) {
// During time travelling, keep stale results batch-local. A result computed // During time travelling, keep stale results batch-local. A result computed
// from the latest inputs can be marked globally clean, even if it is unchanged // from the latest inputs can be marked globally clean, even if it is unchanged
// and its write version therefore remains below its dependencies' versions. // and its write version therefore remains below its dependencies' versions.
if ( if (batch_values !== null) {
batch_values !== null ||
// "read outside of reactivity", e.g. in an event handler
(!current_batch && first_batch?.next)
) {
// only cache the value if we're in a tracking context, otherwise we won't // only cache the value if we're in a tracking context, otherwise we won't
// clear the cache in `mark_reactions` when dependencies are updated // clear the cache in `mark_reactions` when dependencies are updated
if (effect_tracking() || current_batch?.is_fork) { if (effect_tracking() || current_batch?.is_fork) {

@ -38,7 +38,6 @@ import {
schedule_effect, schedule_effect,
legacy_updates, legacy_updates,
current_batch, current_batch,
first_batch,
own_value own_value
} from './batch.js'; } from './batch.js';
import { proxy } from '../proxy.js'; import { proxy } from '../proxy.js';
@ -190,9 +189,7 @@ var count_deps = 0;
* @returns {V} * @returns {V}
*/ */
export function internal_set(source, value, updated_during_traversal = null) { export function internal_set(source, value, updated_during_traversal = null) {
var s = own_value(source); if (!source.equals.call(own_value(source), value)) {
if (s === source ? !source.equals(value) : !source.equals.call(s, value)) {
if (is_destroying_effect) { if (is_destroying_effect) {
old_values.set(source, value); old_values.set(source, value);
} else if (!old_values.has(source)) { } else if (!old_values.has(source)) {
@ -211,11 +208,7 @@ export function internal_set(source, value, updated_during_traversal = null) {
// During time traveling we don't want to reset the status so that // During time traveling we don't want to reset the status so that
// traversal of the graph in the other batches still happens // traversal of the graph in the other batches still happens
if ( if (batch_values === null) {
batch_values === null &&
// could also be "read outside of reactivity", e.g. in an event handler
!first_batch?.next
) {
update_derived_status(derived); update_derived_status(derived);
} }
} }

Loading…
Cancel
Save