diff --git a/jsr.json b/jsr.json index a80bfb0401303aaa51b135cb0d179b11c742a46d..0a42e466ab1ab27ce3b75d6b812e4846b2a6e4e8 100644 --- a/jsr.json +++ b/jsr.json @@ -1,6 +1,6 @@ { "name": "@clo/react-mutation", - "version": "1.0.0-beta.13", + "version": "1.0.0-beta.14", "exports": { ".": "./src/mod.ts", "./tanstack-query.ts": "./src/tanstack-query.ts", diff --git a/src/react.ts b/src/react.ts index c9bf18199e23286fc0e5e50c15babf12bd263201..d4c9dc778e19b92576d0cf6be026a3e3bc499db2 100644 --- a/src/react.ts +++ b/src/react.ts @@ -1,5 +1,6 @@ import { message as errMessage } from "@clo/lib/error.ts"; import type { Timer } from "@clo/lib/ts.ts"; +import { isDisabled } from "@testing-library/user-event/dist/cjs/utils/index.js"; import { type FC, type MouseEvent, @@ -46,9 +47,15 @@ export interface UseMutateResultBase { runWithOptions: ( ..._: [...args: Args, options: RunOptions] ) => void; + + /** Unset error and success states */ clear: () => void; + /** Set `error`, useful for input validators or whatever */ setError: (error: unknown) => void; + /** The arguments of the latest mutation call */ args: Args | undefined; + /** `true` when controls should be disabled */ + isDisabled: boolean; } export interface UseMutateSuccess { @@ -89,8 +96,6 @@ export interface UseMutateIdle { result: undefined; error: undefined; errorMessage: undefined; - /** `true` when controls should be disabled */ - isDisabled: boolean; /** `true` when a `mutate` function is currently running. */ isMutating: boolean; /** `true` when a loading indicator should be shown. */ @@ -116,6 +121,7 @@ type AnyMutationStateWithoutRun = isSuccess: boolean; isError: boolean; args: Args | undefined; + isDisabled: boolean; }; export type AnyMutationState = @@ -134,6 +140,7 @@ function initialState() { isError: false, isOptimisticData: false, args: undefined, + isDisabled: true, } as const; } @@ -368,7 +375,7 @@ class Observer { // TODO: when auth drops this will be dependant on the auth status and isMutating get isDisabled() { self.watched.add("isMutating"); - return self.state.isMutating; + return !self.mutation || self.state.isMutating; }, get isPending() { self.watched.add("isPending");