Change withActions to only allow mutations

This commit is contained in:
Michael B. Gale
2026-07-29 12:55:16 +01:00
parent 42a3b94790
commit 3ca82bb259
2 changed files with 10 additions and 20 deletions

View File

@@ -228,7 +228,8 @@ type DelayedCheck<
Fs extends ReadonlyArray<AllState[number]>,
> = (env: Readonly<BaseEnvBuilder<Args, R, Fs>>) => Promise<any>;
export type ValueOrMutation<T> = T | ((val: T) => void);
export type Mutation<T> = (val: T) => void;
export type ValueOrMutation<T> = T | Mutation<T>;
/**
* Wraps a function that accepts an `ActionState` for testing in different environments.
@@ -324,13 +325,10 @@ abstract class BaseEnvBuilder<
return result;
}
public withActions(arg: ValueOrMutation<ActionsEnv>): this {
/** Applies `fn` to the `ActionsEnv`. */
public withActions(fn: Mutation<ActionsEnv>): this {
const result = this.clone();
if (typeof arg === "function") {
arg(result.state.actions);
} else {
result.state.actions = arg;
}
fn(result.state.actions);
return result;
}