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

@ -16,11 +16,19 @@ export interface Value<V = unknown> extends Signal {
rv: number; rv: number;
/** The latest value for this signal */ /** The latest value for this signal */
v: V; v: V;
/** Dev only */
// dev-only
/** A label (e.g. the `foo` in `let foo = $state(...)`) used for `$inspect.trace()` */
label?: string; label?: string;
/** An error with a stack trace showing when the source was created */
created?: Error | null; created?: Error | null;
/** An error with a stack trace showing when the source was last updated */
updated?: Error | null; 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 { export interface Reaction extends Signal {

@ -442,18 +442,13 @@ export function update_effect(effect) {
effect.teardown = typeof teardown === 'function' ? teardown : null; effect.teardown = typeof teardown === 'function' ? teardown : null;
effect.wv = write_version; effect.wv = write_version;
var deps = effect.deps; // 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
// In DEV, we need to handle a case where $inspect.trace() might if (DEV && tracing_mode_flag && (effect.f & DIRTY) !== 0 && effect.deps !== null) {
// incorrectly state a source dependency has not changed when it has. for (var dep of effect.deps) {
// That's beacuse that source was changed by the same effect, causing if (dep.set_during_effect) {
// 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) {
dep.wv = increment_write_version(); dep.wv = increment_write_version();
dep.trace_need_increase = undefined; dep.set_during_effect = false;
} }
} }
} }

Loading…
Cancel
Save