functype-react 1.20.0 → 1.21.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 +47 -18
- package/dist/AsyncState-DxKw9NF6.d.ts +21 -0
- package/dist/async/AsyncState.d.ts +2 -0
- package/dist/async/index.d.ts +7 -9
- package/dist/async/index.js +1 -1
- package/dist/async/index.js.map +1 -1
- package/dist/async/useIO.d.ts +27 -0
- package/dist/async/useIO.js +2 -0
- package/dist/async/useIO.js.map +1 -0
- package/dist/async/useIOPromise.d.ts +15 -0
- package/dist/async/useIOPromise.js +2 -0
- package/dist/async/useIOPromise.js.map +1 -0
- package/dist/async/useIOValue.d.ts +24 -0
- package/dist/async/useIOValue.js +2 -0
- package/dist/async/useIOValue.js.map +1 -0
- package/dist/{eq-CK6oQqWG.d.ts → eq-CR56QmPb.d.ts} +1 -3
- package/dist/forms/Validated.d.ts +0 -2
- package/dist/forms/Validated.js.map +1 -1
- package/dist/forms/useValidatedField.d.ts +0 -2
- package/dist/forms/useValidatedField.js.map +1 -1
- package/dist/forms/useValidatedForm.d.ts +0 -2
- package/dist/forms/useValidatedForm.js.map +1 -1
- package/dist/hooks/eq.d.ts +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.map +1 -1
- package/dist/hooks/useOption.d.ts +1 -1
- package/dist/hooks/useOption.js.map +1 -1
- package/dist/hooks/useStableCallback.d.ts +1 -1
- package/dist/hooks/useStableCallback.js.map +1 -1
- package/dist/hooks/useStableEffect.d.ts +1 -1
- package/dist/hooks/useStableEffect.js.map +1 -1
- package/dist/hooks/useStableMemo.d.ts +1 -1
- package/dist/hooks/useStableMemo.js.map +1 -1
- package/dist/hooks/useStableState.d.ts +1 -1
- package/dist/hooks/useStableState.js.map +1 -1
- package/dist/hooks/useTry.d.ts +1 -1
- package/dist/hooks/useTry.js.map +1 -1
- package/dist/{index-DjzwkXMF.d.ts → index-Dr09mq-A.d.ts} +1 -9
- package/dist/index.d.ts +10 -10
- package/dist/match/index.d.ts +1 -1
- package/dist/match/index.js +1 -1
- package/dist/match-CkGESkj9.js.map +1 -1
- package/dist/query/IOQueryError.d.ts +0 -2
- package/dist/query/IOQueryError.js.map +1 -1
- package/dist/query/ioQueryFn.d.ts +3 -4
- package/dist/query/ioQueryFn.js +1 -1
- package/dist/query/ioQueryFn.js.map +1 -1
- package/dist/query/queryState.d.ts +8 -10
- package/dist/query/queryState.js.map +1 -1
- package/dist/query/useIOMutation.d.ts +0 -2
- package/dist/query/useIOMutation.js.map +1 -1
- package/dist/query/useIOMutationState.d.ts +4 -6
- package/dist/query/useIOMutationState.js.map +1 -1
- package/dist/query/useIOQuery.d.ts +0 -2
- package/dist/query/useIOQuery.js.map +1 -1
- package/dist/query/useIOQueryState.d.ts +5 -7
- package/dist/query/useIOQueryState.js.map +1 -1
- package/dist/{useEither-DyPW7OaA.d.ts → useEither-D1Rn_tLR.d.ts} +1 -3
- package/dist/{useList-B5Iox1xv.d.ts → useList-C_7X5OA_.d.ts} +1 -3
- package/dist/{useOption-CXXNC1_S.d.ts → useOption-B8UyOh8h.d.ts} +1 -3
- package/dist/{useStableCallback-CXQQOhl6.d.ts → useStableCallback-C5jd1hKf.d.ts} +2 -4
- package/dist/{useStableEffect-C-5NCd1T.d.ts → useStableEffect-BiDhoNpC.d.ts} +2 -4
- package/dist/{useStableMemo-PYyLBWwd.d.ts → useStableMemo-DCeNIpt5.d.ts} +2 -4
- package/dist/{useStableState-fi6nURHS.d.ts → useStableState-BPVQ-XMX.d.ts} +2 -4
- package/dist/{useTry-B0HIcFFb.d.ts → useTry-ie1X0NiH.d.ts} +1 -3
- package/package.json +10 -10
- 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/async/{TaskState.js → AsyncState.js} +0 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ React bindings for the [functype](https://github.com/jordanburke/functype) funct
|
|
|
4
4
|
|
|
5
5
|
## Thesis
|
|
6
6
|
|
|
7
|
-
Push the same ADTs (`Option`, `Either`, `Try`, `
|
|
7
|
+
Push the same ADTs (`Option`, `Either`, `Try`, `IO`, `Validated`) you already trust on the server-side into React component boundaries, so design/requirement errors fail compilation in the UI layer instead of leaking through as `data && !error && !loading` flag soup.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -20,7 +20,7 @@ pnpm add functype functype-react react react-dom
|
|
|
20
20
|
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
21
21
|
| `functype-react` (main) | Stable hooks (`useStable*`), ADT hooks (`useOption`, `useEither`, `useTry`, `useList`), `Match` family components, equality helpers |
|
|
22
22
|
| `functype-react/match` | `<Match>`, `<MatchOption>`, `<MatchEither>`, `<MatchTry>` (also re-exported from main) |
|
|
23
|
-
| `functype-react/async` | `
|
|
23
|
+
| `functype-react/async` | `useIO`, `useIOPromise`, `useIOValue` (React 19 `use()` bridge), `<AsyncBoundary>` |
|
|
24
24
|
| `functype-react/forms` | `Validated<E, A>` type alias, `useValidatedField`, `useValidatedForm` |
|
|
25
25
|
| `functype-react/query` | `useIOQuery(State)`, `useIOMutation(State)`, `ioQueryFn`, `ioMutationFn`, `IOQueryError`, `toQueryState` — TanStack Query adapters for `IO` |
|
|
26
26
|
|
|
@@ -71,35 +71,38 @@ import { Match, MatchOption } from "functype-react"
|
|
|
71
71
|
|
|
72
72
|
Omitting a `_tag` case is a compile error.
|
|
73
73
|
|
|
74
|
-
## Tier 3 — async /
|
|
74
|
+
## Tier 3 — async / IO
|
|
75
75
|
|
|
76
76
|
```ts
|
|
77
|
-
import {
|
|
77
|
+
import { Http } from "functype/fetch"
|
|
78
|
+
import { useIO } from "functype-react/async"
|
|
78
79
|
|
|
79
80
|
function UserPanel({ id }: { id: string }) {
|
|
80
|
-
const state =
|
|
81
|
+
const state = useIO((signal) => Http.get<User>(`/users/${id}`, { signal }).map((r) => r.data), [id])
|
|
81
82
|
if (state.isPending) return <Spinner />
|
|
82
|
-
if (state.isFailure) return <Err err={state.error} />
|
|
83
|
+
if (state.isFailure) return <Err err={state.error} /> // state.error is the effect's typed E
|
|
83
84
|
return state.isSuccess ? <Profile user={state.value} /> : null
|
|
84
85
|
}
|
|
85
86
|
```
|
|
86
87
|
|
|
88
|
+
On unmount or a `deps` change the signal aborts, and the effect stops at its next step (no further retries, polls or `flatMap`s run). A typed failure becomes `Failure`; a defect is rethrown to the nearest error boundary.
|
|
89
|
+
|
|
87
90
|
For React 19 `use()` + Suspense:
|
|
88
91
|
|
|
89
92
|
```tsx
|
|
90
|
-
import {
|
|
93
|
+
import { AsyncBoundary, useIOValue } from "functype-react/async"
|
|
91
94
|
|
|
92
95
|
function UserPanel({ id }: { id: string }) {
|
|
93
|
-
const user =
|
|
96
|
+
const user = useIOValue((signal) => Http.get<User>(`/users/${id}`, { signal }).map((r) => r.data), [id])
|
|
94
97
|
return <Profile user={user} />
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
;<
|
|
100
|
+
;<AsyncBoundary pending={<Spinner />} fallback={(err, reset) => <ErrorPanel err={err} onRetry={reset} />}>
|
|
98
101
|
<UserPanel id="42" />
|
|
99
|
-
</
|
|
102
|
+
</AsyncBoundary>
|
|
100
103
|
```
|
|
101
104
|
|
|
102
|
-
`
|
|
105
|
+
`useIOValue` requires React 19. See the JSDoc on the hook for invariant documentation (stable promise refs, ErrorBoundary outside Suspense, no SSR).
|
|
103
106
|
|
|
104
107
|
## Tier 4 — forms with accumulating validation
|
|
105
108
|
|
|
@@ -165,7 +168,7 @@ if (error) {
|
|
|
165
168
|
|
|
166
169
|
### Matching instead of flag soup
|
|
167
170
|
|
|
168
|
-
The result above is still React Query's — `data` is `A | undefined`, so the success path needs a `!` or a guard. `toQueryState` projects it onto the same `
|
|
171
|
+
The result above is still React Query's — `data` is `A | undefined`, so the success path needs a `!` or a guard. `toQueryState` projects it onto the same `AsyncState` ADT that `functype-react/async` returns, so a query matches exhaustively like any other functype value:
|
|
169
172
|
|
|
170
173
|
```tsx
|
|
171
174
|
import { Match } from "functype-react"
|
|
@@ -191,7 +194,7 @@ function UserPanel({ id }: { id: string }) {
|
|
|
191
194
|
|
|
192
195
|
The projection is a pure function over the result, so you keep everything else React Query gives you (`refetch`, `isFetching`, `dataUpdatedAt`) on the original object. (Invalidation is a client-level operation — `queryClient.invalidateQueries()` — not a method on the result.)
|
|
193
196
|
|
|
194
|
-
If the ADT is all you need, `useIOQueryState` skips the projection step — it returns `
|
|
197
|
+
If the ADT is all you need, `useIOQueryState` skips the projection step — it returns `AsyncState` directly, plus the `isIdle`/`isPending`/`isSuccess`/`isFailure` flags and `refetch`, mirroring what `useIO` returns in Tier 3:
|
|
195
198
|
|
|
196
199
|
```tsx
|
|
197
200
|
const user = useIOQueryState(["user", id], ({ signal }) => Http.get<User>(url, { signal }))
|
|
@@ -212,8 +215,8 @@ Both read only the fields they project. For **queries** that matters: React Quer
|
|
|
212
215
|
|
|
213
216
|
Two behaviours worth knowing before you rely on the ADT:
|
|
214
217
|
|
|
215
|
-
- **A failed background refetch projects to `Failure` even though React Query still holds the last successful `data`.** `
|
|
216
|
-
- **`defect: true` means `.error` is not an `E`** — check it before matching on `_tag`. It is set when the effect factory throws before an `IO` is produced, when the effect produces a defect (`Exit.Die`: a throwing `IO.sync` thunk, a throwing `map`/`flatMap`/`mapError` callback, or `IO.die`), or when the effect is interrupted. Conversely `defect: false` genuinely means `.error` is an `E` — the bridge reads `runExit()`, so it can see the difference. (It previously read `run()`, whose `Either` could not, so a defect arrived indistinguishable from a typed failure and the flag read `false`.)
|
|
218
|
+
- **A failed background refetch projects to `Failure` even though React Query still holds the last successful `data`.** `AsyncState` has no "loaded but stale" variant. This is the deliberate default — it never silently hides a failure — but it does mean a transient refetch error flips a loaded view to the error branch. To keep rendering stale data, read `query.data` alongside the projection or branch on `query.isRefetchError` before projecting.
|
|
219
|
+
- **`defect: true` means `.error` is not an `E`** — check it before matching on `_tag`. It is set when the effect factory throws before an `IO` is produced, when the effect produces a defect (`Exit.Die`: a throwing `IO.sync` thunk, a throwing `map`/`flatMap`/`mapError` callback, or `IO.die`), or when the effect is interrupted (including a query React Query cancelled: the effect runs with the query's `signal`, so it stops at its next step). Conversely `defect: false` genuinely means `.error` is an `E` — the bridge reads `runExit()`, so it can see the difference. (It previously read `run()`, whose `Either` could not, so a defect arrived indistinguishable from a typed failure and the flag read `false`.)
|
|
217
220
|
|
|
218
221
|
Mutations mirror the shape (React Query supplies no `AbortSignal` to mutations, so the callback takes only the variables):
|
|
219
222
|
|
|
@@ -255,16 +258,42 @@ Both the hooks and the primitives are generic over any `IO<never, E, A>` — not
|
|
|
255
258
|
## Compatibility
|
|
256
259
|
|
|
257
260
|
- **TypeScript**: `strict: true` + `noUncheckedIndexedAccess: true`. Loose configs will silently lose the type-level exhaustiveness guarantees.
|
|
258
|
-
- **React**: peer dep range `>=18 <20`. Tier 3's `
|
|
261
|
+
- **React**: peer dep range `>=18 <20`. Tier 3's `useIOValue` (and consequently anything that depends on React 19's `use()` hook) is React-19-only at runtime; the rest of the package works on both.
|
|
259
262
|
- **SSR / RSC**: hooks are client-only and marked with `"use client"`. `<Match>` family components are pure and render fine in Server Components.
|
|
260
263
|
- **React Query**: Tier 5 targets `@tanstack/react-query` v5 (`>=5.0.0`), an optional peer. The `ioQueryFn` / `ioMutationFn` primitives type their context structurally, so they carry no `@tanstack` types and are unaffected by its major-version churn.
|
|
261
264
|
|
|
265
|
+
## Linting
|
|
266
|
+
|
|
267
|
+
`eslint-plugin-functype` ships two React rules:
|
|
268
|
+
|
|
269
|
+
- `functype/no-getOrThrow-in-render` reports a bare `.orThrow()` in a component or hook body, where a missing value would throw during render and unmount the tree.
|
|
270
|
+
- `functype/must-fold-on-component-return` reports a component that picks what it renders with an `isSome()` / `isLeft()` early return or `&&`, instead of `fold` or a `Match` component.
|
|
271
|
+
|
|
272
|
+
Both are on (`warn`) in `functype.configs.strict`. With `recommended`, turn them on yourself:
|
|
273
|
+
|
|
274
|
+
```js
|
|
275
|
+
// eslint.config.mjs
|
|
276
|
+
import functype from "eslint-plugin-functype"
|
|
277
|
+
|
|
278
|
+
export default [
|
|
279
|
+
functype.configs.recommended,
|
|
280
|
+
{
|
|
281
|
+
files: ["**/*.tsx", "**/*.jsx"],
|
|
282
|
+
rules: {
|
|
283
|
+
"functype/no-getOrThrow-in-render": "error",
|
|
284
|
+
"functype/must-fold-on-component-return": "warn",
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
]
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
They work without type information and are more precise with it (`parserOptions.projectService`). See the [plugin README](../eslint-plugin-functype/README.md#react-rules) for what each one reports.
|
|
291
|
+
|
|
262
292
|
## Deferred to v0.2
|
|
263
293
|
|
|
264
294
|
- `./optics` subpath (`useLens`, `useOptional`, `useSelector`) — blocked on core not shipping a lens module yet.
|
|
265
|
-
- React-specific ESLint rules (`must-fold-on-component-return`, `no-getOrThrow-in-render`, etc.) — land in `eslint-functype@2.4.0` once the API stabilizes.
|
|
266
295
|
- Codemods, Storybook, cookbook recipes on the Astro site.
|
|
267
|
-
- Playwright browser-based testing for `
|
|
296
|
+
- Playwright browser-based testing for `useIOValue` + `<AsyncBoundary>` (jsdom doesn't unsuspend React 19's `use()` reliably).
|
|
268
297
|
|
|
269
298
|
## License
|
|
270
299
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lifecycle state of an async operation managed by `useIO` (and the query hooks'
|
|
3
|
+
* `toQueryState` / `useIOQueryState` projections).
|
|
4
|
+
*
|
|
5
|
+
* `Idle` is before the first run, `Pending` while it's in flight, then `Success` or
|
|
6
|
+
* `Failure`. A cancelled run (unmount, or `deps` changing) never reaches `Failure`: its
|
|
7
|
+
* result is discarded.
|
|
8
|
+
*/
|
|
9
|
+
type AsyncState<E, A> = {
|
|
10
|
+
readonly _tag: "Idle";
|
|
11
|
+
} | {
|
|
12
|
+
readonly _tag: "Pending";
|
|
13
|
+
} | {
|
|
14
|
+
readonly _tag: "Success";
|
|
15
|
+
readonly value: A;
|
|
16
|
+
} | {
|
|
17
|
+
readonly _tag: "Failure";
|
|
18
|
+
readonly error: E;
|
|
19
|
+
};
|
|
20
|
+
export { AsyncState as t };
|
|
21
|
+
//# sourceMappingURL=AsyncState-DxKw9NF6.d.ts.map
|
package/dist/async/index.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { t as AsyncState } from "../AsyncState-DxKw9NF6.js";
|
|
2
|
+
import { UseIOResult, useIO } from "./useIO.js";
|
|
3
|
+
import { useIOPromise } from "./useIOPromise.js";
|
|
4
|
+
import { useIOValue } from "./useIOValue.js";
|
|
5
5
|
import { ReactElement, ReactNode } from "react";
|
|
6
|
-
//#region src/async/TaskBoundary.d.ts
|
|
7
6
|
type Props = {
|
|
8
7
|
readonly pending: ReactNode;
|
|
9
8
|
readonly fallback: (error: unknown, reset: () => void) => ReactNode;
|
|
10
9
|
readonly children: ReactNode;
|
|
11
10
|
};
|
|
12
11
|
/**
|
|
13
|
-
* Combines `<Suspense>` (for pending
|
|
12
|
+
* Combines `<Suspense>` (for pending effects consumed via `useIOValue`) with
|
|
14
13
|
* an ErrorBoundary that catches thrown failures. The `fallback` render prop
|
|
15
14
|
* receives the thrown value (typed `unknown` — consumers narrow) and a
|
|
16
15
|
* `reset` callback that clears the error so children can be re-attempted.
|
|
@@ -18,7 +17,6 @@ type Props = {
|
|
|
18
17
|
* The ErrorBoundary wraps the Suspense, matching React's documented rule
|
|
19
18
|
* (otherwise Suspense would catch errors instead of the boundary).
|
|
20
19
|
*/
|
|
21
|
-
export declare function
|
|
22
|
-
|
|
23
|
-
export { type TaskState, type UseTaskResult, useTask, useTaskPromise, useTaskValue };
|
|
20
|
+
export declare function AsyncBoundary(props: Props): ReactElement;
|
|
21
|
+
export { type AsyncState, type UseIOResult, useIO, useIOPromise, useIOValue };
|
|
24
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/async/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{useIO as e}from"./useIO.js";import{useIOPromise as t}from"./useIOPromise.js";import{useIOValue as n}from"./useIOValue.js";import{Component as r,Suspense as i}from"react";import{jsx as a}from"react/jsx-runtime";var o=class extends r{constructor(...e){super(...e),this.state={_tag:`Ok`},this.reset=()=>{this.setState({_tag:`Ok`})}}static getDerivedStateFromError(e){return{_tag:`Errored`,error:e}}componentDidCatch(e,t){}render(){return this.state._tag===`Errored`?this.props.fallback(this.state.error,this.reset):this.props.children}};function s(e){return/* @__PURE__ */ a(o,{fallback:e.fallback,children:/* @__PURE__ */ a(i,{fallback:e.pending,children:e.children})})}export{s as AsyncBoundary,e as useIO,t as useIOPromise,n as useIOValue};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/async/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["AsyncErrorBoundary","Component","_args","AsyncBoundary","props","Suspense","useIO","useIOPromise","useIOValue"],"sources":["../../src/async/AsyncBoundary.tsx"],"sourcesContent":["\"use client\"\n\nimport { Component, type ErrorInfo, type ReactElement, type ReactNode, Suspense } from \"react\"\n\ntype Props = {\n readonly pending: ReactNode\n readonly fallback: (error: unknown, reset: () => void) => ReactNode\n readonly children: ReactNode\n}\n\ntype State = { readonly _tag: \"Ok\" } | { readonly _tag: \"Errored\"; readonly error: unknown }\n\nclass AsyncErrorBoundary extends Component<\n { readonly fallback: Props[\"fallback\"]; readonly children: ReactNode },\n State\n> {\n override state: State = { _tag: \"Ok\" }\n\n static getDerivedStateFromError(error: unknown): State {\n return { _tag: \"Errored\", error }\n }\n\n override componentDidCatch(_error: unknown, _info: ErrorInfo): void {\n // hook for telemetry; intentionally noop in v0.1\n }\n\n reset = (): void => {\n this.setState({ _tag: \"Ok\" })\n }\n\n override render(): ReactNode {\n if (this.state._tag === \"Errored\") {\n return this.props.fallback(this.state.error, this.reset)\n }\n return this.props.children\n }\n}\n\n/**\n * Combines `<Suspense>` (for pending effects consumed via `useIOValue`) with\n * an ErrorBoundary that catches thrown failures. The `fallback` render prop\n * receives the thrown value (typed `unknown` — consumers narrow) and a\n * `reset` callback that clears the error so children can be re-attempted.\n *\n * The ErrorBoundary wraps the Suspense, matching React's documented rule\n * (otherwise Suspense would catch errors instead of the boundary).\n */\nexport function AsyncBoundary(props: Props): ReactElement {\n return (\n <AsyncErrorBoundary fallback={props.fallback}>\n <Suspense fallback={props.pending}>{props.children}</Suspense>\n </AsyncErrorBoundary>\n )\n}\n"],"mappings":"A,yNAYA,IAAMA,EAAN,cAAiCC,CAG/B,C,8BACA,KAAS,MAAe,CAAE,KAAM,IAAK,EAUrC,KAAA,UAAoB,CAClB,KAAK,SAAS,CAAE,KAAM,IAAK,CAAC,CAC9B,C,CAVA,OAAO,yBAAyB,EAAuB,CACrD,MAAO,CAAE,KAAM,UAAW,OAAM,CAClC,CAEA,kBAA2B,EAAiB,EAAwB,CAEpE,CAMA,QAA6B,CAI3B,OAHI,KAAK,MAAM,OAAS,UACf,KAAK,MAAM,SAAS,KAAK,MAAM,MAAO,KAAK,KAAK,EAElD,KAAK,MAAM,QACpB,CACF,EAWA,SAAgBE,EAAc,EAA4B,CACxD,MACE,kBAACH,EAAD,CAAoB,SAAUI,EAAM,SAClC,SAAA,kBAACC,EAAD,CAAU,SAAUD,EAAM,QAAU,SAAAA,EAAM,QAAmB,CAAA,CAC3C,CAAA,CAExB,C"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { t as AsyncState } from "../AsyncState-DxKw9NF6.js";
|
|
2
|
+
import { IO } from "functype/io";
|
|
3
|
+
export type UseIOResult<E, A> = AsyncState<E, A> & {
|
|
4
|
+
readonly isIdle: boolean;
|
|
5
|
+
readonly isPending: boolean;
|
|
6
|
+
readonly isSuccess: boolean;
|
|
7
|
+
readonly isFailure: boolean;
|
|
8
|
+
refetch: () => void;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Runs an `IO<never, E, A>` tied to a component's lifecycle and returns its `AsyncState`,
|
|
12
|
+
* plus boolean flags and a `refetch` trigger.
|
|
13
|
+
*
|
|
14
|
+
* - The factory receives an `AbortSignal` that aborts on unmount or when `deps` change.
|
|
15
|
+
* The effect is cancelled with it: no further step runs once it fires. Also pass it to
|
|
16
|
+
* `Http` / `IO.tryAsync` so an in-flight request aborts too.
|
|
17
|
+
* - A cancelled run's result is discarded, so it never shows up as `Failure`.
|
|
18
|
+
* - A typed failure becomes `Failure` with the effect's `E`.
|
|
19
|
+
* - A defect (a bug: a throw inside the effect, or the factory throwing while building it)
|
|
20
|
+
* is rethrown during render, so the nearest error boundary catches it, the way a bug in
|
|
21
|
+
* any other component would surface.
|
|
22
|
+
* - StrictMode-safe: the cleanup aborts the signal and discards any late result.
|
|
23
|
+
*
|
|
24
|
+
* @interop React reaches an error boundary only through a throw during render, so a defect is rethrown there.
|
|
25
|
+
*/
|
|
26
|
+
export declare function useIO<E, A>(io: (signal: AbortSignal) => IO<never, E, A>, deps: ReadonlyArray<unknown>): UseIOResult<E, A>;
|
|
27
|
+
//# sourceMappingURL=useIO.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{useCallback as e,useEffect as t,useReducer as n,useRef as r,useState as i}from"react";import{Try 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]=i(void 0),[p,m]=n(e=>e+1,0),h=r(s);h.current=s,t(()=>{let e=new AbortController;u({type:`PENDING`});let t=t=>{e.signal.aborted||t.fold(e=>u({type:`FAILURE`,error:e}),e=>u({type:`SUCCESS`,value:e}),()=>f({value:/* @__PURE__ */ Error(`useIO: the effect interrupted itself`)}),e=>f({value:e}))};return a(()=>h.current(e.signal)).fold(e=>f({value:e}),n=>void n.runExit({signal:e.signal}).then(t)),()=>e.abort()},[...c,p]);let g=e(()=>m(),[]);if(d)throw d.value;return{...l,isIdle:l._tag===`Idle`,isPending:l._tag===`Pending`,isSuccess:l._tag===`Success`,isFailure:l._tag===`Failure`,refetch:g}}export{s as useIO};
|
|
2
|
+
//# sourceMappingURL=useIO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIO.js","names":["reducer","action","useIO","state","dispatch","useReducer","defect","setDefect","useState","refetchTick","forceRefetch","n","ioRef","useRef","io","useEffect","controller","settle","exit","Try","thrown","effect","deps","refetch","useCallback"],"sources":["../../src/async/useIO.ts"],"sourcesContent":["\"use client\"\n\nimport { Try } from \"functype\"\nimport type { Exit, IO } from \"functype/io\"\nimport { useCallback, useEffect, useReducer, useRef, useState } from \"react\"\n\nimport type { AsyncState } from \"./AsyncState\"\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: AsyncState<E, A>, action: Action<E, A>): AsyncState<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 UseIOResult<E, A> = AsyncState<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 * Runs an `IO<never, E, A>` tied to a component's lifecycle and returns its `AsyncState`,\n * plus boolean flags and a `refetch` trigger.\n *\n * - The factory receives an `AbortSignal` that aborts on unmount or when `deps` change.\n * The effect is cancelled with it: no further step runs once it fires. Also pass it to\n * `Http` / `IO.tryAsync` so an in-flight request aborts too.\n * - A cancelled run's result is discarded, so it never shows up as `Failure`.\n * - A typed failure becomes `Failure` with the effect's `E`.\n * - A defect (a bug: a throw inside the effect, or the factory throwing while building it)\n * is rethrown during render, so the nearest error boundary catches it, the way a bug in\n * any other component would surface.\n * - StrictMode-safe: the cleanup aborts the signal and discards any late result.\n *\n * @interop React reaches an error boundary only through a throw during render, so a defect is rethrown there.\n */\nexport function useIO<E, A>(\n io: (signal: AbortSignal) => IO<never, E, A>,\n deps: ReadonlyArray<unknown>,\n): UseIOResult<E, A> {\n const [state, dispatch] = useReducer(reducer<E, A>, { _tag: \"Idle\" })\n const [defect, setDefect] = useState<{ readonly value: unknown } | undefined>(undefined)\n const [refetchTick, forceRefetch] = useReducer((n: number) => n + 1, 0)\n const ioRef = useRef(io)\n ioRef.current = io\n\n useEffect(() => {\n const controller = new AbortController()\n dispatch({ type: \"PENDING\" })\n\n const settle = (exit: Exit<E, A>): void => {\n if (controller.signal.aborted) return\n exit.fold(\n (error) => dispatch({ type: \"FAILURE\", error }),\n (value) => dispatch({ type: \"SUCCESS\", value }),\n // Interrupted without an abort means the effect interrupted itself (IO.interrupt()):\n // there is no value and no E, so it is reported like a defect.\n () => setDefect({ value: new Error(\"useIO: the effect interrupted itself\") }),\n (defect) => setDefect({ value: defect }),\n )\n }\n\n // The factory is user code and can throw while building the effect; that's a defect too.\n Try(() => ioRef.current(controller.signal)).fold(\n (thrown) => setDefect({ value: thrown }),\n (effect) => void effect.runExit({ signal: controller.signal }).then(settle),\n )\n\n return () => controller.abort()\n }, [...deps, refetchTick])\n\n const refetch = useCallback(() => forceRefetch(), [])\n\n if (defect) throw defect.value\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":"A,yIAaA,SAASA,EAAc,EAA0B,EAAwC,CAGvF,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,CA0BA,SAAgBC,EACd,EACA,EACmB,CACnB,GAAM,CAACC,EAAOC,GAAYC,EAAWL,EAAe,CAAE,KAAM,MAAO,CAAC,EAC9D,CAACM,EAAQC,GAAaC,EAAkD,IAAA,EAAS,EACjF,CAACC,EAAaC,GAAgBL,EAAY,GAAcM,EAAI,EAAG,CAAC,EAChEC,EAAQC,EAAOC,CAAE,EACvB,EAAM,QAAUA,EAEhBC,MAAgB,CACd,IAAMC,EAAa,IAAI,gBACvBZ,EAAS,CAAE,KAAM,SAAU,CAAC,EAE5B,IAAMa,EAAU,GAA2B,CACrCD,EAAW,OAAO,SACtBE,EAAK,KACF,GAAUd,EAAS,CAAE,KAAM,UAAW,OAAM,CAAC,EAC7C,GAAUA,EAAS,CAAE,KAAM,UAAW,OAAM,CAAC,MAGxCG,EAAU,CAAE,MAAO,gBAAI,MAAM,sCAAsC,CAAE,CAAC,EAC3E,GAAWA,EAAU,CAAE,MAAOD,CAAO,CAAC,CACzC,CACF,EAQA,OALAa,MAAUP,EAAM,QAAQI,EAAW,MAAM,CAAC,CAAC,CAAC,KACzC,GAAWT,EAAU,CAAE,MAAOa,CAAO,CAAC,EACtC,GAAW,KAAKC,EAAO,QAAQ,CAAE,OAAQL,EAAW,MAAO,CAAC,CAAC,CAAC,KAAKC,CAAM,CAC5E,MAEaD,EAAW,MAAM,CAChC,EAAG,CAAC,GAAGM,EAAMb,CAAW,CAAC,EAEzB,IAAMc,EAAUC,MAAkBd,EAAa,EAAG,CAAC,CAAC,EAEpD,GAAIJ,EAAQ,MAAMA,EAAO,MAEzB,MAAO,CACL,GAAGH,EACH,OAAQA,EAAM,OAAS,OACvB,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,UAAWA,EAAM,OAAS,UAC1B,SACF,CACF,C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Exit, IO } from "functype/io";
|
|
2
|
+
/**
|
|
3
|
+
* Starts an `IO<never, E, A>` and returns a `Promise<Exit<E, A>>` that is stable across
|
|
4
|
+
* renders with the same `deps`. Intended for React 19's `use()`: a new promise on each
|
|
5
|
+
* render would suspend forever.
|
|
6
|
+
*
|
|
7
|
+
* `Exit` keeps a typed failure, a defect and an interruption apart, so a consumer can tell
|
|
8
|
+
* them apart; `useIOValue` does that for you.
|
|
9
|
+
*
|
|
10
|
+
* The factory is read through a ref, so the latest closure runs even if it isn't in `deps`.
|
|
11
|
+
* Put in `deps` whatever changes the result. The factory receives an `AbortSignal` for
|
|
12
|
+
* `Http` / `IO.tryAsync`; `useMemo` has no cleanup, so nothing aborts it on unmount.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useIOPromise<E, A>(io: (signal: AbortSignal) => IO<never, E, A>, deps: ReadonlyArray<unknown>): Promise<Exit<E, A>>;
|
|
15
|
+
//# sourceMappingURL=useIOPromise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIOPromise.js","names":["useIOPromise","ioRef","useRef","io","useMemo","controller","deps"],"sources":["../../src/async/useIOPromise.ts"],"sourcesContent":["\"use client\"\n\nimport type { Exit, IO } from \"functype/io\"\nimport { useMemo, useRef } from \"react\"\n\n/**\n * Starts an `IO<never, E, A>` and returns a `Promise<Exit<E, A>>` that is stable across\n * renders with the same `deps`. Intended for React 19's `use()`: a new promise on each\n * render would suspend forever.\n *\n * `Exit` keeps a typed failure, a defect and an interruption apart, so a consumer can tell\n * them apart; `useIOValue` does that for you.\n *\n * The factory is read through a ref, so the latest closure runs even if it isn't in `deps`.\n * Put in `deps` whatever changes the result. The factory receives an `AbortSignal` for\n * `Http` / `IO.tryAsync`; `useMemo` has no cleanup, so nothing aborts it on unmount.\n */\nexport function useIOPromise<E, A>(\n io: (signal: AbortSignal) => IO<never, E, A>,\n deps: ReadonlyArray<unknown>,\n): Promise<Exit<E, A>> {\n const ioRef = useRef(io)\n ioRef.current = io\n\n return useMemo(() => {\n const controller = new AbortController()\n return ioRef.current(controller.signal).runExit({ signal: controller.signal })\n }, deps)\n}\n"],"mappings":"A,yDAiBA,SAAgBA,EACd,EACA,EACqB,CACrB,IAAMC,EAAQC,EAAOC,CAAE,EAGvB,MAFA,GAAM,QAAUA,EAETC,MAAc,CACnB,IAAMC,EAAa,IAAI,gBACvB,OAAOJ,EAAM,QAAQI,EAAW,MAAM,CAAC,CAAC,QAAQ,CAAE,OAAQA,EAAW,MAAO,CAAC,CAC/E,EAAGC,CAAI,CACT,C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IO } from "functype/io";
|
|
2
|
+
/**
|
|
3
|
+
* Suspense-aware variant of `useIO` for React 19+. Suspends while the effect is pending and
|
|
4
|
+
* returns its value. On failure it throws the typed error; on a defect, the defect; on an
|
|
5
|
+
* interruption, an `InterruptedError`. All three reach `<AsyncBoundary>` (or a hand-rolled
|
|
6
|
+
* Suspense + ErrorBoundary pair).
|
|
7
|
+
*
|
|
8
|
+
* Invariants enforced by React 19:
|
|
9
|
+
* 1. The promise must be stable across renders. `useIOPromise` memoizes by `deps`, so
|
|
10
|
+
* passing the same deps yields the same promise.
|
|
11
|
+
* 2. An ErrorBoundary must wrap the Suspense, never the reverse — otherwise Suspense will
|
|
12
|
+
* catch the thrown error instead of the boundary.
|
|
13
|
+
* 3. Do not call this on the server. Build the `IO` in a Client Component and call
|
|
14
|
+
* `useIOValue` there.
|
|
15
|
+
*
|
|
16
|
+
* @interop React's `use()` reaches the nearest ErrorBoundary only through a throw, not an Either return.
|
|
17
|
+
*
|
|
18
|
+
* Testing note: React 19's `use()` does not unsuspend reliably under jsdom +
|
|
19
|
+
* @testing-library/react. End-to-end tests of `useIOValue` + `<AsyncBoundary>` require a
|
|
20
|
+
* real browser scheduler (Playwright); unit tests of `useIO` and `useIOPromise` cover the
|
|
21
|
+
* plumbing.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useIOValue<E, A>(io: (signal: AbortSignal) => IO<never, E, A>, deps: ReadonlyArray<unknown>): A;
|
|
24
|
+
//# sourceMappingURL=useIOValue.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{useIOPromise as e}from"./useIOPromise.js";import{use as t}from"react";import{InterruptedError as n}from"functype/io";function r(r,i){let a=t(e(r,i));if(a.isSuccess())return a.orThrow();throw a.isFailure()?a.toValue().error:a.isDie()?a.toValue().defect:new n}export{r as useIOValue};
|
|
2
|
+
//# sourceMappingURL=useIOValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIOValue.js","names":["useIOValue","exit","use","useIOPromise","io","deps","InterruptedError"],"sources":["../../src/async/useIOValue.ts"],"sourcesContent":["\"use client\"\n\nimport { InterruptedError, type IO } from \"functype/io\"\nimport { use } from \"react\"\n\nimport { useIOPromise } from \"./useIOPromise\"\n\n/**\n * Suspense-aware variant of `useIO` for React 19+. Suspends while the effect is pending and\n * returns its value. On failure it throws the typed error; on a defect, the defect; on an\n * interruption, an `InterruptedError`. All three reach `<AsyncBoundary>` (or a hand-rolled\n * Suspense + ErrorBoundary pair).\n *\n * Invariants enforced by React 19:\n * 1. The promise must be stable across renders. `useIOPromise` memoizes by `deps`, so\n * passing the same deps yields the same promise.\n * 2. An ErrorBoundary must wrap the Suspense, never the reverse — otherwise Suspense will\n * catch the thrown error instead of the boundary.\n * 3. Do not call this on the server. Build the `IO` in a Client Component and call\n * `useIOValue` 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 `useIOValue` + `<AsyncBoundary>` require a\n * real browser scheduler (Playwright); unit tests of `useIO` and `useIOPromise` cover the\n * plumbing.\n */\nexport function useIOValue<E, A>(io: (signal: AbortSignal) => IO<never, E, A>, deps: ReadonlyArray<unknown>): A {\n const exit = use(useIOPromise(io, deps))\n if (exit.isSuccess()) return exit.orThrow()\n if (exit.isFailure()) throw exit.toValue().error\n if (exit.isDie()) throw exit.toValue().defect\n throw new InterruptedError()\n}\n"],"mappings":"A,yIA4BA,SAAgBA,EAAiB,EAA8C,EAAiC,CAC9G,IAAMC,EAAOC,EAAIC,EAAaC,EAAIC,CAAI,CAAC,EACvC,GAAIJ,EAAK,UAAU,EAAG,OAAOA,EAAK,QAAQ,EAG1C,MAFIA,EAAK,UAAU,EAASA,EAAK,QAAQ,CAAC,CAAC,MACvCA,EAAK,MAAM,EAASA,EAAK,QAAQ,CAAC,CAAC,OACjC,IAAIK,CACZ,C"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/hooks/eq.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Equality comparators for use with `useStable*` hooks.
|
|
4
3
|
*
|
|
@@ -25,6 +24,5 @@ declare const tagEq: Eq<unknown>;
|
|
|
25
24
|
* behavior. Functions compare by reference.
|
|
26
25
|
*/
|
|
27
26
|
declare const structuralEq: Eq<unknown>;
|
|
28
|
-
//#endregion
|
|
29
27
|
export { tagEq as i, referenceEq as n, structuralEq as r, Eq as t };
|
|
30
|
-
//# sourceMappingURL=eq-
|
|
28
|
+
//# sourceMappingURL=eq-CR56QmPb.d.ts.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Either, List } from "functype";
|
|
2
|
-
//#region src/forms/Validated.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Applicative-error-accumulating result for form validation.
|
|
5
4
|
*
|
|
@@ -16,5 +15,4 @@ export type Validated<E, A> = Either<List<E>, A>;
|
|
|
16
15
|
export declare function valid<A>(value: A): Validated<never, A>;
|
|
17
16
|
/** Construct an `Invalid` (Left) result from an iterable of errors. */
|
|
18
17
|
export declare function invalid<E>(errors: List<E> | ReadonlyArray<E>): Validated<E, never>;
|
|
19
|
-
//#endregion
|
|
20
18
|
//# sourceMappingURL=Validated.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Validated.js","names":["valid","Right","value","invalid","list","errors","List","Left"],"sources":["../../src/forms/Validated.ts"],"sourcesContent":["import { type Either, Left, List, type List as ListT, Right } from \"functype\"\n\n/**\n * Applicative-error-accumulating result for form validation.\n *\n * Encoded as `Either<List<E>, A>` — the same shape Scala's cats uses for\n * `ValidatedNel`. Multiple field errors accumulate via `List.concat`; on\n * success, the validated value rides in the `Right` channel.\n *\n * functype core already exposes this pattern via `FormValidation<T>` in\n * `packages/functype/src/error/typed/Validation.ts`; this alias just gives\n * the React-facing surface an ergonomic name.\n */\nexport type Validated<E, A> = Either<ListT<E>, A>\n\n/** Construct a `Valid` (Right) result. */\nexport function valid<A>(value: A): Validated<never, A> {\n return Right<ListT<never>, A>(value)\n}\n\n/** Construct an `Invalid` (Left) result from an iterable of errors. */\nexport function invalid<E>(errors: ListT<E> | ReadonlyArray<E>): Validated<E, never> {\n const list = errors instanceof Array ? List<E>(errors) : (errors as ListT<E>)\n return Left<ListT<E>, never>(list)\n}\n"],"mappings":"qDAgBA,SAAgBA,EAAS,EAA+B,CACtD,OAAOC,EAAuBC,CAAK,CACrC,CAGA,SAAgBC,EAAW,EAA0D,CACnF,IAAMC,EAAOC,aAAkB,MAAQC,EAAQD,CAAM,EAAKA,EAC1D,OAAOE,EAAsBH,CAAI,CACnC"}
|
|
1
|
+
{"version":3,"file":"Validated.js","names":["valid","Right","value","invalid","list","errors","List","Left"],"sources":["../../src/forms/Validated.ts"],"sourcesContent":["import { type Either, Left, List, type List as ListT, Right } from \"functype\"\n\n/**\n * Applicative-error-accumulating result for form validation.\n *\n * Encoded as `Either<List<E>, A>` — the same shape Scala's cats uses for\n * `ValidatedNel`. Multiple field errors accumulate via `List.concat`; on\n * success, the validated value rides in the `Right` channel.\n *\n * functype core already exposes this pattern via `FormValidation<T>` in\n * `packages/functype/src/error/typed/Validation.ts`; this alias just gives\n * the React-facing surface an ergonomic name.\n */\nexport type Validated<E, A> = Either<ListT<E>, A>\n\n/** Construct a `Valid` (Right) result. */\nexport function valid<A>(value: A): Validated<never, A> {\n return Right<ListT<never>, A>(value)\n}\n\n/** Construct an `Invalid` (Left) result from an iterable of errors. */\nexport function invalid<E>(errors: ListT<E> | ReadonlyArray<E>): Validated<E, never> {\n const list = errors instanceof Array ? List<E>(errors) : (errors as ListT<E>)\n return Left<ListT<E>, never>(list)\n}\n"],"mappings":"A,qDAgBA,SAAgBA,EAAS,EAA+B,CACtD,OAAOC,EAAuBC,CAAK,CACrC,CAGA,SAAgBC,EAAW,EAA0D,CACnF,IAAMC,EAAOC,aAAkB,MAAQC,EAAQD,CAAM,EAAKA,EAC1D,OAAOE,EAAsBH,CAAI,CACnC,C"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Validated } from "./Validated.js";
|
|
2
2
|
import { ChangeEvent } from "react";
|
|
3
3
|
import { List } from "functype";
|
|
4
|
-
//#region src/forms/useValidatedField.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Single-field state container with continuously-derived validation.
|
|
7
6
|
*
|
|
@@ -26,5 +25,4 @@ export declare function useValidatedField<A, E = string>(opts: {
|
|
|
26
25
|
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
27
26
|
};
|
|
28
27
|
};
|
|
29
|
-
//#endregion
|
|
30
28
|
//# sourceMappingURL=useValidatedField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useValidatedField.js","names":["useValidatedField","value","setValue","useState","opts","validation","useMemo","es","List","useCallback"],"sources":["../../src/forms/useValidatedField.ts"],"sourcesContent":["\"use client\"\n\nimport { List, type List as ListT } from \"functype\"\nimport { type ChangeEvent, useCallback, useMemo, useState } from \"react\"\n\nimport type { Validated } from \"./Validated\"\n\n/**\n * Single-field state container with continuously-derived validation.\n *\n * `validation` is re-derived from `validate(value)` on every render — keep\n * `validate` cheap or memoize the callback.\n *\n * `bind()` returns props ready to spread onto a native `<input>`. The\n * generic `A` may be any value type; `bind` is most useful when `A` is\n * string-shaped. For non-string fields, wire `value`/`setValue` directly.\n */\nexport function useValidatedField<A, E = string>(opts: {\n readonly initial: A\n readonly validate: (a: A) => Validated<E, A>\n}): {\n readonly value: A\n setValue: (a: A) => void\n readonly validation: Validated<E, A>\n readonly errors: ListT<E>\n readonly isValid: boolean\n bind: () => { value: A; onChange: (e: ChangeEvent<HTMLInputElement>) => void }\n} {\n const [value, setValue] = useState<A>(opts.initial)\n\n const validation = useMemo(() => opts.validate(value), [opts, value])\n const errors = useMemo(\n () =>\n validation.fold(\n (es) => es,\n () => List.empty<E>(),\n ),\n [validation],\n )\n const isValid = validation.isRight()\n\n const bind = useCallback(\n () => ({\n value,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value as unknown as A),\n }),\n [value],\n )\n\n return { value, setValue, validation, errors, isValid, bind }\n}\n"],"mappings":"4GAiBA,SAAgBA,EAAiC,EAU/C,CACA,GAAM,CAACC,EAAOC,GAAYC,EAAYC,EAAK,OAAO,EAE5CC,EAAaC,MAAcF,EAAK,SAASH,CAAK,EAAG,CAACG,EAAMH,CAAK,CAAC,EAmBpE,MAAO,CAAE,QAAO,WAAU,aAAY,OAlBvBK,MAEXD,EAAW,KACR,GAAOE,MACFC,EAAK,MAAS,CACtB,EACF,CAACH,CAAU,CAY8B,EAAG,QAV9BA,EAAW,QAUyB,EAAG,KAR1CI,OACJ,CACL,QACA,SAAW,GAAqCP,EAAS,EAAE,OAAO,KAAqB,CACzF,GACA,CAACD,CAAK,CAGkD,CAAE,CAC9D"}
|
|
1
|
+
{"version":3,"file":"useValidatedField.js","names":["useValidatedField","value","setValue","useState","opts","validation","useMemo","es","List","useCallback"],"sources":["../../src/forms/useValidatedField.ts"],"sourcesContent":["\"use client\"\n\nimport { List, type List as ListT } from \"functype\"\nimport { type ChangeEvent, useCallback, useMemo, useState } from \"react\"\n\nimport type { Validated } from \"./Validated\"\n\n/**\n * Single-field state container with continuously-derived validation.\n *\n * `validation` is re-derived from `validate(value)` on every render — keep\n * `validate` cheap or memoize the callback.\n *\n * `bind()` returns props ready to spread onto a native `<input>`. The\n * generic `A` may be any value type; `bind` is most useful when `A` is\n * string-shaped. For non-string fields, wire `value`/`setValue` directly.\n */\nexport function useValidatedField<A, E = string>(opts: {\n readonly initial: A\n readonly validate: (a: A) => Validated<E, A>\n}): {\n readonly value: A\n setValue: (a: A) => void\n readonly validation: Validated<E, A>\n readonly errors: ListT<E>\n readonly isValid: boolean\n bind: () => { value: A; onChange: (e: ChangeEvent<HTMLInputElement>) => void }\n} {\n const [value, setValue] = useState<A>(opts.initial)\n\n const validation = useMemo(() => opts.validate(value), [opts, value])\n const errors = useMemo(\n () =>\n validation.fold(\n (es) => es,\n () => List.empty<E>(),\n ),\n [validation],\n )\n const isValid = validation.isRight()\n\n const bind = useCallback(\n () => ({\n value,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value as unknown as A),\n }),\n [value],\n )\n\n return { value, setValue, validation, errors, isValid, bind }\n}\n"],"mappings":"A,4GAiBA,SAAgBA,EAAiC,EAU/C,CACA,GAAM,CAACC,EAAOC,GAAYC,EAAYC,EAAK,OAAO,EAE5CC,EAAaC,MAAcF,EAAK,SAASH,CAAK,EAAG,CAACG,EAAMH,CAAK,CAAC,EAmBpE,MAAO,CAAE,QAAO,WAAU,aAAY,OAlBvBK,MAEXD,EAAW,KACR,GAAOE,MACFC,EAAK,MAAS,CACtB,EACF,CAACH,CAAU,CAY8B,EAAG,QAV9BA,EAAW,QAUyB,EAAG,KAR1CI,OACJ,CACL,QACA,SAAW,GAAqCP,EAAS,EAAE,OAAO,KAAqB,CACzF,GACA,CAACD,CAAK,CAGkD,CAAE,CAC9D,C"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Validated } from "./Validated.js";
|
|
2
2
|
import { FormEvent } from "react";
|
|
3
3
|
import { List } from "functype";
|
|
4
|
-
//#region src/forms/useValidatedForm.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Form-level state container with applicative error accumulation.
|
|
7
6
|
*
|
|
@@ -32,5 +31,4 @@ export declare function useValidatedForm<S extends Record<string, unknown>, E =
|
|
|
32
31
|
reset: () => void;
|
|
33
32
|
handleSubmit: (onValid: (s: S) => void | Promise<void>) => (e: FormEvent) => void;
|
|
34
33
|
};
|
|
35
|
-
//#endregion
|
|
36
34
|
//# sourceMappingURL=useValidatedForm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useValidatedForm.js","names":["useValidatedForm","values","setValues","useState","opts","setField","useCallback","prev","key","value","reset","validation","useMemo","es","List","e","onValid","s"],"sources":["../../src/forms/useValidatedForm.ts"],"sourcesContent":["\"use client\"\n\nimport { List, type List as ListT } from \"functype\"\nimport { type FormEvent, useCallback, useMemo, useState } from \"react\"\n\nimport type { Validated } from \"./Validated\"\n\n/**\n * Form-level state container with applicative error accumulation.\n *\n * The consumer-provided `validate` is the canonical place to accumulate\n * field-level errors. A common pattern:\n *\n * ```ts\n * const validate = (s: Form): Validated<string, Form> => {\n * const errs = List<string>([])\n * .concat(s.email.includes(\"@\") ? List([]) : List([\"email must contain @\"]))\n * .concat(s.age >= 18 ? List([]) : List([\"age must be 18+\"]))\n * return errs.isEmpty ? valid(s) : invalid(errs)\n * }\n * ```\n *\n * `handleSubmit(onValid)` returns an event handler that calls `e.preventDefault()`\n * and only invokes `onValid` when the current form value passes validation.\n */\nexport function useValidatedForm<S extends Record<string, unknown>, E = string>(opts: {\n readonly initial: S\n readonly validate: (s: S) => Validated<E, S>\n}): {\n readonly values: S\n setField: <K extends keyof S>(key: K, value: S[K]) => void\n readonly validation: Validated<E, S>\n readonly errors: ListT<E>\n readonly isValid: boolean\n reset: () => void\n handleSubmit: (onValid: (s: S) => void | Promise<void>) => (e: FormEvent) => void\n} {\n const [values, setValues] = useState<S>(opts.initial)\n\n const setField = useCallback(<K extends keyof S>(key: K, value: S[K]) => {\n setValues((prev) => ({ ...prev, [key]: value }))\n }, [])\n\n const reset = useCallback(() => setValues(opts.initial), [opts.initial])\n\n const validation = useMemo(() => opts.validate(values), [opts, values])\n const errors = useMemo(\n () =>\n validation.fold(\n (es) => es,\n () => List.empty<E>(),\n ),\n [validation],\n )\n const isValid = validation.isRight()\n\n const handleSubmit = useCallback(\n (onValid: (s: S) => void | Promise<void>) => (e: FormEvent) => {\n e.preventDefault()\n validation.fold(\n () => undefined,\n (s) => {\n void onValid(s)\n },\n )\n },\n [validation],\n )\n\n return { values, setField, validation, errors, isValid, reset, handleSubmit }\n}\n"],"mappings":"4GAyBA,SAAgBA,EAAgE,EAW9E,CACA,GAAM,CAACC,EAAQC,GAAaC,EAAYC,EAAK,OAAO,EAE9CC,EAAWC,GAAgC,EAAQ,IAAgB,CACvEJ,EAAW,IAAU,CAAE,GAAGK,GAAOC,GAAMC,CAAM,EAAE,CACjD,EAAG,CAAC,CAAC,EAECC,EAAQJ,MAAkBJ,EAAUE,EAAK,OAAO,EAAG,CAACA,EAAK,OAAO,CAAC,EAEjEO,EAAaC,MAAcR,EAAK,SAASH,CAAM,EAAG,CAACG,EAAMH,CAAM,CAAC,EAwBtE,MAAO,CAAE,SAAQ,WAAU,aAAY,OAvBxBW,MAEXD,EAAW,KACR,GAAOE,MACFC,EAAK,MAAS,CACtB,EACF,CAACH,CAAU,CAiB+B,EAAG,QAf/BA,EAAW,QAe0B,EAAG,QAAO,aAb1CL,EAClB,GAA6C,GAAiB,CAC7DS,EAAE,eAAe,EACjBJ,EAAW,SACH,IAAA,GACL,GAAM,CACLK,EAAaC,CAAC,CAChB,CACF,CACF,EACA,CAACN,CAAU,CAG6D,CAAE,CAC9E"}
|
|
1
|
+
{"version":3,"file":"useValidatedForm.js","names":["useValidatedForm","values","setValues","useState","opts","setField","useCallback","prev","key","value","reset","validation","useMemo","es","List","e","onValid","s"],"sources":["../../src/forms/useValidatedForm.ts"],"sourcesContent":["\"use client\"\n\nimport { List, type List as ListT } from \"functype\"\nimport { type FormEvent, useCallback, useMemo, useState } from \"react\"\n\nimport type { Validated } from \"./Validated\"\n\n/**\n * Form-level state container with applicative error accumulation.\n *\n * The consumer-provided `validate` is the canonical place to accumulate\n * field-level errors. A common pattern:\n *\n * ```ts\n * const validate = (s: Form): Validated<string, Form> => {\n * const errs = List<string>([])\n * .concat(s.email.includes(\"@\") ? List([]) : List([\"email must contain @\"]))\n * .concat(s.age >= 18 ? List([]) : List([\"age must be 18+\"]))\n * return errs.isEmpty ? valid(s) : invalid(errs)\n * }\n * ```\n *\n * `handleSubmit(onValid)` returns an event handler that calls `e.preventDefault()`\n * and only invokes `onValid` when the current form value passes validation.\n */\nexport function useValidatedForm<S extends Record<string, unknown>, E = string>(opts: {\n readonly initial: S\n readonly validate: (s: S) => Validated<E, S>\n}): {\n readonly values: S\n setField: <K extends keyof S>(key: K, value: S[K]) => void\n readonly validation: Validated<E, S>\n readonly errors: ListT<E>\n readonly isValid: boolean\n reset: () => void\n handleSubmit: (onValid: (s: S) => void | Promise<void>) => (e: FormEvent) => void\n} {\n const [values, setValues] = useState<S>(opts.initial)\n\n const setField = useCallback(<K extends keyof S>(key: K, value: S[K]) => {\n setValues((prev) => ({ ...prev, [key]: value }))\n }, [])\n\n const reset = useCallback(() => setValues(opts.initial), [opts.initial])\n\n const validation = useMemo(() => opts.validate(values), [opts, values])\n const errors = useMemo(\n () =>\n validation.fold(\n (es) => es,\n () => List.empty<E>(),\n ),\n [validation],\n )\n const isValid = validation.isRight()\n\n const handleSubmit = useCallback(\n (onValid: (s: S) => void | Promise<void>) => (e: FormEvent) => {\n e.preventDefault()\n validation.fold(\n () => undefined,\n (s) => {\n void onValid(s)\n },\n )\n },\n [validation],\n )\n\n return { values, setField, validation, errors, isValid, reset, handleSubmit }\n}\n"],"mappings":"A,4GAyBA,SAAgBA,EAAgE,EAW9E,CACA,GAAM,CAACC,EAAQC,GAAaC,EAAYC,EAAK,OAAO,EAE9CC,EAAWC,GAAgC,EAAQ,IAAgB,CACvEJ,EAAW,IAAU,CAAE,GAAGK,GAAOC,GAAMC,CAAM,EAAE,CACjD,EAAG,CAAC,CAAC,EAECC,EAAQJ,MAAkBJ,EAAUE,EAAK,OAAO,EAAG,CAACA,EAAK,OAAO,CAAC,EAEjEO,EAAaC,MAAcR,EAAK,SAASH,CAAM,EAAG,CAACG,EAAMH,CAAM,CAAC,EAwBtE,MAAO,CAAE,SAAQ,WAAU,aAAY,OAvBxBW,MAEXD,EAAW,KACR,GAAOE,MACFC,EAAK,MAAS,CACtB,EACF,CAACH,CAAU,CAiB+B,EAAG,QAf/BA,EAAW,QAe0B,EAAG,QAAO,aAb1CL,EAClB,GAA6C,GAAiB,CAC7DS,EAAE,eAAe,EACjBJ,EAAW,SACH,IAAA,GACL,GAAM,CACLK,EAAaC,CAAC,CAChB,CACF,CACF,EACA,CAACN,CAAU,CAG6D,CAAE,CAC9E,C"}
|
package/dist/hooks/eq.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "../eq-
|
|
1
|
+
import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "../eq-CR56QmPb.js";
|
|
2
2
|
export { Eq, referenceEq, structuralEq, tagEq };
|
package/dist/hooks/eq.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eq.js","names":["referenceEq","tagEq","a","b","ta","tb","structuralEq","item","i","ka","kb","k"],"sources":["../../src/hooks/eq.ts"],"sourcesContent":["/**\n * Equality comparators for use with `useStable*` hooks.\n *\n * functype core doesn't ship an Eq typeclass; instead, comparators are passed\n * explicitly. The default everywhere is `referenceEq` (Object.is), matching\n * React's built-in dependency comparison.\n */\n\nexport type Eq<A> = (a: A, b: A) => boolean\n\n/**\n * Reference equality, identical to React's default `Object.is` for hook deps.\n */\nexport const referenceEq: Eq<unknown> = Object.is\n\n/**\n * Compares two functype ADTs by their `_tag` literal only.\n *\n * Useful when you only care about variant changes (e.g., re-render when an\n * `Option` flips between Some and None, but not on payload changes). Returns\n * false for non-tagged values.\n */\nexport const tagEq: Eq<unknown> = (a, b) => {\n if (Object.is(a, b)) return true\n if (typeof a !== \"object\" || a === null) return false\n if (typeof b !== \"object\" || b === null) return false\n const ta = (a as { _tag?: unknown })._tag\n const tb = (b as { _tag?: unknown })._tag\n return ta !== undefined && ta === tb\n}\n\n/**\n * Recursive structural equality. Handles primitives, arrays, plain objects, and\n * tagged ADTs. Cycles are not detected — passing cyclic structures is undefined\n * behavior. Functions compare by reference.\n */\nexport const structuralEq: Eq<unknown> = (a, b) => {\n if (Object.is(a, b)) return true\n if (typeof a !== typeof b) return false\n if (a === null || b === null) return false\n if (typeof a !== \"object\") return false\n\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false\n return a.every((item, i) => structuralEq(item, b[i]))\n }\n if (Array.isArray(b)) return false\n\n const ka = Object.keys(a as object)\n const kb = Object.keys(b as object)\n if (ka.length !== kb.length) return false\n return ka.every(\n (k) =>\n Object.prototype.hasOwnProperty.call(b, k) &&\n structuralEq((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k]),\n )\n}\n"],"mappings":"AAaA,MAAaA,EAA2B,OAAO,GASlCC,GAAsB,EAAG,IAAM,CAC1C,GAAI,OAAO,GAAGC,EAAGC,CAAC,EAAG,MAAO,GAE5B,GADI,OAAOD,GAAM,WAAYA,GACzB,OAAOC,GAAM,WAAYA,EAAY,MAAO,GAChD,IAAMC,EAAMF,EAAyB,KAC/BG,EAAMF,EAAyB,KACrC,OAAOC,IAAO,IAAA,IAAaA,IAAOC,CACpC,EAOaC,GAA6B,EAAG,IAAM,CACjD,GAAI,OAAO,GAAGJ,EAAGC,CAAC,EAAG,MAAO,GAG5B,GAFI,OAAOD,GAAM,OAAOC,GACpBD,IAAM,MAAQC,IAAM,MACpB,OAAOD,GAAM,SAAU,MAAO,GAElC,GAAI,MAAM,QAAQA,CAAC,EAEjB,MADI,CAAC,MAAM,QAAQC,CAAC,GAAKD,EAAE,SAAWC,EAAE,OAAe,GAChDD,EAAE,OAAO,EAAM,IAAMI,EAAaC,EAAMJ,EAAEK,EAAE,CAAC,EAEtD,GAAI,MAAM,QAAQL,CAAC,EAAG,MAAO,GAE7B,IAAMM,EAAK,OAAO,KAAKP,CAAW,EAC5BQ,EAAK,OAAO,KAAKP,CAAW,EAElC,OADIM,EAAG,SAAWC,EAAG,QACdD,EAAG,MACP,GACC,OAAO,UAAU,eAAe,KAAKN,EAAGQ,CAAC,GACzCL,EAAcJ,EAA8BS,GAAKR,EAA8BQ,EAAE,CACrF,CACF"}
|
|
1
|
+
{"version":3,"file":"eq.js","names":["referenceEq","tagEq","a","b","ta","tb","structuralEq","item","i","ka","kb","k"],"sources":["../../src/hooks/eq.ts"],"sourcesContent":["/**\n * Equality comparators for use with `useStable*` hooks.\n *\n * functype core doesn't ship an Eq typeclass; instead, comparators are passed\n * explicitly. The default everywhere is `referenceEq` (Object.is), matching\n * React's built-in dependency comparison.\n */\n\nexport type Eq<A> = (a: A, b: A) => boolean\n\n/**\n * Reference equality, identical to React's default `Object.is` for hook deps.\n */\nexport const referenceEq: Eq<unknown> = Object.is\n\n/**\n * Compares two functype ADTs by their `_tag` literal only.\n *\n * Useful when you only care about variant changes (e.g., re-render when an\n * `Option` flips between Some and None, but not on payload changes). Returns\n * false for non-tagged values.\n */\nexport const tagEq: Eq<unknown> = (a, b) => {\n if (Object.is(a, b)) return true\n if (typeof a !== \"object\" || a === null) return false\n if (typeof b !== \"object\" || b === null) return false\n const ta = (a as { _tag?: unknown })._tag\n const tb = (b as { _tag?: unknown })._tag\n return ta !== undefined && ta === tb\n}\n\n/**\n * Recursive structural equality. Handles primitives, arrays, plain objects, and\n * tagged ADTs. Cycles are not detected — passing cyclic structures is undefined\n * behavior. Functions compare by reference.\n */\nexport const structuralEq: Eq<unknown> = (a, b) => {\n if (Object.is(a, b)) return true\n if (typeof a !== typeof b) return false\n if (a === null || b === null) return false\n if (typeof a !== \"object\") return false\n\n if (Array.isArray(a)) {\n if (!Array.isArray(b) || a.length !== b.length) return false\n return a.every((item, i) => structuralEq(item, b[i]))\n }\n if (Array.isArray(b)) return false\n\n const ka = Object.keys(a as object)\n const kb = Object.keys(b as object)\n if (ka.length !== kb.length) return false\n return ka.every(\n (k) =>\n Object.prototype.hasOwnProperty.call(b, k) &&\n structuralEq((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k]),\n )\n}\n"],"mappings":"AAaA,MAAaA,EAA2B,OAAO,GASlCC,GAAsB,EAAG,IAAM,CAC1C,GAAI,OAAO,GAAGC,EAAGC,CAAC,EAAG,MAAO,GAE5B,GADI,OAAOD,GAAM,WAAYA,GACzB,OAAOC,GAAM,WAAYA,EAAY,MAAO,GAChD,IAAMC,EAAMF,EAAyB,KAC/BG,EAAMF,EAAyB,KACrC,OAAOC,IAAO,IAAA,IAAaA,IAAOC,CACpC,EAOaC,GAA6B,EAAG,IAAM,CACjD,GAAI,OAAO,GAAGJ,EAAGC,CAAC,EAAG,MAAO,GAG5B,GAFI,OAAOD,GAAM,OAAOC,GACpBD,IAAM,MAAQC,IAAM,MACpB,OAAOD,GAAM,SAAU,MAAO,GAElC,GAAI,MAAM,QAAQA,CAAC,EAEjB,MADI,CAAC,MAAM,QAAQC,CAAC,GAAKD,EAAE,SAAWC,EAAE,OAAe,GAChDD,EAAE,OAAO,EAAM,IAAMI,EAAaC,EAAMJ,EAAEK,EAAE,CAAC,EAEtD,GAAI,MAAM,QAAQL,CAAC,EAAG,MAAO,GAE7B,IAAMM,EAAK,OAAO,KAAKP,CAAW,EAC5BQ,EAAK,OAAO,KAAKP,CAAW,EAElC,OADIM,EAAG,SAAWC,EAAG,QACdD,EAAG,MACP,GACC,OAAO,UAAU,eAAe,KAAKN,EAAGQ,CAAC,GACzCL,EAAcJ,EAA8BS,GAAKR,EAA8BQ,EAAE,CACrF,CACF,E"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "../eq-
|
|
2
|
-
import { t as useEither } from "../useEither-
|
|
3
|
-
import { t as useList } from "../useList-
|
|
4
|
-
import { t as useOption } from "../useOption-
|
|
5
|
-
import { t as useStableCallback } from "../useStableCallback-
|
|
6
|
-
import { t as useStableEffect } from "../useStableEffect-
|
|
7
|
-
import { t as useStableMemo } from "../useStableMemo-
|
|
8
|
-
import { t as useStableState } from "../useStableState-
|
|
9
|
-
import { t as useTry } from "../useTry-
|
|
1
|
+
import { i as tagEq, n as referenceEq, r as structuralEq, t as Eq } from "../eq-CR56QmPb.js";
|
|
2
|
+
import { t as useEither } from "../useEither-D1Rn_tLR.js";
|
|
3
|
+
import { t as useList } from "../useList-C_7X5OA_.js";
|
|
4
|
+
import { t as useOption } from "../useOption-B8UyOh8h.js";
|
|
5
|
+
import { t as useStableCallback } from "../useStableCallback-C5jd1hKf.js";
|
|
6
|
+
import { t as useStableEffect } from "../useStableEffect-BiDhoNpC.js";
|
|
7
|
+
import { t as useStableMemo } from "../useStableMemo-DCeNIpt5.js";
|
|
8
|
+
import { t as useStableState } from "../useStableState-BPVQ-XMX.js";
|
|
9
|
+
import { t as useTry } from "../useTry-ie1X0NiH.js";
|
|
10
10
|
export { type Eq, referenceEq, structuralEq, tagEq, useEither, useList, useOption, useStableCallback, useStableEffect, useStableMemo, useStableState, useTry };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useEither } from "../useEither-
|
|
1
|
+
import { t as useEither } from "../useEither-D1Rn_tLR.js";
|
|
2
2
|
export { useEither };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEither.js","names":["useEither","value","setValue","useState","initial","Left","setRight","useCallback","Right","a","setLeft","e","fold","onLeft","onRight","useMemo"],"sources":["../../src/hooks/useEither.ts"],"sourcesContent":["\"use client\"\n\nimport { type Either, Left, Right } from \"functype/either\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful Either container. Defaults to Left(undefined) when no initial.\n */\nexport function useEither<E, A>(\n initial?: Either<E, A>,\n): {\n readonly value: Either<E, A>\n setRight: (a: A) => void\n setLeft: (e: E) => void\n fold: <R>(onLeft: (e: E) => R, onRight: (a: A) => R) => R\n} {\n const [value, setValue] = useState<Either<E, A>>(() => initial ?? Left<E, A>(undefined as unknown as E))\n\n const setRight = useCallback((a: A) => setValue(Right<E, A>(a)), [])\n const setLeft = useCallback((e: E) => setValue(Left<E, A>(e)), [])\n\n const fold = useCallback(<R>(onLeft: (e: E) => R, onRight: (a: A) => R) => value.fold(onLeft, onRight), [value])\n\n return useMemo(() => ({ value, setRight, setLeft, fold }), [value, setRight, setLeft, fold])\n}\n"],"mappings":"8HAQA,SAAgBA,EACd,EAMA,CACA,GAAM,CAACC,EAAOC,GAAYC,MAA6BC,GAAWC,EAAW,IAAA,EAAyB,CAAC,EAEjGC,EAAWC,EAAa,GAASL,EAASM,EAAYC,CAAC,CAAC,EAAG,CAAC,CAAC,EAC7DC,EAAUH,EAAa,GAASL,EAASG,EAAWM,CAAC,CAAC,EAAG,CAAC,CAAC,EAE3DC,EAAOL,GAAgB,EAAqB,IAAyBN,EAAM,KAAKY,EAAQC,CAAO,EAAG,CAACb,CAAK,CAAC,EAE/G,OAAOc,OAAe,CAAE,QAAO,WAAU,UAAS,MAAK,GAAI,CAACd,EAAOK,EAAUI,EAASE,CAAI,CAAC,CAC7F"}
|
|
1
|
+
{"version":3,"file":"useEither.js","names":["useEither","value","setValue","useState","initial","Left","setRight","useCallback","Right","a","setLeft","e","fold","onLeft","onRight","useMemo"],"sources":["../../src/hooks/useEither.ts"],"sourcesContent":["\"use client\"\n\nimport { type Either, Left, Right } from \"functype/either\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful Either container. Defaults to Left(undefined) when no initial.\n */\nexport function useEither<E, A>(\n initial?: Either<E, A>,\n): {\n readonly value: Either<E, A>\n setRight: (a: A) => void\n setLeft: (e: E) => void\n fold: <R>(onLeft: (e: E) => R, onRight: (a: A) => R) => R\n} {\n const [value, setValue] = useState<Either<E, A>>(() => initial ?? Left<E, A>(undefined as unknown as E))\n\n const setRight = useCallback((a: A) => setValue(Right<E, A>(a)), [])\n const setLeft = useCallback((e: E) => setValue(Left<E, A>(e)), [])\n\n const fold = useCallback(<R>(onLeft: (e: E) => R, onRight: (a: A) => R) => value.fold(onLeft, onRight), [value])\n\n return useMemo(() => ({ value, setRight, setLeft, fold }), [value, setRight, setLeft, fold])\n}\n"],"mappings":"A,8HAQA,SAAgBA,EACd,EAMA,CACA,GAAM,CAACC,EAAOC,GAAYC,MAA6BC,GAAWC,EAAW,IAAA,EAAyB,CAAC,EAEjGC,EAAWC,EAAa,GAASL,EAASM,EAAYC,CAAC,CAAC,EAAG,CAAC,CAAC,EAC7DC,EAAUH,EAAa,GAASL,EAASG,EAAWM,CAAC,CAAC,EAAG,CAAC,CAAC,EAE3DC,EAAOL,GAAgB,EAAqB,IAAyBN,EAAM,KAAKY,EAAQC,CAAO,EAAG,CAACb,CAAK,CAAC,EAE/G,OAAOc,OAAe,CAAE,QAAO,WAAU,UAAS,MAAK,GAAI,CAACd,EAAOK,EAAUI,EAASE,CAAI,CAAC,CAC7F,C"}
|
package/dist/hooks/useList.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useList } from "../useList-
|
|
1
|
+
import { t as useList } from "../useList-C_7X5OA_.js";
|
|
2
2
|
export { useList };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.js","names":["useList","value","setValue","useState","List","initial","add","useCallback","prev","a","remove","removeAt","index","clear","map","f","filter","p","useMemo"],"sources":["../../src/hooks/useList.ts"],"sourcesContent":["\"use client\"\n\nimport { List, type List as ListT } from \"functype/list\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful immutable List container. All mutators return new state.\n */\nexport function useList<A>(initial?: readonly A[]): {\n readonly value: ListT<A>\n add: (a: A) => void\n remove: (a: A) => void\n removeAt: (index: number) => void\n clear: () => void\n map: <B>(f: (a: A) => B) => ListT<B>\n filter: (p: (a: A) => boolean) => ListT<A>\n} {\n const [value, setValue] = useState<ListT<A>>(() => List<A>(initial ?? []))\n\n const add = useCallback((a: A) => setValue((prev) => prev.add(a) as ListT<A>), [])\n const remove = useCallback((a: A) => setValue((prev) => prev.remove(a)), [])\n const removeAt = useCallback((index: number) => setValue((prev) => prev.removeAt(index)), [])\n const clear = useCallback(() => setValue(List.empty<A>()), [])\n\n const map = useCallback(<B>(f: (a: A) => B) => value.map(f), [value])\n const filter = useCallback((p: (a: A) => boolean) => value.filter(p), [value])\n\n return useMemo(\n () => ({ value, add, remove, removeAt, clear, map, filter }),\n [value, add, remove, removeAt, clear, map, filter],\n )\n}\n"],"mappings":"iHAQA,SAAgBA,EAAW,EAQzB,CACA,GAAM,CAACC,EAAOC,GAAYC,MAAyBC,EAAQC,GAAW,CAAC,CAAC,CAAC,EAEnEC,EAAMC,EAAa,GAASL,EAAU,GAASM,EAAK,IAAIC,CAAC,CAAa,EAAG,CAAC,CAAC,EAC3EC,EAASH,EAAa,GAASL,EAAU,GAASM,EAAK,OAAOC,CAAC,CAAC,EAAG,CAAC,CAAC,EACrEE,EAAWJ,EAAa,GAAkBL,EAAU,GAASM,EAAK,SAASI,CAAK,CAAC,EAAG,CAAC,CAAC,EACtFC,EAAQN,MAAkBL,EAASE,EAAK,MAAS,CAAC,EAAG,CAAC,CAAC,EAEvDU,EAAMP,EAAgB,GAAmBN,EAAM,IAAIc,CAAC,EAAG,CAACd,CAAK,CAAC,EAC9De,EAAST,EAAa,GAAyBN,EAAM,OAAOgB,CAAC,EAAG,CAAChB,CAAK,CAAC,EAE7E,OAAOiB,OACE,CAAE,QAAO,MAAK,SAAQ,WAAU,QAAO,MAAK,QAAO,GAC1D,CAACjB,EAAOK,EAAKI,EAAQC,EAAUE,EAAOC,EAAKE,CAAM,CACnD,CACF"}
|
|
1
|
+
{"version":3,"file":"useList.js","names":["useList","value","setValue","useState","List","initial","add","useCallback","prev","a","remove","removeAt","index","clear","map","f","filter","p","useMemo"],"sources":["../../src/hooks/useList.ts"],"sourcesContent":["\"use client\"\n\nimport { List, type List as ListT } from \"functype/list\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful immutable List container. All mutators return new state.\n */\nexport function useList<A>(initial?: readonly A[]): {\n readonly value: ListT<A>\n add: (a: A) => void\n remove: (a: A) => void\n removeAt: (index: number) => void\n clear: () => void\n map: <B>(f: (a: A) => B) => ListT<B>\n filter: (p: (a: A) => boolean) => ListT<A>\n} {\n const [value, setValue] = useState<ListT<A>>(() => List<A>(initial ?? []))\n\n const add = useCallback((a: A) => setValue((prev) => prev.add(a) as ListT<A>), [])\n const remove = useCallback((a: A) => setValue((prev) => prev.remove(a)), [])\n const removeAt = useCallback((index: number) => setValue((prev) => prev.removeAt(index)), [])\n const clear = useCallback(() => setValue(List.empty<A>()), [])\n\n const map = useCallback(<B>(f: (a: A) => B) => value.map(f), [value])\n const filter = useCallback((p: (a: A) => boolean) => value.filter(p), [value])\n\n return useMemo(\n () => ({ value, add, remove, removeAt, clear, map, filter }),\n [value, add, remove, removeAt, clear, map, filter],\n )\n}\n"],"mappings":"A,iHAQA,SAAgBA,EAAW,EAQzB,CACA,GAAM,CAACC,EAAOC,GAAYC,MAAyBC,EAAQC,GAAW,CAAC,CAAC,CAAC,EAEnEC,EAAMC,EAAa,GAASL,EAAU,GAASM,EAAK,IAAIC,CAAC,CAAa,EAAG,CAAC,CAAC,EAC3EC,EAASH,EAAa,GAASL,EAAU,GAASM,EAAK,OAAOC,CAAC,CAAC,EAAG,CAAC,CAAC,EACrEE,EAAWJ,EAAa,GAAkBL,EAAU,GAASM,EAAK,SAASI,CAAK,CAAC,EAAG,CAAC,CAAC,EACtFC,EAAQN,MAAkBL,EAASE,EAAK,MAAS,CAAC,EAAG,CAAC,CAAC,EAEvDU,EAAMP,EAAgB,GAAmBN,EAAM,IAAIc,CAAC,EAAG,CAACd,CAAK,CAAC,EAC9De,EAAST,EAAa,GAAyBN,EAAM,OAAOgB,CAAC,EAAG,CAAChB,CAAK,CAAC,EAE7E,OAAOiB,OACE,CAAE,QAAO,MAAK,SAAQ,WAAU,QAAO,MAAK,QAAO,GAC1D,CAACjB,EAAOK,EAAKI,EAAQC,EAAUE,EAAOC,EAAKE,CAAM,CACnD,CACF,C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useOption } from "../useOption-
|
|
1
|
+
import { t as useOption } from "../useOption-B8UyOh8h.js";
|
|
2
2
|
export { useOption };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOption.js","names":["useOption","value","setValue","useState","Option","initial","set","useCallback","a","clear","map","f","fold","onNone","onSome","useMemo"],"sources":["../../src/hooks/useOption.ts"],"sourcesContent":["\"use client\"\n\nimport { Option, type Option as OptionT } from \"functype/option\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful Option container. `set(null | undefined)` clears to None.\n *\n * @interop This hook converts nullable JS values into Option, so `initial` and `set` must accept them.\n */\nexport function useOption<A>(initial?: A): {\n readonly value: OptionT<A>\n set: (a: A | null | undefined) => void\n clear: () => void\n map: <B>(f: (a: A) => B) => OptionT<B>\n fold: <R>(onNone: () => R, onSome: (a: A) => R) => R\n} {\n const [value, setValue] = useState<OptionT<A>>(() => Option<A>(initial))\n\n const set = useCallback((a: A | null | undefined) => setValue(Option<A>(a)), [])\n const clear = useCallback(() => setValue(Option.none<A>()), [])\n\n const map = useCallback(<B>(f: (a: A) => B) => value.map(f), [value])\n const fold = useCallback(<R>(onNone: () => R, onSome: (a: A) => R) => value.fold(onNone, onSome), [value])\n\n return useMemo(() => ({ value, set, clear, map, fold }), [value, set, clear, map, fold])\n}\n"],"mappings":"qHAUA,SAAgBA,EAAa,EAM3B,CACA,GAAM,CAACC,EAAOC,GAAYC,MAA2BC,EAAUC,CAAO,CAAC,EAEjEC,EAAMC,EAAa,GAA4BL,EAASE,EAAUI,CAAC,CAAC,EAAG,CAAC,CAAC,EACzEC,EAAQF,MAAkBL,EAASE,EAAO,KAAQ,CAAC,EAAG,CAAC,CAAC,EAExDM,EAAMH,EAAgB,GAAmBN,EAAM,IAAIU,CAAC,EAAG,CAACV,CAAK,CAAC,EAC9DW,EAAOL,GAAgB,EAAiB,IAAwBN,EAAM,KAAKY,EAAQC,CAAM,EAAG,CAACb,CAAK,CAAC,EAEzG,OAAOc,OAAe,CAAE,QAAO,MAAK,QAAO,MAAK,MAAK,GAAI,CAACd,EAAOK,EAAKG,EAAOC,EAAKE,CAAI,CAAC,CACzF"}
|
|
1
|
+
{"version":3,"file":"useOption.js","names":["useOption","value","setValue","useState","Option","initial","set","useCallback","a","clear","map","f","fold","onNone","onSome","useMemo"],"sources":["../../src/hooks/useOption.ts"],"sourcesContent":["\"use client\"\n\nimport { Option, type Option as OptionT } from \"functype/option\"\nimport { useCallback, useMemo, useState } from \"react\"\n\n/**\n * Stateful Option container. `set(null | undefined)` clears to None.\n *\n * @interop This hook converts nullable JS values into Option, so `initial` and `set` must accept them.\n */\nexport function useOption<A>(initial?: A): {\n readonly value: OptionT<A>\n set: (a: A | null | undefined) => void\n clear: () => void\n map: <B>(f: (a: A) => B) => OptionT<B>\n fold: <R>(onNone: () => R, onSome: (a: A) => R) => R\n} {\n const [value, setValue] = useState<OptionT<A>>(() => Option<A>(initial))\n\n const set = useCallback((a: A | null | undefined) => setValue(Option<A>(a)), [])\n const clear = useCallback(() => setValue(Option.none<A>()), [])\n\n const map = useCallback(<B>(f: (a: A) => B) => value.map(f), [value])\n const fold = useCallback(<R>(onNone: () => R, onSome: (a: A) => R) => value.fold(onNone, onSome), [value])\n\n return useMemo(() => ({ value, set, clear, map, fold }), [value, set, clear, map, fold])\n}\n"],"mappings":"A,qHAUA,SAAgBA,EAAa,EAM3B,CACA,GAAM,CAACC,EAAOC,GAAYC,MAA2BC,EAAUC,CAAO,CAAC,EAEjEC,EAAMC,EAAa,GAA4BL,EAASE,EAAUI,CAAC,CAAC,EAAG,CAAC,CAAC,EACzEC,EAAQF,MAAkBL,EAASE,EAAO,KAAQ,CAAC,EAAG,CAAC,CAAC,EAExDM,EAAMH,EAAgB,GAAmBN,EAAM,IAAIU,CAAC,EAAG,CAACV,CAAK,CAAC,EAC9DW,EAAOL,GAAgB,EAAiB,IAAwBN,EAAM,KAAKY,EAAQC,CAAM,EAAG,CAACb,CAAK,CAAC,EAEzG,OAAOc,OAAe,CAAE,QAAO,MAAK,QAAO,MAAK,MAAK,GAAI,CAACd,EAAOK,EAAKG,EAAOC,EAAKE,CAAI,CAAC,CACzF,C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useStableCallback } from "../useStableCallback-
|
|
1
|
+
import { t as useStableCallback } from "../useStableCallback-C5jd1hKf.js";
|
|
2
2
|
export { useStableCallback };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStableCallback.js","names":["useStableCallback","prev","useRef","tick","deps","stale","eqs","i","referenceEq","d","useCallback","callback"],"sources":["../../src/hooks/useStableCallback.ts"],"sourcesContent":["\"use client\"\n\nimport { type DependencyList, useCallback, useRef } from \"react\"\n\nimport { type Eq, referenceEq } from \"./eq\"\n\n/**\n * Like `useCallback`, but only returns a new function when *some* dep has\n * changed under the supplied (or default) comparator.\n */\nexport function useStableCallback<F extends (...args: never[]) => unknown>(\n callback: F,\n deps: DependencyList,\n // eslint-disable-next-line functype/prefer-option -- an `undefined` slot means \"default equality for this dep\"; replacing it with Eq.default is a 1.x-breaking API change, deferred to 2.0.\n eqs?: ReadonlyArray<Eq<unknown> | undefined>,\n): F {\n const prev = useRef<DependencyList | null>(null)\n const tick = useRef(0)\n\n if (prev.current === null) {\n prev.current = deps\n tick.current += 1\n } else {\n const stale = prev.current\n const changed = deps.some((d, i) => {\n const cmp = eqs?.[i] ?? referenceEq\n return !cmp(stale[i], d)\n })\n if (changed) {\n prev.current = deps\n tick.current += 1\n }\n }\n\n return useCallback(callback, [tick.current]) as F\n}\n"],"mappings":"mGAUA,SAAgBA,EACd,EACA,EAEA,EACG,CACH,IAAMC,EAAOC,EAA8B,IAAI,EACzCC,EAAOD,EAAO,CAAC,EAErB,GAAID,EAAK,UAAY,KACnB,EAAK,QAAUG,EACf,EAAK,SAAW,MACX,CACL,IAAMC,EAAQJ,EAAK,QACHG,EAAK,MAAM,EAAG,IAErB,EADKE,IAAMC,IAAMC,EAAA,CACZH,EAAME,GAAIE,CAAC,CAEf,IACR,EAAK,QAAUL,EACf,EAAK,SAAW,EAEpB,CAEA,OAAOM,EAAYC,EAAU,CAACR,EAAK,OAAO,CAAC,CAC7C"}
|
|
1
|
+
{"version":3,"file":"useStableCallback.js","names":["useStableCallback","prev","useRef","tick","deps","stale","eqs","i","referenceEq","d","useCallback","callback"],"sources":["../../src/hooks/useStableCallback.ts"],"sourcesContent":["\"use client\"\n\nimport { type DependencyList, useCallback, useRef } from \"react\"\n\nimport { type Eq, referenceEq } from \"./eq\"\n\n/**\n * Like `useCallback`, but only returns a new function when *some* dep has\n * changed under the supplied (or default) comparator.\n */\nexport function useStableCallback<F extends (...args: never[]) => unknown>(\n callback: F,\n deps: DependencyList,\n // eslint-disable-next-line functype/prefer-option -- an `undefined` slot means \"default equality for this dep\"; replacing it with Eq.default is a 1.x-breaking API change, deferred to 2.0.\n eqs?: ReadonlyArray<Eq<unknown> | undefined>,\n): F {\n const prev = useRef<DependencyList | null>(null)\n const tick = useRef(0)\n\n if (prev.current === null) {\n prev.current = deps\n tick.current += 1\n } else {\n const stale = prev.current\n const changed = deps.some((d, i) => {\n const cmp = eqs?.[i] ?? referenceEq\n return !cmp(stale[i], d)\n })\n if (changed) {\n prev.current = deps\n tick.current += 1\n }\n }\n\n return useCallback(callback, [tick.current]) as F\n}\n"],"mappings":"A,mGAUA,SAAgBA,EACd,EACA,EAEA,EACG,CACH,IAAMC,EAAOC,EAA8B,IAAI,EACzCC,EAAOD,EAAO,CAAC,EAErB,GAAID,EAAK,UAAY,KACnB,EAAK,QAAUG,EACf,EAAK,SAAW,MACX,CACL,IAAMC,EAAQJ,EAAK,QACHG,EAAK,MAAM,EAAG,IAErB,EADKE,IAAMC,IAAMC,EAAA,CACZH,EAAME,GAAIE,CAAC,CAEf,IACR,EAAK,QAAUL,EACf,EAAK,SAAW,EAEpB,CAEA,OAAOM,EAAYC,EAAU,CAACR,EAAK,OAAO,CAAC,CAC7C,C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useStableEffect } from "../useStableEffect-
|
|
1
|
+
import { t as useStableEffect } from "../useStableEffect-BiDhoNpC.js";
|
|
2
2
|
export { useStableEffect };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStableEffect.js","names":["useStableEffect","prev","useRef","tick","deps","stale","eqs","i","referenceEq","d","useEffect","effect"],"sources":["../../src/hooks/useStableEffect.ts"],"sourcesContent":["\"use client\"\n\nimport { type DependencyList, type EffectCallback, useEffect, useRef } from \"react\"\n\nimport { type Eq, referenceEq } from \"./eq\"\n\n/**\n * Like `useEffect`, but re-runs only when *some* dep has changed under the\n * supplied (or default) comparator. The `eqs` array is aligned positionally\n * with `deps`; missing entries fall back to `referenceEq`.\n *\n * Useful when deps include functype ADTs (`Option`, `Either`, etc.) whose\n * structural identity is what matters, but whose references churn every render.\n */\nexport function useStableEffect(\n effect: EffectCallback,\n deps: DependencyList,\n // eslint-disable-next-line functype/prefer-option -- an `undefined` slot means \"default equality for this dep\"; replacing it with Eq.default is a 1.x-breaking API change, deferred to 2.0.\n eqs?: ReadonlyArray<Eq<unknown> | undefined>,\n): void {\n const prev = useRef<DependencyList | null>(null)\n const tick = useRef(0)\n\n if (prev.current === null) {\n prev.current = deps\n tick.current += 1\n } else {\n const stale = prev.current\n const changed = deps.some((d, i) => {\n const cmp = eqs?.[i] ?? referenceEq\n return !cmp(stale[i], d)\n })\n if (changed) {\n prev.current = deps\n tick.current += 1\n }\n }\n\n useEffect(effect, [tick.current])\n}\n"],"mappings":"iGAcA,SAAgBA,EACd,EACA,EAEA,EACM,CACN,IAAMC,EAAOC,EAA8B,IAAI,EACzCC,EAAOD,EAAO,CAAC,EAErB,GAAID,EAAK,UAAY,KACnB,EAAK,QAAUG,EACf,EAAK,SAAW,MACX,CACL,IAAMC,EAAQJ,EAAK,QACHG,EAAK,MAAM,EAAG,IAErB,EADKE,IAAMC,IAAMC,EAAA,CACZH,EAAME,GAAIE,CAAC,CAEf,IACR,EAAK,QAAUL,EACf,EAAK,SAAW,EAEpB,CAEAM,EAAUC,EAAQ,CAACR,EAAK,OAAO,CAAC,CAClC"}
|
|
1
|
+
{"version":3,"file":"useStableEffect.js","names":["useStableEffect","prev","useRef","tick","deps","stale","eqs","i","referenceEq","d","useEffect","effect"],"sources":["../../src/hooks/useStableEffect.ts"],"sourcesContent":["\"use client\"\n\nimport { type DependencyList, type EffectCallback, useEffect, useRef } from \"react\"\n\nimport { type Eq, referenceEq } from \"./eq\"\n\n/**\n * Like `useEffect`, but re-runs only when *some* dep has changed under the\n * supplied (or default) comparator. The `eqs` array is aligned positionally\n * with `deps`; missing entries fall back to `referenceEq`.\n *\n * Useful when deps include functype ADTs (`Option`, `Either`, etc.) whose\n * structural identity is what matters, but whose references churn every render.\n */\nexport function useStableEffect(\n effect: EffectCallback,\n deps: DependencyList,\n // eslint-disable-next-line functype/prefer-option -- an `undefined` slot means \"default equality for this dep\"; replacing it with Eq.default is a 1.x-breaking API change, deferred to 2.0.\n eqs?: ReadonlyArray<Eq<unknown> | undefined>,\n): void {\n const prev = useRef<DependencyList | null>(null)\n const tick = useRef(0)\n\n if (prev.current === null) {\n prev.current = deps\n tick.current += 1\n } else {\n const stale = prev.current\n const changed = deps.some((d, i) => {\n const cmp = eqs?.[i] ?? referenceEq\n return !cmp(stale[i], d)\n })\n if (changed) {\n prev.current = deps\n tick.current += 1\n }\n }\n\n useEffect(effect, [tick.current])\n}\n"],"mappings":"A,iGAcA,SAAgBA,EACd,EACA,EAEA,EACM,CACN,IAAMC,EAAOC,EAA8B,IAAI,EACzCC,EAAOD,EAAO,CAAC,EAErB,GAAID,EAAK,UAAY,KACnB,EAAK,QAAUG,EACf,EAAK,SAAW,MACX,CACL,IAAMC,EAAQJ,EAAK,QACHG,EAAK,MAAM,EAAG,IAErB,EADKE,IAAMC,IAAMC,EAAA,CACZH,EAAME,GAAIE,CAAC,CAEf,IACR,EAAK,QAAUL,EACf,EAAK,SAAW,EAEpB,CAEAM,EAAUC,EAAQ,CAACR,EAAK,OAAO,CAAC,CAClC,C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as useStableMemo } from "../useStableMemo-
|
|
1
|
+
import { t as useStableMemo } from "../useStableMemo-DCeNIpt5.js";
|
|
2
2
|
export { useStableMemo };
|