functype-react 1.27.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -35
- package/dist/AsyncState-zTPspeWC.d.ts +20 -0
- package/dist/async/AsyncState.d.ts +2 -0
- package/dist/async/index.d.ts +7 -10
- package/dist/async/index.js +1 -1
- package/dist/async/index.js.map +1 -1
- package/dist/async/useIO.d.ts +26 -0
- package/dist/async/useIO.js +2 -0
- package/dist/async/useIO.js.map +1 -0
- package/dist/async/useIOPromise.d.ts +14 -0
- package/dist/async/useIOPromise.js +2 -0
- package/dist/async/useIOPromise.js.map +1 -0
- package/dist/async/useIOValue.d.ts +23 -0
- package/dist/async/useIOValue.js +2 -0
- package/dist/async/useIOValue.js.map +1 -0
- package/dist/{eq-CK6oQqWG.d.ts → eq-cYnbruZq.d.ts} +9 -7
- package/dist/forms/Validated.d.ts +1 -4
- package/dist/forms/Validated.js.map +1 -1
- package/dist/forms/index.d.ts +1 -1
- package/dist/forms/index.js +1 -1
- package/dist/forms/useValidatedField.d.ts +3 -6
- package/dist/forms/useValidatedField.js +1 -1
- package/dist/forms/useValidatedField.js.map +1 -1
- package/dist/forms/useValidatedForm.d.ts +3 -6
- package/dist/forms/useValidatedForm.js +1 -1
- package/dist/forms/useValidatedForm.js.map +1 -1
- package/dist/hooks/eq.d.ts +1 -1
- package/dist/hooks/eq.js +1 -1
- package/dist/hooks/eq.js.map +1 -1
- package/dist/hooks/index.d.ts +9 -9
- package/dist/hooks/useEither.d.ts +1 -1
- package/dist/hooks/useEither.js.map +1 -1
- package/dist/hooks/useList.d.ts +1 -1
- package/dist/hooks/useList.js +1 -1
- package/dist/hooks/useList.js.map +1 -1
- package/dist/hooks/useOption.d.ts +1 -1
- package/dist/hooks/useOption.js +1 -1
- package/dist/hooks/useOption.js.map +1 -1
- package/dist/hooks/useStableCallback.d.ts +1 -1
- package/dist/hooks/useStableCallback.js +1 -1
- package/dist/hooks/useStableCallback.js.map +1 -1
- package/dist/hooks/useStableEffect.d.ts +1 -1
- package/dist/hooks/useStableEffect.js +1 -1
- package/dist/hooks/useStableEffect.js.map +1 -1
- package/dist/hooks/useStableMemo.d.ts +1 -1
- package/dist/hooks/useStableMemo.js +1 -1
- package/dist/hooks/useStableMemo.js.map +1 -1
- package/dist/hooks/useStableState.d.ts +1 -1
- package/dist/hooks/useStableState.js +1 -1
- package/dist/hooks/useStableState.js.map +1 -1
- package/dist/hooks/useTry.d.ts +1 -1
- package/dist/hooks/useTry.js +1 -1
- package/dist/hooks/useTry.js.map +1 -1
- package/dist/{index-DjzwkXMF.d.ts → index-Byicsy1U.d.ts} +2 -11
- package/dist/index.d.ts +18 -10
- package/dist/index.js +1 -1
- package/dist/match/index.d.ts +1 -1
- package/dist/match/index.js +1 -1
- package/dist/{match-CkGESkj9.js → match-BnD70A5l.js} +1 -1
- package/dist/match-BnD70A5l.js.map +1 -0
- package/dist/query/IOQueryError.d.ts +1 -4
- package/dist/query/IOQueryError.js +1 -1
- package/dist/query/IOQueryError.js.map +1 -1
- package/dist/query/index.d.ts +18 -0
- package/dist/query/ioQueryFn.d.ts +4 -6
- package/dist/query/ioQueryFn.js +1 -1
- package/dist/query/ioQueryFn.js.map +1 -1
- package/dist/query/queryState.d.ts +11 -15
- package/dist/query/queryState.js.map +1 -1
- package/dist/query/useIOMutation.d.ts +3 -6
- package/dist/query/useIOMutation.js +1 -1
- package/dist/query/useIOMutation.js.map +1 -1
- package/dist/query/useIOMutationState.d.ts +7 -10
- package/dist/query/useIOMutationState.js.map +1 -1
- package/dist/query/useIOQuery.d.ts +3 -6
- package/dist/query/useIOQuery.js +1 -1
- package/dist/query/useIOQuery.js.map +1 -1
- package/dist/query/useIOQueryState.d.ts +8 -11
- package/dist/query/useIOQueryState.js.map +1 -1
- package/dist/{useEither-DyPW7OaA.d.ts → useEither-BveKCnsh.d.ts} +1 -4
- package/dist/{useList-B5Iox1xv.d.ts → useList-B83krQsi.d.ts} +1 -4
- package/dist/{useOption-CXXNC1_S.d.ts → useOption-C1VH3h20.d.ts} +1 -4
- package/dist/{useStableCallback-CXQQOhl6.d.ts → useStableCallback-C4UjxvJ1.d.ts} +2 -5
- package/dist/{useStableEffect-C-5NCd1T.d.ts → useStableEffect-CgkwQ5kY.d.ts} +2 -5
- package/dist/{useStableMemo-PYyLBWwd.d.ts → useStableMemo-KbV23mg-.d.ts} +2 -5
- package/dist/{useStableState-fi6nURHS.d.ts → useStableState-B-AaH7WY.d.ts} +2 -5
- package/dist/{useTry-B0HIcFFb.d.ts → useTry-B9VzXJLg.d.ts} +1 -4
- package/package.json +10 -11
- package/dist/TaskState-DWxGWqXf.d.ts +0 -24
- package/dist/async/TaskState.d.ts +0 -2
- package/dist/async/useTask.d.ts +0 -24
- package/dist/async/useTask.js +0 -2
- package/dist/async/useTask.js.map +0 -1
- package/dist/async/useTaskPromise.d.ts +0 -14
- package/dist/async/useTaskPromise.js +0 -2
- package/dist/async/useTaskPromise.js.map +0 -1
- package/dist/async/useTaskValue.d.ts +0 -24
- package/dist/async/useTaskValue.js +0 -2
- package/dist/async/useTaskValue.js.map +0 -1
- package/dist/match-CkGESkj9.js.map +0 -1
- /package/dist/async/{TaskState.js → AsyncState.js} +0 -0
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UseMutationResult } from "@tanstack/react-query";
|
|
2
|
+
import { IO } from "functype/io";
|
|
3
|
+
import { t as AsyncState } from "../AsyncState-zTPspeWC.js";
|
|
2
4
|
import { IOQueryError } from "./IOQueryError.js";
|
|
3
5
|
import { UseIOMutationOptions } from "./useIOMutation.js";
|
|
4
|
-
import { IO } from "functype/io";
|
|
5
|
-
import { UseMutationResult } from "@tanstack/react-query";
|
|
6
|
-
//#region src/query/useIOMutationState.d.ts
|
|
7
6
|
/**
|
|
8
|
-
* `
|
|
7
|
+
* `AsyncState` plus the flags and the trigger functions. Unlike a query, a mutation is
|
|
9
8
|
* useless without its trigger, so `mutate` / `mutateAsync` / `reset` are carried
|
|
10
9
|
* through with React Query's own signatures.
|
|
11
10
|
*/
|
|
12
|
-
export type UseIOMutationStateResult<A, E, V, TContext> =
|
|
11
|
+
export type UseIOMutationStateResult<A, E, V, TContext> = AsyncState<IOQueryError<E>, A> & Pick<UseMutationResult<A, IOQueryError<E>, V, TContext>, "mutate" | "mutateAsync" | "reset"> & {
|
|
13
12
|
readonly isIdle: boolean;
|
|
14
13
|
readonly isPending: boolean;
|
|
15
14
|
readonly isSuccess: boolean;
|
|
16
15
|
readonly isFailure: boolean;
|
|
17
16
|
};
|
|
18
17
|
/**
|
|
19
|
-
* `useIOMutation` projected onto the `
|
|
18
|
+
* `useIOMutation` projected onto the `AsyncState` ADT, so a mutation's lifecycle matches
|
|
20
19
|
* exhaustively like a query's. React Query's own `idle` status maps directly onto `Idle`.
|
|
21
20
|
*
|
|
22
21
|
* ```tsx
|
|
@@ -34,6 +33,4 @@ export type UseIOMutationStateResult<A, E, V, TContext> = TaskState<IOQueryError
|
|
|
34
33
|
* </Match>
|
|
35
34
|
* ```
|
|
36
35
|
*/
|
|
37
|
-
export declare function useIOMutationState<A, E, V = void, TContext = unknown>(io: (variables: V) => IO<never, E, A>, options?: UseIOMutationOptions<A, E, V, TContext>): UseIOMutationStateResult<A, E, V, TContext>;
|
|
38
|
-
//#endregion
|
|
39
|
-
//# sourceMappingURL=useIOMutationState.d.ts.map
|
|
36
|
+
export declare function useIOMutationState<A, E, V = void, TContext = unknown>(io: (variables: V) => IO<never, E, A>, options?: UseIOMutationOptions<A, E, V, TContext>): UseIOMutationStateResult<A, E, V, TContext>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIOMutationState.js","names":["
|
|
1
|
+
{"version":3,"file":"useIOMutationState.js","names":["toMutationState","useIOMutation","useIOMutationState","io","options","mutation","state"],"sources":["../../src/query/useIOMutationState.ts"],"sourcesContent":["\"use client\"\n\nimport type { UseMutationResult } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { AsyncState } from \"../async/AsyncState\"\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { toMutationState } from \"./queryState\"\nimport type { UseIOMutationOptions } from \"./useIOMutation\"\nimport { useIOMutation } from \"./useIOMutation\"\n\n/**\n * `AsyncState` plus the flags and the trigger functions. Unlike a query, a mutation is\n * useless without its trigger, so `mutate` / `mutateAsync` / `reset` are carried\n * through with React Query's own signatures.\n */\nexport type UseIOMutationStateResult<A, E, V, TContext> = AsyncState<IOQueryError<E>, A> &\n Pick<UseMutationResult<A, IOQueryError<E>, V, TContext>, \"mutate\" | \"mutateAsync\" | \"reset\"> & {\n readonly isIdle: boolean\n readonly isPending: boolean\n readonly isSuccess: boolean\n readonly isFailure: boolean\n }\n\n/**\n * `useIOMutation` projected onto the `AsyncState` ADT, so a mutation's lifecycle matches\n * exhaustively like a query's. React Query's own `idle` status maps directly onto `Idle`.\n *\n * ```tsx\n * const create = useIOMutationState((body: CreateTokenInput) => Http.post<Token>(url, { body }))\n *\n * <button onClick={() => create.mutate({ name: \"ci\" })} disabled={create.isPending}>create</button>\n *\n * <Match value={create}>\n * {{\n * Idle: () => null,\n * Pending: () => <Spinner />,\n * Failure: ({ error }) => <Err e={error.error} />,\n * Success: ({ value }) => <TokenRow token={value} />,\n * }}\n * </Match>\n * ```\n */\nexport function useIOMutationState<A, E, V = void, TContext = unknown>(\n io: (variables: V) => IO<never, E, A>,\n options?: UseIOMutationOptions<A, E, V, TContext>,\n): UseIOMutationStateResult<A, E, V, TContext> {\n const mutation = useIOMutation(io, options)\n const state = toMutationState(mutation)\n\n return {\n ...state,\n isIdle: state._tag === \"Idle\",\n isPending: state._tag === \"Pending\",\n isSuccess: state._tag === \"Success\",\n isFailure: state._tag === \"Failure\",\n mutate: mutation.mutate,\n mutateAsync: mutation.mutateAsync,\n reset: mutation.reset,\n }\n}\n"],"mappings":"A,kHA2CA,SAAgBE,EACdC,EACAC,EAC6C,CAC7C,IAAMC,EAAWJ,EAAcE,EAAIC,CAAO,EACpCE,EAAQN,EAAgBK,CAAQ,EAEtC,MAAO,CACL,GAAGC,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,OAAQD,EAAS,OACjB,YAAaA,EAAS,YACtB,MAAOA,EAAS,KAClB,CACF,C"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { IOQueryError } from "./IOQueryError.js";
|
|
2
|
-
import { IO } from "functype/io";
|
|
3
1
|
import { QueryFunctionContext, QueryKey, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
|
-
|
|
2
|
+
import { IO } from "functype/io";
|
|
3
|
+
import { IOQueryError } from "./IOQueryError.js";
|
|
5
4
|
export type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<UseQueryOptions<A, IOQueryError<E>, TData, TQueryKey>, "queryKey" | "queryFn"> & {
|
|
6
5
|
/** Override the derived `Error.message` on failure. */
|
|
7
6
|
readonly formatError?: (error: E) => string;
|
|
@@ -33,6 +32,4 @@ export type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<Us
|
|
|
33
32
|
* through untouched. For full control over the query object — or for
|
|
34
33
|
* `useSuspenseQuery` / `useInfiniteQuery` — use the `ioQueryFn` primitive directly.
|
|
35
34
|
*/
|
|
36
|
-
export declare function useIOQuery<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>, options?: UseIOQueryOptions<A, E, TData, TQueryKey>): UseQueryResult<TData, IOQueryError<E>>;
|
|
37
|
-
//#endregion
|
|
38
|
-
//# sourceMappingURL=useIOQuery.d.ts.map
|
|
35
|
+
export declare function useIOQuery<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>, options?: UseIOQueryOptions<A, E, TData, TQueryKey>): UseQueryResult<TData, IOQueryError<E>>;
|
package/dist/query/useIOQuery.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{useQuery as e}from"@tanstack/react-query";import{ioQueryFn as t}from"./ioQueryFn.js";function n(n,r,i){let{formatError:a,...o}=i??{};return e({...o,queryKey:n,queryFn:t(r,{formatError:a})})}export{n as useIOQuery};
|
|
2
2
|
//# sourceMappingURL=useIOQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIOQuery.js","names":["useIOQuery","
|
|
1
|
+
{"version":3,"file":"useIOQuery.js","names":["useQuery","ioQueryFn","useIOQuery","queryKey","io","options","formatError","queryOptions"],"sources":["../../src/query/useIOQuery.ts"],"sourcesContent":["\"use client\"\n\nimport type { QueryFunctionContext, QueryKey, UseQueryOptions, UseQueryResult } from \"@tanstack/react-query\"\nimport { useQuery } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { ioQueryFn } from \"./ioQueryFn\"\n\nexport type UseIOQueryOptions<A, E, TData, TQueryKey extends QueryKey> = Omit<\n UseQueryOptions<A, IOQueryError<E>, TData, TQueryKey>,\n \"queryKey\" | \"queryFn\"\n> & {\n /** Override the derived `Error.message` on failure. */\n readonly formatError?: (error: E) => string\n}\n\n/**\n * `useQuery` for effects — runs an `IO<never, E, A>` and threads its typed error channel\n * through to React Query's `error`.\n *\n * The failure is boxed as `IOQueryError<E>`, so `error instanceof Error` and\n * `error.message` behave normally while `error.error` stays fully discriminable:\n *\n * ```ts\n * const { data, error } = useIOQuery(\n * [\"connector-limits\", userId],\n * ({ signal }) => Http.get<Limits>(url, { headers, signal }),\n * { enabled: !!userId },\n * )\n *\n * if (error) {\n * HttpErrors.match(error.error, {\n * NetworkError: () => <Offline />,\n * HttpStatusError: (e) => (e.status === 403 ? <UpgradePrompt /> : <Failed />),\n * DecodeError: () => <SchemaDrift />,\n * })\n * }\n * ```\n *\n * Every other `useQuery` option (`select`, `staleTime`, `placeholderData`, …) passes\n * through untouched. For full control over the query object — or for\n * `useSuspenseQuery` / `useInfiniteQuery` — use the `ioQueryFn` primitive directly.\n */\nexport function useIOQuery<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>,\n options?: UseIOQueryOptions<A, E, TData, TQueryKey>,\n): UseQueryResult<TData, IOQueryError<E>> {\n const { formatError, ...queryOptions } = options ?? {}\n\n return useQuery<A, IOQueryError<E>, TData, TQueryKey>({\n ...queryOptions,\n queryKey,\n queryFn: ioQueryFn<E, A, QueryFunctionContext<TQueryKey>>(io, { formatError }),\n })\n}\n"],"mappings":"A,yGA4CA,SAAgBE,EACdC,EACAC,EACAC,EACwC,CACxC,GAAM,CAAEC,cAAa,GAAGC,GAAiBF,GAAW,CAAC,EAErD,OAAOL,EAA+C,CACpD,GAAGO,EACHJ,WACA,QAASF,EAAiDG,EAAI,CAAEE,aAAY,CAAC,CAC/E,CAAC,CACH,C"}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { QueryFunctionContext, QueryKey, UseQueryResult } from "@tanstack/react-query";
|
|
2
|
+
import { IO } from "functype/io";
|
|
3
|
+
import { t as AsyncState } from "../AsyncState-zTPspeWC.js";
|
|
2
4
|
import { IOQueryError } from "./IOQueryError.js";
|
|
3
5
|
import { UseIOQueryOptions } from "./useIOQuery.js";
|
|
4
|
-
import { IO } from "functype/io";
|
|
5
|
-
import { QueryFunctionContext, QueryKey, UseQueryResult } from "@tanstack/react-query";
|
|
6
|
-
//#region src/query/useIOQueryState.d.ts
|
|
7
6
|
/**
|
|
8
|
-
* `
|
|
9
|
-
* `
|
|
7
|
+
* `AsyncState` plus the convenience flags and refetch trigger, mirroring
|
|
8
|
+
* `UseIOResult` from `functype-react/async` so both async surfaces read alike.
|
|
10
9
|
*
|
|
11
10
|
* `refetch` keeps React Query's own signature rather than a lossy re-declaration.
|
|
12
11
|
*/
|
|
13
|
-
export type UseIOQueryStateResult<A, E> =
|
|
12
|
+
export type UseIOQueryStateResult<A, E> = AsyncState<IOQueryError<E>, A> & Pick<UseQueryResult<A, IOQueryError<E>>, "refetch"> & {
|
|
14
13
|
readonly isIdle: boolean;
|
|
15
14
|
readonly isPending: boolean;
|
|
16
15
|
readonly isSuccess: boolean;
|
|
17
16
|
readonly isFailure: boolean;
|
|
18
17
|
};
|
|
19
18
|
/**
|
|
20
|
-
* `useIOQuery` projected straight onto the `
|
|
19
|
+
* `useIOQuery` projected straight onto the `AsyncState` ADT — the flag-soup-free path
|
|
21
20
|
* in one call.
|
|
22
21
|
*
|
|
23
22
|
* ```tsx
|
|
@@ -39,6 +38,4 @@ export type UseIOQueryStateResult<A, E> = TaskState<IOQueryError<E>, A> & Pick<U
|
|
|
39
38
|
* (`isFetching`, `dataUpdatedAt`, `failureCount`), use {@link useIOQuery} with
|
|
40
39
|
* {@link toQueryState} instead.
|
|
41
40
|
*/
|
|
42
|
-
export declare function useIOQueryState<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>, options?: UseIOQueryOptions<A, E, TData, TQueryKey>): UseIOQueryStateResult<TData, E>;
|
|
43
|
-
//#endregion
|
|
44
|
-
//# sourceMappingURL=useIOQueryState.d.ts.map
|
|
41
|
+
export declare function useIOQueryState<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>, options?: UseIOQueryOptions<A, E, TData, TQueryKey>): UseIOQueryStateResult<TData, E>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIOQueryState.js","names":["
|
|
1
|
+
{"version":3,"file":"useIOQueryState.js","names":["toQueryState","useIOQuery","useIOQueryState","queryKey","io","options","query","state"],"sources":["../../src/query/useIOQueryState.ts"],"sourcesContent":["\"use client\"\n\nimport type { QueryFunctionContext, QueryKey, UseQueryResult } from \"@tanstack/react-query\"\nimport type { IO } from \"functype/io\"\n\nimport type { AsyncState } from \"../async/AsyncState\"\nimport type { IOQueryError } from \"./IOQueryError\"\nimport { toQueryState } from \"./queryState\"\nimport type { UseIOQueryOptions } from \"./useIOQuery\"\nimport { useIOQuery } from \"./useIOQuery\"\n\n/**\n * `AsyncState` plus the convenience flags and refetch trigger, mirroring\n * `UseIOResult` from `functype-react/async` so both async surfaces read alike.\n *\n * `refetch` keeps React Query's own signature rather than a lossy re-declaration.\n */\nexport type UseIOQueryStateResult<A, E> = AsyncState<IOQueryError<E>, A> &\n Pick<UseQueryResult<A, IOQueryError<E>>, \"refetch\"> & {\n readonly isIdle: boolean\n readonly isPending: boolean\n readonly isSuccess: boolean\n readonly isFailure: boolean\n }\n\n/**\n * `useIOQuery` projected straight onto the `AsyncState` ADT — the flag-soup-free path\n * in one call.\n *\n * ```tsx\n * const user = useIOQueryState([\"user\", id], ({ signal }) => Http.get<User>(url, { signal }))\n *\n * <Match value={user}>\n * {{\n * Idle: () => null,\n * Pending: () => <Spinner />,\n * Failure: ({ error }) => <Err e={error.error} />,\n * Success: ({ value }) => <Profile user={value} />,\n * }}\n * </Match>\n * ```\n *\n * Reads only `status` / `fetchStatus` / `data` / `error` / `refetch` off the query, so\n * React Query's tracked-properties optimization still applies — the component is not\n * subscribed to fields it never renders. When you need the rest of the result\n * (`isFetching`, `dataUpdatedAt`, `failureCount`), use {@link useIOQuery} with\n * {@link toQueryState} instead.\n */\nexport function useIOQueryState<A, E, TData = A, TQueryKey extends QueryKey = QueryKey>(\n queryKey: TQueryKey,\n io: (context: QueryFunctionContext<TQueryKey>) => IO<never, E, A>,\n options?: UseIOQueryOptions<A, E, TData, TQueryKey>,\n): UseIOQueryStateResult<TData, E> {\n const query = useIOQuery(queryKey, io, options)\n const state = toQueryState(query)\n\n return {\n ...state,\n isIdle: state._tag === \"Idle\",\n isPending: state._tag === \"Pending\",\n isSuccess: state._tag === \"Success\",\n isFailure: state._tag === \"Failure\",\n refetch: query.refetch,\n }\n}\n"],"mappings":"A,yGAgDA,SAAgBE,EACdC,EACAC,EACAC,EACiC,CACjC,IAAMC,EAAQL,EAAWE,EAAUC,EAAIC,CAAO,EACxCE,EAAQP,EAAaM,CAAK,EAEhC,MAAO,CACL,GAAGC,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,QAASD,EAAM,OACjB,CACF,C"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Either } from "functype/either";
|
|
2
|
-
//#region src/hooks/useEither.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Stateful Either container. Defaults to Left(undefined) when no initial.
|
|
5
4
|
*/
|
|
@@ -9,6 +8,4 @@ declare function useEither<E, A>(initial?: Either<E, A>): {
|
|
|
9
8
|
setLeft: (e: E) => void;
|
|
10
9
|
fold: <R>(onLeft: (e: E) => R, onRight: (a: A) => R) => R;
|
|
11
10
|
};
|
|
12
|
-
|
|
13
|
-
export { useEither as t };
|
|
14
|
-
//# sourceMappingURL=useEither-DyPW7OaA.d.ts.map
|
|
11
|
+
export { useEither as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { List } from "functype/list";
|
|
2
|
-
//#region src/hooks/useList.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Stateful immutable List container. All mutators return new state.
|
|
5
4
|
*/
|
|
@@ -12,6 +11,4 @@ declare function useList<A>(initial?: readonly A[]): {
|
|
|
12
11
|
map: <B>(f: (a: A) => B) => List<B>;
|
|
13
12
|
filter: (p: (a: A) => boolean) => List<A>;
|
|
14
13
|
};
|
|
15
|
-
|
|
16
|
-
export { useList as t };
|
|
17
|
-
//# sourceMappingURL=useList-B5Iox1xv.d.ts.map
|
|
14
|
+
export { useList as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Option } from "functype/option";
|
|
2
|
-
//#region src/hooks/useOption.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Stateful Option container. `set(null | undefined)` clears to None.
|
|
5
4
|
*
|
|
@@ -12,6 +11,4 @@ declare function useOption<A>(initial?: A): {
|
|
|
12
11
|
map: <B>(f: (a: A) => B) => Option<B>;
|
|
13
12
|
fold: <R>(onNone: () => R, onSome: (a: A) => R) => R;
|
|
14
13
|
};
|
|
15
|
-
|
|
16
|
-
export { useOption as t };
|
|
17
|
-
//# sourceMappingURL=useOption-CXXNC1_S.d.ts.map
|
|
14
|
+
export { useOption as t };
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
1
|
import { DependencyList } from "react";
|
|
3
|
-
|
|
2
|
+
import { t as Eq } from "./eq-cYnbruZq.js";
|
|
4
3
|
/**
|
|
5
4
|
* Like `useCallback`, but only returns a new function when *some* dep has
|
|
6
5
|
* changed under the supplied (or default) comparator.
|
|
7
6
|
*/
|
|
8
7
|
declare function useStableCallback<F extends (...args: never[]) => unknown>(callback: F, deps: DependencyList, eqs?: ReadonlyArray<Eq<unknown> | undefined>): F;
|
|
9
|
-
|
|
10
|
-
export { useStableCallback as t };
|
|
11
|
-
//# sourceMappingURL=useStableCallback-CXQQOhl6.d.ts.map
|
|
8
|
+
export { useStableCallback as t };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
1
|
import { DependencyList, EffectCallback } from "react";
|
|
3
|
-
|
|
2
|
+
import { t as Eq } from "./eq-cYnbruZq.js";
|
|
4
3
|
/**
|
|
5
4
|
* Like `useEffect`, but re-runs only when *some* dep has changed under the
|
|
6
5
|
* supplied (or default) comparator. The `eqs` array is aligned positionally
|
|
@@ -10,6 +9,4 @@ import { DependencyList, EffectCallback } from "react";
|
|
|
10
9
|
* structural identity is what matters, but whose references churn every render.
|
|
11
10
|
*/
|
|
12
11
|
declare function useStableEffect(effect: EffectCallback, deps: DependencyList, eqs?: ReadonlyArray<Eq<unknown> | undefined>): void;
|
|
13
|
-
|
|
14
|
-
export { useStableEffect as t };
|
|
15
|
-
//# sourceMappingURL=useStableEffect-C-5NCd1T.d.ts.map
|
|
12
|
+
export { useStableEffect as t };
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
2
1
|
import { DependencyList } from "react";
|
|
3
|
-
|
|
2
|
+
import { t as Eq } from "./eq-cYnbruZq.js";
|
|
4
3
|
/**
|
|
5
4
|
* Like `useMemo`, but recomputes only when *some* dep has changed under the
|
|
6
5
|
* supplied (or default) comparator. The `eqs` array is aligned positionally
|
|
7
6
|
* with `deps`; missing entries fall back to `referenceEq`.
|
|
8
7
|
*/
|
|
9
8
|
declare function useStableMemo<A>(factory: () => A, deps: DependencyList, eqs?: ReadonlyArray<Eq<unknown> | undefined>): A;
|
|
10
|
-
|
|
11
|
-
export { useStableMemo as t };
|
|
12
|
-
//# sourceMappingURL=useStableMemo-PYyLBWwd.d.ts.map
|
|
9
|
+
export { useStableMemo as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as Eq } from "./eq-
|
|
2
|
-
//#region src/hooks/useStableState.d.ts
|
|
1
|
+
import { t as Eq } from "./eq-cYnbruZq.js";
|
|
3
2
|
/**
|
|
4
3
|
* Drop-in replacement for `useState` that no-ops when the next value is equal
|
|
5
4
|
* to the current under `eq`. Defaults to `Object.is` (React's built-in), so the
|
|
@@ -9,6 +8,4 @@ import { t as Eq } from "./eq-CK6oQqWG.js";
|
|
|
9
8
|
* @param eq - Comparator used to decide whether to skip the update
|
|
10
9
|
*/
|
|
11
10
|
declare function useStableState<A>(initial: A | (() => A), eq?: Eq<A>): readonly [A, (next: A | ((prev: A) => A)) => void];
|
|
12
|
-
|
|
13
|
-
export { useStableState as t };
|
|
14
|
-
//# sourceMappingURL=useStableState-fi6nURHS.d.ts.map
|
|
11
|
+
export { useStableState as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Try } from "functype/try";
|
|
2
|
-
//#region src/hooks/useTry.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Stateful Try container. Defaults to Failure(new Error("uninitialized")) when no initial.
|
|
5
4
|
*/
|
|
@@ -9,6 +8,4 @@ declare function useTry<A>(initial?: Try<A>): {
|
|
|
9
8
|
setFailure: (e: Error) => void;
|
|
10
9
|
fold: <R>(onFailure: (e: Error) => R, onSuccess: (a: A) => R) => R;
|
|
11
10
|
};
|
|
12
|
-
|
|
13
|
-
export { useTry as t };
|
|
14
|
-
//# sourceMappingURL=useTry-B0HIcFFb.d.ts.map
|
|
11
|
+
export { useTry as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functype-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "React bindings for functype — ADT-aware hooks and exhaustive pattern matching components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"functype",
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"adt",
|
|
11
11
|
"option",
|
|
12
12
|
"either",
|
|
13
|
-
"task",
|
|
14
13
|
"typescript",
|
|
15
14
|
"functional"
|
|
16
15
|
],
|
|
@@ -27,7 +26,7 @@
|
|
|
27
26
|
},
|
|
28
27
|
"peerDependencies": {
|
|
29
28
|
"@tanstack/react-query": ">=5.0.0",
|
|
30
|
-
"functype": ">=0.
|
|
29
|
+
"functype": ">=2.0.0",
|
|
31
30
|
"react": ">=18.0.0 <20.0.0",
|
|
32
31
|
"react-dom": ">=18.0.0 <20.0.0"
|
|
33
32
|
},
|
|
@@ -40,20 +39,20 @@
|
|
|
40
39
|
}
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
|
-
"@tanstack/react-query": "^5.
|
|
42
|
+
"@tanstack/react-query": "^5.107.1",
|
|
44
43
|
"@testing-library/dom": "^10.4.2",
|
|
45
44
|
"@testing-library/jest-dom": "^7.0.1",
|
|
46
45
|
"@testing-library/react": "^16.3.3",
|
|
47
|
-
"@types/node": "^24.19.
|
|
46
|
+
"@types/node": "^24.19.2",
|
|
48
47
|
"@types/react": "^19.3.0",
|
|
49
48
|
"@types/react-dom": "^19.3.0",
|
|
50
49
|
"fast-check": "^4.10.2",
|
|
51
|
-
"functype": "^1.
|
|
52
|
-
"jsdom": "^
|
|
53
|
-
"react": "^19.3.
|
|
54
|
-
"react-dom": "^19.3.
|
|
55
|
-
"ts-builds": "^
|
|
56
|
-
"tsdown": "^0.23.
|
|
50
|
+
"functype": "^2.1.0",
|
|
51
|
+
"jsdom": "^31.0.1",
|
|
52
|
+
"react": "^19.3.1",
|
|
53
|
+
"react-dom": "^19.3.1",
|
|
54
|
+
"ts-builds": "^5.0.0",
|
|
55
|
+
"tsdown": "^0.23.7"
|
|
57
56
|
},
|
|
58
57
|
"type": "module",
|
|
59
58
|
"main": "./dist/index.js",
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//#region src/async/TaskState.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Lifecycle state of an async operation managed by `useTask`.
|
|
4
|
-
*
|
|
5
|
-
* Note: the tag values are `Idle | Pending | Success | Failure` — these are
|
|
6
|
-
* the consumer-facing lifecycle phases, intentionally broader than functype
|
|
7
|
-
* core's `TaskOutcome<T>` (which has only `Ok | Err`). The hook maps
|
|
8
|
-
* `TaskOutcome.Ok → Success`, `TaskOutcome.Err → Failure`, and adds `Idle`
|
|
9
|
-
* (pre-mount) and `Pending` (in flight) for the rendering side.
|
|
10
|
-
*/
|
|
11
|
-
type TaskState<E, A> = {
|
|
12
|
-
readonly _tag: "Idle";
|
|
13
|
-
} | {
|
|
14
|
-
readonly _tag: "Pending";
|
|
15
|
-
} | {
|
|
16
|
-
readonly _tag: "Success";
|
|
17
|
-
readonly value: A;
|
|
18
|
-
} | {
|
|
19
|
-
readonly _tag: "Failure";
|
|
20
|
-
readonly error: E;
|
|
21
|
-
};
|
|
22
|
-
//#endregion
|
|
23
|
-
export { TaskState as t };
|
|
24
|
-
//# sourceMappingURL=TaskState-DWxGWqXf.d.ts.map
|
package/dist/async/useTask.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { t as TaskState } from "../TaskState-DWxGWqXf.js";
|
|
2
|
-
import { Throwable } from "functype";
|
|
3
|
-
//#region src/async/useTask.d.ts
|
|
4
|
-
export type UseTaskResult<E, A> = TaskState<E, A> & {
|
|
5
|
-
readonly isIdle: boolean;
|
|
6
|
-
readonly isPending: boolean;
|
|
7
|
-
readonly isSuccess: boolean;
|
|
8
|
-
readonly isFailure: boolean;
|
|
9
|
-
refetch: () => void;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Run an async operation tied to a React component's lifecycle.
|
|
13
|
-
*
|
|
14
|
-
* - Returns a discriminated `TaskState<Throwable, A>` plus boolean flags and
|
|
15
|
-
* a `refetch` trigger.
|
|
16
|
-
* - The `task` callback receives an `AbortSignal` wired to a cancellation
|
|
17
|
-
* token that fires when the component unmounts or `deps` change. Pass the
|
|
18
|
-
* signal to `fetch` (or any abortable API) to cancel in-flight work.
|
|
19
|
-
* - StrictMode-safe: the cleanup fn cancels the token and discards any
|
|
20
|
-
* late-arriving result.
|
|
21
|
-
*/
|
|
22
|
-
export declare function useTask<A>(task: (signal: AbortSignal) => Promise<A> | A, deps: ReadonlyArray<unknown>): UseTaskResult<Throwable, A>;
|
|
23
|
-
//#endregion
|
|
24
|
-
//# sourceMappingURL=useTask.d.ts.map
|
package/dist/async/useTask.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";import{useCallback as e,useEffect as t,useReducer as n,useRef as r}from"react";import{Task as i,createCancellationTokenSource as a}from"functype";function o(e,t){return t.type===`PENDING`?{_tag:`Pending`}:t.type===`SUCCESS`?{_tag:`Success`,value:t.value}:{_tag:`Failure`,error:t.error}}function s(s,c){let[l,u]=n(o,{_tag:`Idle`}),[d,f]=n(e=>e+1,0),p=r(s);p.current=s,t(()=>{let e={value:!1},t=a();return u({type:`PENDING`}),i().Async(()=>p.current(t.token.signal),void 0,void 0,t.token).then(t=>{e.value||(t.isOk()?u({type:`SUCCESS`,value:t.value}):u({type:`FAILURE`,error:t.error}))}),()=>{e.value=!0,t.cancel()}},[...c,d]);let m=e(()=>f(),[]);return{...l,isIdle:l._tag===`Idle`,isPending:l._tag===`Pending`,isSuccess:l._tag===`Success`,isFailure:l._tag===`Failure`,refetch:m}}export{s as useTask};
|
|
2
|
-
//# sourceMappingURL=useTask.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTask.js","names":["reducer","action","useTask","state","dispatch","useReducer","refetchTick","forceRefetch","n","taskRef","useRef","task","useEffect","cancelled","tokenSource","createCancellationTokenSource","Task","outcome","deps","refetch","useCallback"],"sources":["../../src/async/useTask.ts"],"sourcesContent":["\"use client\"\n\nimport { createCancellationTokenSource, Task, type Throwable } from \"functype\"\nimport { useCallback, useEffect, useReducer, useRef } from \"react\"\n\nimport type { TaskState } from \"./TaskState\"\n\ntype Action<E, A> =\n | { readonly type: \"PENDING\" }\n | { readonly type: \"SUCCESS\"; readonly value: A }\n | { readonly type: \"FAILURE\"; readonly error: E }\n\nfunction reducer<E, A>(_state: TaskState<E, A>, action: Action<E, A>): TaskState<E, A> {\n if (action.type === \"PENDING\") return { _tag: \"Pending\" }\n if (action.type === \"SUCCESS\") return { _tag: \"Success\", value: action.value }\n return { _tag: \"Failure\", error: action.error }\n}\n\nexport type UseTaskResult<E, A> = TaskState<E, A> & {\n readonly isIdle: boolean\n readonly isPending: boolean\n readonly isSuccess: boolean\n readonly isFailure: boolean\n refetch: () => void\n}\n\n/**\n * Run an async operation tied to a React component's lifecycle.\n *\n * - Returns a discriminated `TaskState<Throwable, A>` plus boolean flags and\n * a `refetch` trigger.\n * - The `task` callback receives an `AbortSignal` wired to a cancellation\n * token that fires when the component unmounts or `deps` change. Pass the\n * signal to `fetch` (or any abortable API) to cancel in-flight work.\n * - StrictMode-safe: the cleanup fn cancels the token and discards any\n * late-arriving result.\n */\nexport function useTask<A>(\n task: (signal: AbortSignal) => Promise<A> | A,\n deps: ReadonlyArray<unknown>,\n): UseTaskResult<Throwable, A> {\n const [state, dispatch] = useReducer(reducer<Throwable, A>, { _tag: \"Idle\" })\n const [refetchTick, forceRefetch] = useReducer((n: number) => n + 1, 0)\n const taskRef = useRef(task)\n taskRef.current = task\n\n useEffect(() => {\n const cancelled = { value: false }\n const tokenSource = createCancellationTokenSource()\n dispatch({ type: \"PENDING\" })\n\n void Task<A>()\n .Async<A>(() => taskRef.current(tokenSource.token.signal) as Promise<A>, undefined, undefined, tokenSource.token)\n .then((outcome) => {\n if (cancelled.value) return\n if (outcome.isOk()) {\n dispatch({ type: \"SUCCESS\", value: outcome.value as A })\n } else {\n dispatch({ type: \"FAILURE\", error: outcome.error as Throwable })\n }\n })\n\n return () => {\n cancelled.value = true\n tokenSource.cancel()\n }\n }, [...deps, refetchTick])\n\n const refetch = useCallback(() => forceRefetch(), [])\n\n return {\n ...state,\n isIdle: state._tag === \"Idle\",\n isPending: state._tag === \"Pending\",\n isSuccess: state._tag === \"Success\",\n isFailure: state._tag === \"Failure\",\n refetch,\n }\n}\n"],"mappings":"+JAYA,SAASA,EAAc,EAAyB,EAAuC,CAGrF,OAFIC,EAAO,OAAS,UAAkB,CAAE,KAAM,SAAU,EACpDA,EAAO,OAAS,UAAkB,CAAE,KAAM,UAAW,MAAOA,EAAO,KAAM,EACtE,CAAE,KAAM,UAAW,MAAOA,EAAO,KAAM,CAChD,CAqBA,SAAgBC,EACd,EACA,EAC6B,CAC7B,GAAM,CAACC,EAAOC,GAAYC,EAAWL,EAAuB,CAAE,KAAM,MAAO,CAAC,EACtE,CAACM,EAAaC,GAAgBF,EAAY,GAAcG,EAAI,EAAG,CAAC,EAChEC,EAAUC,EAAOC,CAAI,EAC3B,EAAQ,QAAUA,EAElBC,MAAgB,CACd,IAAMC,EAAY,CAAE,MAAO,EAAM,EAC3BC,EAAcC,EAA8B,EAclD,OAbAX,EAAS,CAAE,KAAM,SAAU,CAAC,EAE5BY,EAAa,CAAC,CACX,UAAeP,EAAQ,QAAQK,EAAY,MAAM,MAAM,EAAiB,IAAA,GAAW,IAAA,GAAWA,EAAY,KAAK,CAAC,CAChH,KAAM,GAAY,CACbD,EAAU,QACVI,EAAQ,KAAK,EACfb,EAAS,CAAE,KAAM,UAAW,MAAOa,EAAQ,KAAW,CAAC,EAEvDb,EAAS,CAAE,KAAM,UAAW,MAAOa,EAAQ,KAAmB,CAAC,EAEnE,CAAC,MAEU,CACX,EAAU,MAAQ,GAClBH,EAAY,OAAO,CACrB,CACF,EAAG,CAAC,GAAGI,EAAMZ,CAAW,CAAC,EAEzB,IAAMa,EAAUC,MAAkBb,EAAa,EAAG,CAAC,CAAC,EAEpD,MAAO,CACL,GAAGJ,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,SACF,CACF"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { TaskOutcome } from "functype";
|
|
2
|
-
//#region src/async/useTaskPromise.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Returns a `Promise<TaskOutcome<A>>` that is stable across renders with the
|
|
5
|
-
* same `deps`. Intended for consumers of React 19's `use()` hook — providing
|
|
6
|
-
* a new promise reference on each render would infinite-suspend.
|
|
7
|
-
*
|
|
8
|
-
* The `task` callback is read through a ref, so the latest closure is invoked
|
|
9
|
-
* even if it isn't included in `deps`. Encode in `deps` whatever semantically
|
|
10
|
-
* changes the task's result.
|
|
11
|
-
*/
|
|
12
|
-
export declare function useTaskPromise<A>(task: (signal: AbortSignal) => Promise<A> | A, deps: ReadonlyArray<unknown>): Promise<TaskOutcome<A>>;
|
|
13
|
-
//#endregion
|
|
14
|
-
//# sourceMappingURL=useTaskPromise.d.ts.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";import{useMemo as e,useRef as t}from"react";import{Task as n,createCancellationTokenSource as r}from"functype";function i(i,a){let o=t(i);return o.current=i,e(()=>{let e=r();return n().Async(()=>o.current(e.token.signal),void 0,void 0,e.token)},a)}export{i as useTaskPromise};
|
|
2
|
-
//# sourceMappingURL=useTaskPromise.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTaskPromise.js","names":["useTaskPromise","taskRef","useRef","task","useMemo","tokenSource","createCancellationTokenSource","Task","deps"],"sources":["../../src/async/useTaskPromise.ts"],"sourcesContent":["\"use client\"\n\nimport { createCancellationTokenSource, Task, type TaskOutcome } from \"functype\"\nimport { useMemo, useRef } from \"react\"\n\n/**\n * Returns a `Promise<TaskOutcome<A>>` that is stable across renders with the\n * same `deps`. Intended for consumers of React 19's `use()` hook — providing\n * a new promise reference on each render would infinite-suspend.\n *\n * The `task` callback is read through a ref, so the latest closure is invoked\n * even if it isn't included in `deps`. Encode in `deps` whatever semantically\n * changes the task's result.\n */\nexport function useTaskPromise<A>(\n task: (signal: AbortSignal) => Promise<A> | A,\n deps: ReadonlyArray<unknown>,\n): Promise<TaskOutcome<A>> {\n const taskRef = useRef(task)\n taskRef.current = task\n\n return useMemo(() => {\n const tokenSource = createCancellationTokenSource()\n return Task<A>().Async<A>(\n () => taskRef.current(tokenSource.token.signal) as Promise<A>,\n undefined,\n undefined,\n tokenSource.token,\n )\n }, deps)\n}\n"],"mappings":"4HAcA,SAAgBA,EACd,EACA,EACyB,CACzB,IAAMC,EAAUC,EAAOC,CAAI,EAG3B,MAFA,GAAQ,QAAUA,EAEXC,MAAc,CACnB,IAAMC,EAAcC,EAA8B,EAClD,OAAOC,EAAQ,CAAC,CAAC,UACTN,EAAQ,QAAQI,EAAY,MAAM,MAAM,EAC9C,IAAA,GACA,IAAA,GACAA,EAAY,KACd,CACF,EAAGG,CAAI,CACT"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//#region src/async/useTaskValue.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Suspense-aware variant of `useTask` for React 19+. Suspends the component
|
|
4
|
-
* while the task is pending and throws on failure — both behaviors integrate
|
|
5
|
-
* with `<TaskBoundary>` (or a hand-rolled Suspense + ErrorBoundary pair).
|
|
6
|
-
*
|
|
7
|
-
* Invariants enforced by React 19:
|
|
8
|
-
* 1. The promise must be stable across renders. `useTaskPromise` memoizes by
|
|
9
|
-
* `deps`, so passing the same deps yields the same promise.
|
|
10
|
-
* 2. An ErrorBoundary must wrap the Suspense, never the reverse — otherwise
|
|
11
|
-
* Suspense will catch the thrown error instead of the boundary.
|
|
12
|
-
* 3. Do not call this on the server. Pass the underlying `Task` (or its
|
|
13
|
-
* promise) into a Client Component and call `useTaskValue` there.
|
|
14
|
-
*
|
|
15
|
-
* @interop React's `use()` reaches the nearest ErrorBoundary only through a throw, not an Either return.
|
|
16
|
-
*
|
|
17
|
-
* Testing note: React 19's `use()` does not unsuspend reliably under jsdom +
|
|
18
|
-
* @testing-library/react. End-to-end tests of `useTaskValue` + `<TaskBoundary>`
|
|
19
|
-
* require a real browser scheduler (Playwright); unit tests of `useTask` and
|
|
20
|
-
* `useTaskPromise` cover the Task plumbing.
|
|
21
|
-
*/
|
|
22
|
-
export declare function useTaskValue<A>(task: (signal: AbortSignal) => Promise<A> | A, deps: ReadonlyArray<unknown>): A;
|
|
23
|
-
//#endregion
|
|
24
|
-
//# sourceMappingURL=useTaskValue.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTaskValue.js","names":["useTaskValue","outcome","use","useTaskPromise","task","deps"],"sources":["../../src/async/useTaskValue.ts"],"sourcesContent":["\"use client\"\n\nimport { use } from \"react\"\n\nimport { useTaskPromise } from \"./useTaskPromise\"\n\n/**\n * Suspense-aware variant of `useTask` for React 19+. Suspends the component\n * while the task is pending and throws on failure — both behaviors integrate\n * with `<TaskBoundary>` (or a hand-rolled Suspense + ErrorBoundary pair).\n *\n * Invariants enforced by React 19:\n * 1. The promise must be stable across renders. `useTaskPromise` memoizes by\n * `deps`, so passing the same deps yields the same promise.\n * 2. An ErrorBoundary must wrap the Suspense, never the reverse — otherwise\n * Suspense will catch the thrown error instead of the boundary.\n * 3. Do not call this on the server. Pass the underlying `Task` (or its\n * promise) into a Client Component and call `useTaskValue` there.\n *\n * @interop React's `use()` reaches the nearest ErrorBoundary only through a throw, not an Either return.\n *\n * Testing note: React 19's `use()` does not unsuspend reliably under jsdom +\n * @testing-library/react. End-to-end tests of `useTaskValue` + `<TaskBoundary>`\n * require a real browser scheduler (Playwright); unit tests of `useTask` and\n * `useTaskPromise` cover the Task plumbing.\n */\nexport function useTaskValue<A>(task: (signal: AbortSignal) => Promise<A> | A, deps: ReadonlyArray<unknown>): A {\n const outcome = use(useTaskPromise(task, deps))\n if (outcome.isErr()) {\n throw outcome.error\n }\n return outcome.value as A\n}\n"],"mappings":"8FA0BA,SAAgBA,EAAgB,EAA+C,EAAiC,CAC9G,IAAMC,EAAUC,EAAIC,EAAeC,EAAMC,CAAI,CAAC,EAC9C,GAAIJ,EAAQ,MAAM,EAChB,MAAMA,EAAQ,MAEhB,OAAOA,EAAQ,KACjB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"match-CkGESkj9.js","names":["Match","handler","props","Fragment","MatchEither","MatchOption","MatchTry"],"sources":["../src/match/Match.tsx","../src/match/MatchEither.tsx","../src/match/MatchOption.tsx","../src/match/MatchTry.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Maps each `_tag` literal to a handler that receives the narrowed variant.\n *\n * TypeScript enforces exhaustiveness: omitting a case from `children` is a\n * compile error.\n */\nexport type MatchCases<U extends { _tag: string }> = {\n readonly [K in U[\"_tag\"]]: (value: Extract<U, { readonly _tag: K }>) => ReactNode\n}\n\n/**\n * Generic discriminated-union matcher for ADTs that follow functype's `_tag`\n * convention. Pass a value and a record of handlers keyed on each tag; the\n * matching handler is invoked with the narrowed variant.\n *\n * ```tsx\n * <Match value={state}>\n * {{\n * Loading: () => <Spinner />,\n * Success: ({ data }) => <Result data={data} />,\n * Failure: ({ error }) => <Err err={error} />,\n * }}\n * </Match>\n * ```\n */\nexport function Match<U extends { _tag: string }>(props: {\n readonly value: U\n readonly children: MatchCases<U>\n}): ReactElement {\n const handler = props.children[props.value._tag as U[\"_tag\"]] as (value: U) => ReactNode\n return <>{handler(props.value)}</>\n}\n","import type { Either } from \"functype/either\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Either<L, R>`.\n */\nexport function MatchEither<L, R>(props: {\n readonly value: Either<L, R>\n readonly Left: (l: L) => ReactNode\n readonly Right: (r: R) => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.Left, props.Right)}</>\n}\n","import type { Option } from \"functype/option\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Option<A>`. Renders `Some(a)` to the\n * `Some` handler and `None` to the `None` handler.\n */\nexport function MatchOption<A>(props: {\n readonly value: Option<A>\n readonly Some: (a: A) => ReactNode\n readonly None: () => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.None, props.Some)}</>\n}\n","import type { Try } from \"functype/try\"\nimport type { ReactElement, ReactNode } from \"react\"\n\n/**\n * Tag-narrowed sugar over `Match` for `Try<A>`. `Failure` receives the\n * underlying `Error`; `Success` receives the value.\n */\nexport function MatchTry<A>(props: {\n readonly value: Try<A>\n readonly Success: (a: A) => ReactNode\n readonly Failure: (e: Error) => ReactNode\n}): ReactElement {\n return <>{props.value.fold(props.Failure, props.Success)}</>\n}\n"],"mappings":"sDA2BA,SAAgBA,EAAkC,EAGjC,CACf,IAAMC,EAAUC,EAAM,SAASA,EAAM,MAAM,MAC3C,MAAO,kBAAAC,EAAA,CAAA,SAAGF,EAAQC,EAAM,KAAK,CAAI,CAAA,CACnC,CC3BA,SAAgBE,EAAkB,EAIjB,CACf,MAAO,kBAAAD,EAAA,CAAA,SAAGD,EAAM,MAAM,KAAKA,EAAM,KAAMA,EAAM,KAAK,CAAI,CAAA,CACxD,CCLA,SAAgBG,EAAe,EAId,CACf,MAAO,kBAAAF,EAAA,CAAA,SAAGD,EAAM,MAAM,KAAKA,EAAM,KAAMA,EAAM,IAAI,CAAI,CAAA,CACvD,CCNA,SAAgBI,EAAY,EAIX,CACf,MAAO,kBAAAH,EAAA,CAAA,SAAGD,EAAM,MAAM,KAAKA,EAAM,QAASA,EAAM,OAAO,CAAI,CAAA,CAC7D"}
|
|
File without changes
|