incremental-batches
Rich Harris 1 month ago
parent 144611a18c
commit afa5af06c9

@ -4,6 +4,7 @@ import { snapshot } from '../../shared/clone.js';
import { DERIVED, ASYNC, PROXY_PATH_SYMBOL, STATE_SYMBOL } from '#client/constants';
import { effect_tracking } from '../reactivity/effects.js';
import { active_reaction, untrack } from '../runtime.js';
import { get_cv, get_wv } from '../reactivity/batch.js';
/**
* @typedef {{
@ -27,7 +28,7 @@ function log_entry(signal, entry) {
const type = get_type(signal);
const current_reaction = /** @type {Reaction} */ (active_reaction);
const dirty = signal.wv > current_reaction.wv || current_reaction.wv === 0;
const dirty = get_wv(signal) > get_cv(current_reaction);
const style = dirty
? 'color: CornflowerBlue; font-weight: bold'
: 'color: grey; font-weight: normal';

@ -1285,13 +1285,27 @@ export function fork(fn) {
};
}
/**
* @param {Value} value
*/
export function get_wv(value) {
return batch_wvs?.get(value) ?? value.wv;
}
/**
* @param {Reaction} reaction
*/
export function get_cv(reaction) {
return batch_cvs?.get(reaction) ?? reaction.cv;
}
/**
* @param {Reaction} reaction
*/
export function set_cv(reaction) {
current_batch?.cvs.set(reaction, write_version);
batch_cvs?.set(reaction, write_version);
reaction.cv = write_version;
export function set_cv(reaction, cv = write_version) {
current_batch?.cvs.set(reaction, cv);
batch_cvs?.set(reaction, cv);
reaction.cv = cv;
}
/**

@ -53,6 +53,7 @@ import {
batch_wvs,
current_batch,
flushSync,
get_cv,
schedule_effect,
set_cv
} from './reactivity/batch.js';
@ -176,7 +177,7 @@ export function is_dirty(reaction) {
return false;
}
var cv = batch_cvs?.get(reaction) ?? reaction.cv;
var cv = get_cv(reaction);
var length = dependencies.length;
@ -454,13 +455,18 @@ export function update_effect(effect) {
destroy_effect_children(effect);
}
set_cv(effect);
// get this now, so that any writes during execution cause a re-run,
// but don't set it yet so that `$inspect.trace` works
const cv = write_version;
execute_effect_teardown(effect);
var teardown = update_reaction(effect);
effect.teardown = typeof teardown === 'function' ? teardown : null;
if (!is_runes()) {
if (is_runes()) {
set_cv(effect, cv);
} else {
// in legacy mode, prevent the effect re-running immediately
set_cv(effect);
}

Loading…
Cancel
Save