refactor: pass variable store explicitly to getCombined

Remove the mutable `streamFallback` global state and instead pass the
`VariableStore` as an explicit argument to `getCombined` and related
functions. This ensures correctness by avoiding reliance on mutable
module state during reactivity calculations.
This commit is contained in:
2026-07-13 10:22:22 +08:00
parent c524dd5867
commit 4c2eb65470
2 changed files with 37 additions and 42 deletions
+8 -8
View File
@@ -140,9 +140,9 @@ function dispatchSet(
}
const key = p.key;
// Use getCombined for old value so tag transitions are detected correctly
// even when the variable has active mods.
const oldValue = getCombined(key);
// Use getCombined with stream fallback for old value so tag transitions
// are detected correctly even when the variable has active mods.
const oldValue = getCombined(key, ctx.variables);
let newValue: string;
try {
@@ -158,8 +158,8 @@ function dispatchSet(
const result = evaluateExpression(p.expr, {
lookup: (name: string) => {
const k = "$" + name;
// Use getCombined for accurate values including active mods
return k === key ? undefined : getCombined(k);
// Use getCombined with stream fallback for accurate values
return k === key ? undefined : getCombined(k, ctx.variables);
},
});
newValue = String(result.value);
@@ -192,9 +192,9 @@ function dispatchSet(
}
// Send the direct set last so cascade messages arrive first.
// Use getCombined so the stream store receives the correct value
// (base + active mods) rather than just the raw base.
const combinedValue = getCombined(key);
// Use getCombined with stream fallback so the stream store receives the
// correct value (base + active mods) rather than just the raw base.
const combinedValue = getCombined(key, ctx.variables);
const r1 = sendMessage("var", { action: "set", key, value: combinedValue });
const u1 = unwrap(r1);
if (!u1.ok) return u1;