make things a bit more self-explanatory

pull/16131/head
Rich Harris 3 months ago
parent b6a26aeb42
commit d4f81205eb

@ -66,6 +66,8 @@ export function source(v, stack) {
if (DEV && tracing_mode_flag) {
signal.created = stack ?? get_stack('CreatedAt');
signal.updated = null;
signal.set_during_effect = false;
}
return signal;
@ -169,10 +171,7 @@ export function internal_set(source, value) {
source.updated = get_stack('UpdatedAt');
if (active_effect !== null) {
// Signal that we should increment the write version
// after the current effect has run, so that it is
// marked dirty if the effect uses `$inspect.trace()`
source.trace_need_increase = true;
source.set_during_effect = true;
}
}

@ -16,11 +16,19 @@ export interface Value<V = unknown> extends Signal {
rv: number;
/** The latest value for this signal */
v: V;
/** Dev only */
// dev-only
/** A label (e.g. the `foo` in `let foo = $state(...)`) used for `$inspect.trace()` */
label?: string;
/** An error with a stack trace showing when the source was created */
created?: Error | null;
/** An error with a stack trace showing when the source was last updated */
updated?: Error | null;
trace_need_increase?: boolean;
/**
* Whether or not the source was set while running an effect if so, we need to
* increment the write version so that it shows up as dirty when the effect re-runs
*/
set_during_effect?: boolean;
}
export interface Reaction extends Signal {

@ -442,18 +442,13 @@ export function update_effect(effect) {
effect.teardown = typeof teardown === 'function' ? teardown : null;
effect.wv = write_version;
var deps = effect.deps;
// In DEV, we need to handle a case where $inspect.trace() might
// incorrectly state a source dependency has not changed when it has.
// That's beacuse that source was changed by the same effect, causing
// the versions to match. We can avoid this by incrementing the version
if (DEV && tracing_mode_flag && (effect.f & DIRTY) !== 0 && deps !== null) {
for (let i = 0; i < deps.length; i++) {
var dep = deps[i];
if (dep.trace_need_increase) {
// In DEV, increment versions of any sources that were written to during the effect,
// so that they are correctly marked as dirty when the effect re-runs
if (DEV && tracing_mode_flag && (effect.f & DIRTY) !== 0 && effect.deps !== null) {
for (var dep of effect.deps) {
if (dep.set_during_effect) {
dep.wv = increment_write_version();
dep.trace_need_increase = undefined;
dep.set_during_effect = false;
}
}
}

Loading…
Cancel
Save