Skip to content

Commit 32f45df

Browse files
committed
[form] Rename action combinators
1 parent af345be commit 32f45df

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

packages/form/src/use-action.svelte.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface ActionOptions<T, R, E> {
3737
onSuccess?: (result: R) => void;
3838
onFailure?: (failure: FailedAction<E>) => void;
3939
/**
40-
* @default waitForPrevious
40+
* @default ignoreNewUntilPreviousIsFinished
4141
*/
4242
combinator?: ActionsCombinator<E>;
4343
/**
@@ -51,20 +51,21 @@ export interface ActionOptions<T, R, E> {
5151
}
5252

5353
/**
54-
* Wait for completion of previous action
54+
* Forget previous action
5555
*/
56-
export const waitForPrevious: ActionsCombinator<any> = ({ status }) =>
57-
status <= Status.IDLE;
56+
export const forgetPrevious: ActionsCombinator<any> = () => true;
5857

5958
/**
6059
* Abort previous action
6160
*/
6261
export const abortPrevious: ActionsCombinator<any> = () => "abort";
6362

6463
/**
65-
* Ignore previous action
64+
* Ignore new actions until the previous action is completed
6665
*/
67-
export const ignorePrevious: ActionsCombinator<any> = () => true;
66+
export const ignoreNewUntilPreviousIsFinished: ActionsCombinator<any> = ({
67+
status,
68+
}) => status <= Status.IDLE;
6869

6970
export type ActionRun<T> = T extends undefined | unknown
7071
? (value?: T) => Promise<void>
@@ -86,7 +87,9 @@ export function useAction<T, R, E = unknown>(
8687
): Action<T, R, E> {
8788
const delayedMs = $derived(options.delayedMs ?? 500);
8889
const timeoutMs = $derived(options.timeoutMs ?? 8000);
89-
const combinator = $derived(options.combinator ?? waitForPrevious);
90+
const combinator = $derived(
91+
options.combinator ?? ignoreNewUntilPreviousIsFinished
92+
);
9093

9194
let state = $state<ActionState<E>>({
9295
status: Status.IDLE,

0 commit comments

Comments
 (0)