@shivaedev/react 0.45.0 → 0.46.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/CHANGELOG.md +12 -0
- package/README.md +9 -7
- package/dist/client/adapters/SessionGeneration.d.ts +1 -3
- package/dist/client/adapters/SessionGeneration.d.ts.map +1 -1
- package/dist/client/adapters/SessionGeneration.js +3 -3
- package/dist/client/adapters/SessionGeneration.js.map +1 -1
- package/dist/client/mountLive.d.ts +2 -2
- package/dist/client/mountLive.d.ts.map +1 -1
- package/dist/client/mountLive.js +1 -8
- package/dist/client/mountLive.js.map +1 -1
- package/dist/client/resultState.d.ts +1 -2
- package/dist/client/resultState.d.ts.map +1 -1
- package/dist/client/resultState.js +0 -2
- package/dist/client/resultState.js.map +1 -1
- package/dist/client/sessionBoundary.d.ts +2 -3
- package/dist/client/sessionBoundary.d.ts.map +1 -1
- package/dist/client/sessionBoundary.js +1 -2
- package/dist/client/sessionBoundary.js.map +1 -1
- package/package.json +10 -10
- package/src/client/adapters/SessionGeneration.ts +3 -7
- package/src/client/mountLive.ts +2 -11
- package/src/client/resultState.ts +1 -4
- package/src/client/sessionBoundary.ts +1 -4
- package/dist/client/adapters/useLiveWindow.d.ts +0 -4
- package/dist/client/adapters/useLiveWindow.d.ts.map +0 -1
- package/dist/client/adapters/useLiveWindow.js +0 -16
- package/dist/client/adapters/useLiveWindow.js.map +0 -1
- package/dist/registerLiveWindow.d.ts +0 -5
- package/dist/registerLiveWindow.d.ts.map +0 -1
- package/dist/registerLiveWindow.js +0 -31
- package/dist/registerLiveWindow.js.map +0 -1
- package/src/client/adapters/useLiveWindow.ts +0 -17
- package/src/registerLiveWindow.ts +0 -41
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.46.0 - 2026-11-06
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- Live query screens receive server-pushed values. Remove `SessionBoundary.liveCoalesceWindow` and `QueryOptions.coalesceWindow`; server coalescing applies automatically.
|
|
8
|
+
|
|
9
|
+
## 0.45.1 - 2026-11-06
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Update `@shivaedev/identity` from 0.29.1 to 0.29.2.
|
|
14
|
+
|
|
3
15
|
## 0.45.0 - 2026-11-06
|
|
4
16
|
|
|
5
17
|
### Added
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
React screens should not rebuild loading, refresh, save and session rules around every native Effect atom. This package gives queries and actions readable state, joins a record to its editable form, and keeps each session's client state together.
|
|
4
4
|
|
|
5
|
-
Live query screens and route loaders receive their first authorized result on the subscription in one RPC request. Later
|
|
5
|
+
Live query screens and route loaders receive their first authorized result on the subscription in one RPC request. Later matching commits rerun that subscriber’s authorized query on the server and push its changed result.
|
|
6
6
|
|
|
7
7
|
## Why you want this
|
|
8
8
|
|
|
@@ -32,7 +32,9 @@ An **editor** joins a query atom, a form field schema and a save Effect. The que
|
|
|
32
32
|
|
|
33
33
|
Use `useConnectionStatus(client)` from `@shivaedev/react/client/adapters/useConnectionStatus.ts` with the client returned by contract's `makeClient`. It returns one `"live" | "reconnecting" | "waiting-for-connection"` value across mounted queries from every binding on that client's `Client` service. Live subscription status changes debounce for 300 ms on the client runtime's Clock. A bound command held for reconnection reports `"waiting-for-connection"` immediately, so the application can show Reconnecting while keeping the action pending. Contract holds unsent commands for up to 10 seconds and returns a typed `RpcClientError` on timeout; commands already sent are never replayed. The default socket probes Ping/Pong on browser or native resume and reconnects after 2.5 seconds without a Pong. A query refusal is separate from connectivity. Visible browser `online` and `visibilitychange` signals interrupt the live retry delay and reconnect immediately with a fresh backoff schedule.
|
|
34
34
|
|
|
35
|
-
A **session generation** is the string returned by `identify(session)`. `SessionBoundary` owns its client, registry and React subtree. Your auth owner supplies the session and decides when to replace or end it. The boundary automatically mounts live connections on bound contract APIs returned by `connect`, directly or as client properties such as `api`. Use a Platform database host and the default shared WebSocket client; the application needs no subscribe handler or `live()` call.
|
|
35
|
+
A **session generation** is the string returned by `identify(session)`. `SessionBoundary` owns its client, registry and React subtree. Your auth owner supplies the session and decides when to replace or end it. The boundary automatically mounts live connections on bound contract APIs returned by `connect`, directly or as client properties such as `api`. Use a Platform database host and the default shared WebSocket client; the application needs no subscribe handler or `live()` call. The process holding the socket reloads the session and runs the read policy and handler for each subscriber independently. It stores one encoded-result hash per subscribed query in memory and pushes changed values; equal reads acknowledge completion without replacing the screen. Each subscription has at most one rerun in flight and one pending, merging further changes while busy. Other subscriptions run independently in parallel. Backlog overflow and PostgreSQL listener recovery trigger a server `Resync`: the server reruns queries itself, and the client sends no follow-up reads. Query results stay in their native registry; RPC declarations and transport stay with native Effect and the application; this package supplies their React state and lifecycle boundary.
|
|
36
|
+
|
|
37
|
+
An explicit query refresh keeps the current data visible while reporting pending until the new subscription result arrives. Retryable connection failures keep that data visible during reconnection. Render read denials before retained data; replacing or ending the session disposes its registry.
|
|
36
38
|
|
|
37
39
|
Bound contract queries keep their last successful result for five minutes after the last reader leaves. Opening the same query in that window shows the kept value immediately with `stale: true` and `refreshing: true`, then replaces it when revalidation answers. Query execution and subscriptions stop while nobody reads. At most 100 idle results are kept per registry; the least recently left query is evicted first. Active readers do not consume that allowance. Set `queryRetention={{ timeToLive: "1 minute", capacity: 50 }}` on `SessionBoundary` to change these bounds; zero for either disables idle retention. Settings apply when a query becomes idle. Expiry uses the query runtime’s Effect Clock. Signing out or changing `identify(session)` disposes every kept result with the session registry. Results belong to individual queries, with no record sharing between them.
|
|
38
40
|
|
|
@@ -113,7 +115,7 @@ import { SessionBoundary } from "@shivaedev/react/client/sessionBoundary.ts";
|
|
|
113
115
|
|
|
114
116
|
#### Connections with several modules
|
|
115
117
|
|
|
116
|
-
The session boundary finds bound APIs through nested objects and arrays at any depth, including `client.api.notes
|
|
118
|
+
The session boundary finds bound APIs through nested objects and arrays at any depth, including `client.api.notes`. Shared objects and cycles do not mount a binding twice. Use contract's `composeBindings` to select an explicit list instead of discovering the bindings in that object. The client can keep its application modules nested:
|
|
117
119
|
|
|
118
120
|
```ts
|
|
119
121
|
import { composeBindings } from "@shivaedev/contract/composeBindings.ts";
|
|
@@ -562,7 +564,7 @@ const rename = useAction(ReportsClient.runtime, api.rename.run, {
|
|
|
562
564
|
|
|
563
565
|
The command's identity is the native action atom, or the `run` function in the runtime overload. Pass a stable bound function such as `api.rename.run`; memoize wrappers with `useCallback` or `useMemo`. Changing the command on a mounted control keeps `pending` true until its outgoing request settles. Its result, data and cause stay with the outgoing command: a refusal or success from Launch never appears on a replacement Resume control. Resume dispatches its own function and input. Completion callbacks for the outgoing runtime command stop when it is replaced; callbacks for the same command still use the latest committed props.
|
|
564
566
|
|
|
565
|
-
The hook calls the supplied Effect once. A bound contract command still owns invalidation, and completion does not wait for
|
|
567
|
+
The hook calls the supplied Effect once. A bound contract command still owns invalidation, and completion does not wait for server query reruns and their pushed results. Undo payloads, expected versions and presentation text stay in the application.
|
|
566
568
|
|
|
567
569
|
A newer dispatch interrupts the earlier command by default. Interrupted work produces no completion feedback. Pass `{ concurrent: true, onSuccess, onFailure }` to let invocations overlap and report their own outcomes. `result`, `data`, `cause` and `pending` remain the native action atom's aggregate state, including its native result selection during concurrent execution; they do not identify an invocation. Use notice descriptors for per-invocation messages and completion callbacks for application work. Keep the runtime and concurrency policy stable for the same owner.
|
|
568
570
|
|
|
@@ -621,7 +623,7 @@ change.remove({ _tag: "edit", rows: selectedVersions, scale: 0.5, copies: true }
|
|
|
621
623
|
|
|
622
624
|
#### Commands with a pending display value
|
|
623
625
|
|
|
624
|
-
Use `usePendingCommand` for a command acting on a query row, such as a list toggle. Give each row a stable action atom with the existing bound command, so the command's declared invalidation keys still drive
|
|
626
|
+
Use `usePendingCommand` for a command acting on a query row, such as a list toggle. Give each row a stable action atom with the existing bound command, so the command's declared invalidation keys still drive server reruns:
|
|
625
627
|
|
|
626
628
|
```tsx
|
|
627
629
|
import * as Atom from "effect/reactivity/Atom";
|
|
@@ -646,7 +648,7 @@ function EnabledToggle({ row }: { readonly row: { readonly id: number; readonly
|
|
|
646
648
|
|
|
647
649
|
Each row needs its own action atom because the native atom owns its current result, including failures. `Atom.family` keeps an independent action atom stable for each row ID. This lets one row fail while another keeps its requested display through the shared list refetch. Do not share one action atom across independently controlled rows.
|
|
648
650
|
|
|
649
|
-
The example assumes a bound `api.toggle.run` accepting `{ id, enabled }`, a bound list query and their native `ItemsClient`. `queries` lists the query atoms whose
|
|
651
|
+
The example assumes a bound `api.toggle.run` accepting `{ id, enabled }`, a bound list query and their native `ItemsClient`. `queries` lists the query atoms whose next results the display waits for; it does not add invalidations. Include every relevant query and keep the action and query atom identities stable. `value` is the current server value; `wanted(input)` computes the requested display value.
|
|
650
652
|
|
|
651
653
|
`command.value` changes on dispatch and stays at the requested value while the command or any watched query is waiting. `pending` covers that whole interval. After the queries settle, `value` follows the server again, even if it differs from the requested value. A command failure immediately returns to the server value and remains typed in `result` and `cause`, just as with `useAction`. The other action fields describe the native command result, so `result` can already be successful while `pending` still waits for refetches. This binding holds a display value; it does not write to the query cache.
|
|
652
654
|
|
|
@@ -1231,7 +1233,7 @@ const screen = screenDriver({ act, pending, root: view.container, tell: story.te
|
|
|
1231
1233
|
| `pending` | The native result is waiting. |
|
|
1232
1234
|
| `refreshing` | The result is waiting and successful data is available. |
|
|
1233
1235
|
|
|
1234
|
-
`useQuery(atom, options?)` adds `refresh(): void`; `useAction` adds `dispatch(input): void`. `QueryOptions.
|
|
1236
|
+
`useQuery(atom, options?)` adds `refresh(): void`; `useAction` adds `dispatch(input): void`. `QueryOptions.notice` publishes a notice descriptor for a failed result. `QueryOptions.keepPreviousData` defaults to `false` and controls retention across query atom changes. Same-identity refresh retention is always enabled. `result` and `cause` describe the current native query even when `data` displays a previous atom's success. Success, input and typed failure types are inferred from the supplied atom. The Effect overload is `useAction(runtime, run, options?)`, where `ActionOptions` supplies `concurrent`, `notices`, `onSuccess(value, input)` and `onFailure(error, input)`; its shared state also includes the native runtime's typed failure.
|
|
1235
1237
|
|
|
1236
1238
|
Import the defining `.ts` module, such as `@shivaedev/react/client/editor.ts`. There is no root import. `useSessionRecheck()` from `client/sessionBoundary.ts` requests the boundary’s shared session check.
|
|
1237
1239
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type Duration } from "effect";
|
|
2
1
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
2
|
import { type ReactNode } from "react";
|
|
4
3
|
import { type QueryRetentionOptions } from "@shivaedev/contract/queryRetention.ts";
|
|
@@ -6,11 +5,10 @@ interface SessionGenerationProps<TSession, TClient> {
|
|
|
6
5
|
readonly children: (client: TClient) => ReactNode;
|
|
7
6
|
readonly connect: (session: TSession, registry: AtomRegistry.AtomRegistry) => TClient;
|
|
8
7
|
readonly identity: string | undefined;
|
|
9
|
-
readonly liveCoalesceWindow?: Duration.Input | undefined;
|
|
10
8
|
readonly queryRetention?: QueryRetentionOptions | undefined;
|
|
11
9
|
readonly recheck: () => void;
|
|
12
10
|
readonly session: TSession;
|
|
13
11
|
}
|
|
14
|
-
export declare function SessionGeneration<TSession, TClient>({ session, connect, recheck, children, identity,
|
|
12
|
+
export declare function SessionGeneration<TSession, TClient>({ session, connect, recheck, children, identity, queryRetention: retention, }: SessionGenerationProps<TSession, TClient>): ReactNode;
|
|
15
13
|
export {};
|
|
16
14
|
//# sourceMappingURL=SessionGeneration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionGeneration.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/SessionGeneration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SessionGeneration.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/SessionGeneration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAiB,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAG3E,OAAO,EAAE,KAAK,qBAAqB,EAAkB,MAAM,uCAAuC,CAAC;AA6DnG,UAAU,sBAAsB,CAAC,QAAQ,EAAE,OAAO;IACjD,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,SAAS,CAAC;IAClD,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,YAAY,KAAK,OAAO,CAAC;IACtF,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,cAAc,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;CAC3B;AACD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,EACpD,OAAO,EACP,OAAO,EACP,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,cAAc,EAAE,SAAS,GACzB,EAAE,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,SAAS,CA6BvD"}
|
|
@@ -47,7 +47,7 @@ function hidden(connection, identity, retention) {
|
|
|
47
47
|
};
|
|
48
48
|
return owned;
|
|
49
49
|
}
|
|
50
|
-
export function SessionGeneration({ session, connect, recheck, children, identity,
|
|
50
|
+
export function SessionGeneration({ session, connect, recheck, children, identity, queryRetention: retention, }) {
|
|
51
51
|
const recheckLatest = useLatestCallback(recheck);
|
|
52
52
|
const [connection] = useState(() => ({ connect, session }));
|
|
53
53
|
const [owned, own] = useState(() => owning(connection, identity, retention));
|
|
@@ -57,7 +57,7 @@ export function SessionGeneration({ session, connect, recheck, children, identit
|
|
|
57
57
|
useEffect(() => registerSessionRecheck(owned.registry, recheckLatest), [owned, recheckLatest]);
|
|
58
58
|
useEffect(() => {
|
|
59
59
|
owned.mounted += 1;
|
|
60
|
-
const stopLive = Effect.runSync(mountLive(owned.client
|
|
60
|
+
const stopLive = Effect.runSync(mountLive(owned.client).pipe(Effect.provideService(AtomRegistry.AtomRegistry, owned.registry)));
|
|
61
61
|
return () => {
|
|
62
62
|
stopLive();
|
|
63
63
|
owned.mounted -= 1;
|
|
@@ -70,7 +70,7 @@ export function SessionGeneration({ session, connect, recheck, children, identit
|
|
|
70
70
|
own((current) => (current === owned ? hidden(connection, identity, configured) : current));
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
|
-
}, [identity, owned,
|
|
73
|
+
}, [identity, owned, connection]);
|
|
74
74
|
return createElement(RecheckContext.Provider, { value: recheckLatest }, createElement(RegistryContext.Provider, { value: owned.registry }, children(owned.client)));
|
|
75
75
|
}
|
|
76
76
|
//# sourceMappingURL=SessionGeneration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionGeneration.js","sourceRoot":"","sources":["../../../src/client/adapters/SessionGeneration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"SessionGeneration.js","sourceRoot":"","sources":["../../../src/client/adapters/SessionGeneration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAkB,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAA8B,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACnG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,SA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AAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAChI,OAAO,GAAG,EAAE;YACX,QAAQ,EAAE,CAAC;YACX,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;YACnB,cAAc,CAAC,GAAG,EAAE;gBACnB,IAAI,KAAK,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;oBACvB,OAAO;gBACR,CAAC;gBACD,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;gBACtD,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;gBACzB,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5F,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;IAClC,OAAO,aAAa,CACnB,cAAc,CAAC,QAAQ,EACvB,EAAE,KAAK,EAAE,aAAa,EAAE,EACxB,aAAa,CAAC,eAAe,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAC1F,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect } from "effect";
|
|
2
2
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
|
-
export declare const mountLive: (client: unknown
|
|
3
|
+
export declare const mountLive: (client: unknown) => Effect.Effect<() => void, never, AtomRegistry.AtomRegistry>;
|
|
4
4
|
//# sourceMappingURL=mountLive.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mountLive.d.ts","sourceRoot":"","sources":["../../src/client/mountLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,
|
|
1
|
+
{"version":3,"file":"mountLive.d.ts","sourceRoot":"","sources":["../../src/client/mountLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAqB,MAAM,QAAQ,CAAC;AAE1D,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAK/D,eAAO,MAAM,SAAS,2CAyBV,IAAI,mCAKd,CAAC"}
|
package/dist/client/mountLive.js
CHANGED
|
@@ -3,9 +3,8 @@ import * as Atom from "effect/reactivity/Atom";
|
|
|
3
3
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
4
4
|
import { LiveConnection } from "@shivaedev/contract/automaticLive.ts";
|
|
5
5
|
import { liveBindings } from "@shivaedev/contract/composeBindings.ts";
|
|
6
|
-
import { registerLiveWindow } from "#registerLiveWindow.ts";
|
|
7
6
|
import { recheckUnauthorized } from "#sessionRecheck.ts";
|
|
8
|
-
export const mountLive = Effect.fn("Live.mountLive")(function* (client
|
|
7
|
+
export const mountLive = Effect.fn("Live.mountLive")(function* (client) {
|
|
9
8
|
const registry = yield* AtomRegistry.AtomRegistry;
|
|
10
9
|
function recheckFailure(failure) {
|
|
11
10
|
const error = Option.flatMap(failure, Cause.findErrorOption);
|
|
@@ -18,12 +17,6 @@ export const mountLive = Effect.fn("Live.mountLive")(function* (client, coalesce
|
|
|
18
17
|
for (const value of liveBindings(client)) {
|
|
19
18
|
const live = value[LiveConnection];
|
|
20
19
|
if (Predicate.hasProperty(live, "connection") && Atom.isAtom(live.connection) && !found.has(live.connection)) {
|
|
21
|
-
if (coalesceWindow !== undefined
|
|
22
|
-
&& Predicate.hasProperty(live, "coalesceWindow")
|
|
23
|
-
&& Atom.isAtom(live.coalesceWindow)
|
|
24
|
-
&& Atom.isWritable(live.coalesceWindow)) {
|
|
25
|
-
releases.push(yield* registerLiveWindow(live.coalesceWindow, coalesceWindow));
|
|
26
|
-
}
|
|
27
20
|
found.add(live.connection);
|
|
28
21
|
releases.push(registry.subscribe(Atom.map(live.status, (status) => status.failure), (failure) => recheckFailure(failure), { immediate: true }));
|
|
29
22
|
releases.push(registry.mount(live.connection));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mountLive.js","sourceRoot":"","sources":["../../src/client/mountLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"mountLive.js","sourceRoot":"","sources":["../../src/client/mountLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,EAAE,MAAe;IAC9E,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC;IAClD,SAAS,cAAc,CAAC,OAA4C;QACnE,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;QAC7D,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,KAAK,mBAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QACjD,CAAC;IACF,CAAC;IAED,MAAM,QAAQ,GAAsB,EAAE,CAAC;IACvC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAW,CAAC;IACjC,KAAK,MAAM,KAAK,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,GAAG,KAAK,CAAC,cAAc,CAAC,CAAC;QACnC,IAAI,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9G,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC3B,QAAQ,CAAC,IAAI,CACZ,QAAQ,CAAC,SAAS,CACjB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EACjD,CAAC,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,EACpC,EAAE,SAAS,EAAE,IAAI,EAAE,CACnB,CACD,CAAC;YACF,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QAChD,CAAC;IACF,CAAC;IACD,OAAO,GAAS,EAAE;QACjB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAChC,OAAO,EAAE,CAAC;QACX,CAAC;IACF,CAAC,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cause, type
|
|
1
|
+
import { Cause, type Effect, Option } from "effect";
|
|
2
2
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
3
|
import type * as Atom from "effect/reactivity/Atom";
|
|
4
4
|
import type { AtomServices } from "#AtomServices.ts";
|
|
@@ -20,7 +20,6 @@ export interface QueryState<A, E> extends ResultState<A, E> {
|
|
|
20
20
|
readonly stale: boolean;
|
|
21
21
|
}
|
|
22
22
|
export interface QueryOptions<E = unknown> {
|
|
23
|
-
readonly coalesceWindow?: Duration.Input | undefined;
|
|
24
23
|
readonly keepPreviousData?: boolean;
|
|
25
24
|
readonly notice?: (failure: {
|
|
26
25
|
readonly cause: Cause.Cause<E>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resultState.d.ts","sourceRoot":"","sources":["../../src/client/resultState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"resultState.d.ts","sourceRoot":"","sources":["../../src/client/resultState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,EAAa,MAAM,QAAQ,CAAC;AAC/D,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAIpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,uBAAuB,CAAC;AAG5E,MAAM,WAAW,WAAW,CAAC,CAAC,EAAE,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAC/C;AAkBD,MAAM,WAAW,UAAU,CAAC,CAAC,EAAE,CA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CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1G,wBAAgB,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,EACvD,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,aAAa,CAAC,EAC3C,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,EAC5D,OAAO,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GACjE,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC"}
|
|
@@ -6,7 +6,6 @@ import { isUnauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
|
6
6
|
import { usePermissionFailure } from "#adapters/usePermissionFailure.ts";
|
|
7
7
|
import { useQueryNotice } from "#adapters/useQueryNotice.ts";
|
|
8
8
|
import { useActionResult } from "#client/adapters/useActionResult.ts";
|
|
9
|
-
import { useLiveWindow } from "#client/adapters/useLiveWindow.ts";
|
|
10
9
|
import { useActionSource } from "./actionCompletion.js";
|
|
11
10
|
import { useSessionRecheck } from "./sessionBoundary.js";
|
|
12
11
|
function state(result, data = AsyncResult.value(result)) {
|
|
@@ -29,7 +28,6 @@ function useRecheckOnUnauthorized(result, enabled = true) {
|
|
|
29
28
|
export function useQuery(atom, options = {}) {
|
|
30
29
|
const result = useAtomValue(atom);
|
|
31
30
|
const registry = useContext(RegistryContext);
|
|
32
|
-
useLiveWindow(atom, options.coalesceWindow);
|
|
33
31
|
const keepPreviousData = options.keepPreviousData === true;
|
|
34
32
|
const nativeData = AsyncResult.value(result);
|
|
35
33
|
const [held, hold] = useState(() => ({ atom, data: nativeData, dataAtom: atom, keepPreviousData, registry, result }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resultState.js","sourceRoot":"","sources":["../../src/client/resultState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"resultState.js","sourceRoot":"","sources":["../../src/client/resultState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,KAAK,EAAe,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAEtE,OAAO,EAAsB,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AASzD,SAAS,KAAK,CAAO,MAAqC,EAAE,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3F,OAAO;QACN,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC;QAChC,IAAI;QACJ,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,UAAU,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QACjD,MAAM;KACN,CAAC;AACH,CAAC;AACD,SAAS,wBAAwB,CAAO,M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AA4D,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC,CACjH,CACD;QACD,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;KAChF,CAAC;AACH,CAAC;AAUD,MAAM,UAAU,SAAS,CACxB,MAA4E,EAC5E,GAA6D,EAC7D,OAAO,GAAmC,EAAE;IAE5C,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACrC,wBAAwB,CAAC,MAAM,EAAE,GAAG,KAAK,SAAS,CAAC,CAAC;IACpD,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;AACzD,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Effect } from "effect";
|
|
2
2
|
import type * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
3
|
import type * as Atom from "effect/reactivity/Atom";
|
|
4
4
|
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
@@ -8,7 +8,6 @@ export interface SessionBoundaryProps<TSession, TClient> {
|
|
|
8
8
|
readonly children: (client: TClient) => ReactNode;
|
|
9
9
|
readonly connect: (session: TSession, registry: AtomRegistry.AtomRegistry) => TClient;
|
|
10
10
|
readonly identify: (session: TSession) => string;
|
|
11
|
-
readonly liveCoalesceWindow?: Duration.Input | undefined;
|
|
12
11
|
readonly navigate?: ((href: string) => void) | undefined;
|
|
13
12
|
readonly queryRetention?: QueryRetentionOptions | undefined;
|
|
14
13
|
readonly recheck: (() => void) | Effect.Effect<unknown, unknown, AtomRegistry.AtomRegistry>;
|
|
@@ -19,5 +18,5 @@ export interface SessionBoundaryProps<TSession, TClient> {
|
|
|
19
18
|
readonly signOut?: Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>> | undefined;
|
|
20
19
|
}
|
|
21
20
|
export declare function useSessionRecheck(): () => void;
|
|
22
|
-
export declare function SessionBoundary<TSession, TClient>({ session, runtime,
|
|
21
|
+
export declare function SessionBoundary<TSession, TClient>({ session, runtime, queryRetention, identify, connect, recheck, signedOut, signOut, redirectTo, navigate, children, }: SessionBoundaryProps<TSession, TClient>): ReactNode;
|
|
23
22
|
//# sourceMappingURL=sessionBoundary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionBoundary.d.ts","sourceRoot":"","sources":["../../src/client/sessionBoundary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"sessionBoundary.d.ts","sourceRoot":"","sources":["../../src/client/sessionBoundary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAA2B,KAAK,SAAS,EAAc,MAAM,OAAO,CAAC;AAC5E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AASnF,MAAM,WAAW,oBAAoB,CAAC,QAAQ,EAAE,OAAO;IACtD,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,SAAS,CAAC;IAClD,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,CAAC,YAAY,KAAK,OAAO,CAAC;IACtF,QAAQ,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAC;IACjD,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACzD,QAAQ,CAAC,cAAc,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAC5D,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;IAC5F,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,GAAG,SAAS,CAAC;IAC5E,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;CACpF;AACD,wBAAgB,iBAAiB,IAAI,MAAM,IAAI,CAE9C;AACD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,EAClD,OAAO,EACP,OAAO,EACP,cAAc,EACd,QAAQ,EACR,OAAO,EACP,OAAO,EACP,SAAS,EACT,OAAO,EACP,UAAU,EACV,QAAQ,EACR,QAAQ,GACR,EAAE,oBAAoB,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,SAAS,CA6BrD"}
|
|
@@ -11,7 +11,7 @@ import { useDraftOwner } from "./useDraftOwner.js";
|
|
|
11
11
|
export function useSessionRecheck() {
|
|
12
12
|
return useContext(RecheckContext);
|
|
13
13
|
}
|
|
14
|
-
export function SessionBoundary({ session, runtime,
|
|
14
|
+
export function SessionBoundary({ session, runtime, queryRetention, identify, connect, recheck, signedOut, signOut, redirectTo, navigate, children, }) {
|
|
15
15
|
const registry = useContext(RegistryContext);
|
|
16
16
|
const id = session === undefined ? undefined : identify(session);
|
|
17
17
|
const current = useDraftOwner(id);
|
|
@@ -23,7 +23,6 @@ export function SessionBoundary({ session, runtime, liveCoalesceWindow, queryRet
|
|
|
23
23
|
children,
|
|
24
24
|
connect,
|
|
25
25
|
identity: id,
|
|
26
|
-
liveCoalesceWindow,
|
|
27
26
|
queryRetention,
|
|
28
27
|
recheck: retry,
|
|
29
28
|
session,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionBoundary.js","sourceRoot":"","sources":["../../src/client/sessionBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAKrD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAkB,UAAU,EAAE,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"sessionBoundary.js","sourceRoot":"","sources":["../../src/client/sessionBoundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAKrD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAkB,UAAU,EAAE,MAAM,OAAO,CAAC;AAE5E,OAA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IACH,OAAO,aAAa,CACnB,sBAAsB,CAAC,QAAQ,EAC/B,EAAE,KAAK,EAAE,QAAQ,EAAE,EACnB,aAAa,CACZ,mBAAmB,CAAC,QAAQ,EAC5B,EAAE,KAAK,EAAE,OAAO,EAAE,EAClB,aAAa,CACZ,cAAc,EACd,EAAE,GAAG,EAAE,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,EACjC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,UAAU,CAAC,CACnH,CACD,CACD,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "React query, action, editor and session hooks for native Effect atoms",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@shivaedev/access": "0.6.0",
|
|
49
|
-
"@shivaedev/contract": "0.
|
|
49
|
+
"@shivaedev/contract": "0.43.0",
|
|
50
50
|
"@shivaedev/errors": "0.10.0",
|
|
51
51
|
"@shivaedev/form": "0.19.0",
|
|
52
|
-
"@shivaedev/identity": "0.
|
|
52
|
+
"@shivaedev/identity": "0.30.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@effect/atom-react": "4.1.0",
|
|
@@ -57,14 +57,14 @@
|
|
|
57
57
|
"@effect/sql-pg": "4.1.0",
|
|
58
58
|
"@effect/sql-sqlite-node": "4.1.0",
|
|
59
59
|
"@shivaedev/changes": "0.11.0",
|
|
60
|
-
"@shivaedev/jobs": "0.
|
|
61
|
-
"@shivaedev/quality": "0.
|
|
62
|
-
"@shivaedev/server": "0.
|
|
60
|
+
"@shivaedev/jobs": "0.41.0",
|
|
61
|
+
"@shivaedev/quality": "0.69.3",
|
|
62
|
+
"@shivaedev/server": "0.31.0",
|
|
63
63
|
"@shivaedev/service": "0.8.0",
|
|
64
|
-
"@shivaedev/sql": "0.
|
|
65
|
-
"@shivaedev/test-kits": "0.
|
|
66
|
-
"@shivaedev/test-sql": "0.24.
|
|
67
|
-
"@shivaedev/test-story": "0.
|
|
64
|
+
"@shivaedev/sql": "0.45.0",
|
|
65
|
+
"@shivaedev/test-kits": "0.10.0",
|
|
66
|
+
"@shivaedev/test-sql": "0.24.3",
|
|
67
|
+
"@shivaedev/test-story": "0.45.0",
|
|
68
68
|
"@tanstack/react-router": "1.170.46",
|
|
69
69
|
"@types/node": "24.19.2",
|
|
70
70
|
"@types/react": "19.3.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RegistryContext } from "@effect/atom-react";
|
|
2
|
-
import {
|
|
2
|
+
import { Effect } from "effect";
|
|
3
3
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
4
4
|
import { createElement, type ReactNode, useEffect, useState } from "react";
|
|
5
5
|
import { LiveConnection } from "@shivaedev/contract/automaticLive.ts";
|
|
@@ -69,7 +69,6 @@ interface SessionGenerationProps<TSession, TClient> {
|
|
|
69
69
|
readonly children: (client: TClient) => ReactNode;
|
|
70
70
|
readonly connect: (session: TSession, registry: AtomRegistry.AtomRegistry) => TClient;
|
|
71
71
|
readonly identity: string | undefined;
|
|
72
|
-
readonly liveCoalesceWindow?: Duration.Input | undefined;
|
|
73
72
|
readonly queryRetention?: QueryRetentionOptions | undefined;
|
|
74
73
|
readonly recheck: () => void;
|
|
75
74
|
readonly session: TSession;
|
|
@@ -80,7 +79,6 @@ export function SessionGeneration<TSession, TClient>({
|
|
|
80
79
|
recheck,
|
|
81
80
|
children,
|
|
82
81
|
identity,
|
|
83
|
-
liveCoalesceWindow,
|
|
84
82
|
queryRetention: retention,
|
|
85
83
|
}: SessionGenerationProps<TSession, TClient>): ReactNode {
|
|
86
84
|
const recheckLatest = useLatestCallback(recheck);
|
|
@@ -92,9 +90,7 @@ export function SessionGeneration<TSession, TClient>({
|
|
|
92
90
|
useEffect(() => registerSessionRecheck(owned.registry, recheckLatest), [owned, recheckLatest]);
|
|
93
91
|
useEffect(() => {
|
|
94
92
|
owned.mounted += 1;
|
|
95
|
-
const stopLive = Effect.runSync(
|
|
96
|
-
mountLive(owned.client, liveCoalesceWindow).pipe(Effect.provideService(AtomRegistry.AtomRegistry, owned.registry)),
|
|
97
|
-
);
|
|
93
|
+
const stopLive = Effect.runSync(mountLive(owned.client).pipe(Effect.provideService(AtomRegistry.AtomRegistry, owned.registry)));
|
|
98
94
|
return () => {
|
|
99
95
|
stopLive();
|
|
100
96
|
owned.mounted -= 1;
|
|
@@ -107,7 +103,7 @@ export function SessionGeneration<TSession, TClient>({
|
|
|
107
103
|
own((current) => (current === owned ? hidden(connection, identity, configured) : current));
|
|
108
104
|
});
|
|
109
105
|
};
|
|
110
|
-
}, [identity, owned,
|
|
106
|
+
}, [identity, owned, connection]);
|
|
111
107
|
return createElement(
|
|
112
108
|
RecheckContext.Provider,
|
|
113
109
|
{ value: recheckLatest },
|
package/src/client/mountLive.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Cause,
|
|
1
|
+
import { Cause, Effect, Option, Predicate } from "effect";
|
|
2
2
|
import * as Atom from "effect/reactivity/Atom";
|
|
3
3
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
4
4
|
import { LiveConnection } from "@shivaedev/contract/automaticLive.ts";
|
|
5
5
|
import { liveBindings } from "@shivaedev/contract/composeBindings.ts";
|
|
6
|
-
import { registerLiveWindow } from "#registerLiveWindow.ts";
|
|
7
6
|
import { recheckUnauthorized } from "#sessionRecheck.ts";
|
|
8
7
|
|
|
9
|
-
export const mountLive = Effect.fn("Live.mountLive")(function* (client: unknown
|
|
8
|
+
export const mountLive = Effect.fn("Live.mountLive")(function* (client: unknown) {
|
|
10
9
|
const registry = yield* AtomRegistry.AtomRegistry;
|
|
11
10
|
function recheckFailure(failure: Option.Option<Cause.Cause<unknown>>) {
|
|
12
11
|
const error = Option.flatMap(failure, Cause.findErrorOption);
|
|
@@ -20,14 +19,6 @@ export const mountLive = Effect.fn("Live.mountLive")(function* (client: unknown,
|
|
|
20
19
|
for (const value of liveBindings(client)) {
|
|
21
20
|
const live = value[LiveConnection];
|
|
22
21
|
if (Predicate.hasProperty(live, "connection") && Atom.isAtom(live.connection) && !found.has(live.connection)) {
|
|
23
|
-
if (
|
|
24
|
-
coalesceWindow !== undefined
|
|
25
|
-
&& Predicate.hasProperty(live, "coalesceWindow")
|
|
26
|
-
&& Atom.isAtom(live.coalesceWindow)
|
|
27
|
-
&& Atom.isWritable(live.coalesceWindow)
|
|
28
|
-
) {
|
|
29
|
-
releases.push(yield* registerLiveWindow(live.coalesceWindow, coalesceWindow));
|
|
30
|
-
}
|
|
31
22
|
found.add(live.connection);
|
|
32
23
|
releases.push(
|
|
33
24
|
registry.subscribe(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RegistryContext, useAtomRefresh, useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
2
|
-
import { Cause, type
|
|
2
|
+
import { Cause, type Effect, Option, Predicate } from "effect";
|
|
3
3
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
4
4
|
import type * as Atom from "effect/reactivity/Atom";
|
|
5
5
|
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
@@ -9,7 +9,6 @@ import type { AtomServices } from "#AtomServices.ts";
|
|
|
9
9
|
import { usePermissionFailure } from "#adapters/usePermissionFailure.ts";
|
|
10
10
|
import { useQueryNotice } from "#adapters/useQueryNotice.ts";
|
|
11
11
|
import { useActionResult } from "#client/adapters/useActionResult.ts";
|
|
12
|
-
import { useLiveWindow } from "#client/adapters/useLiveWindow.ts";
|
|
13
12
|
import type { NoticeDescriptor } from "#notices.ts";
|
|
14
13
|
import { type ActionOptions, useActionSource } from "./actionCompletion.ts";
|
|
15
14
|
import { useSessionRecheck } from "./sessionBoundary.ts";
|
|
@@ -45,7 +44,6 @@ export interface QueryState<A, E> extends ResultState<A, E> {
|
|
|
45
44
|
readonly stale: boolean;
|
|
46
45
|
}
|
|
47
46
|
export interface QueryOptions<E = unknown> {
|
|
48
|
-
readonly coalesceWindow?: Duration.Input | undefined;
|
|
49
47
|
readonly keepPreviousData?: boolean;
|
|
50
48
|
readonly notice?: (failure: { readonly cause: Cause.Cause<E>; readonly refreshing: boolean }) => NoticeDescriptor | undefined;
|
|
51
49
|
}
|
|
@@ -60,7 +58,6 @@ interface HeldQuery<A, E> {
|
|
|
60
58
|
export function useQuery<A, E>(atom: Atom.Atom<AsyncResult.AsyncResult<A, E>>, options: QueryOptions<E> = {}): QueryState<A, E> {
|
|
61
59
|
const result = useAtomValue(atom);
|
|
62
60
|
const registry = useContext(RegistryContext);
|
|
63
|
-
useLiveWindow(atom, options.coalesceWindow);
|
|
64
61
|
const keepPreviousData = options.keepPreviousData === true;
|
|
65
62
|
const nativeData = AsyncResult.value(result);
|
|
66
63
|
const [held, hold] = useState<HeldQuery<A, E>>(() => ({ atom, data: nativeData, dataAtom: atom, keepPreviousData, registry, result }));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RegistryContext } from "@effect/atom-react";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Effect } from "effect";
|
|
3
3
|
import type * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
4
4
|
import type * as Atom from "effect/reactivity/Atom";
|
|
5
5
|
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
@@ -17,7 +17,6 @@ export interface SessionBoundaryProps<TSession, TClient> {
|
|
|
17
17
|
readonly children: (client: TClient) => ReactNode;
|
|
18
18
|
readonly connect: (session: TSession, registry: AtomRegistry.AtomRegistry) => TClient;
|
|
19
19
|
readonly identify: (session: TSession) => string;
|
|
20
|
-
readonly liveCoalesceWindow?: Duration.Input | undefined;
|
|
21
20
|
readonly navigate?: ((href: string) => void) | undefined;
|
|
22
21
|
readonly queryRetention?: QueryRetentionOptions | undefined;
|
|
23
22
|
readonly recheck: (() => void) | Effect.Effect<unknown, unknown, AtomRegistry.AtomRegistry>;
|
|
@@ -33,7 +32,6 @@ export function useSessionRecheck(): () => void {
|
|
|
33
32
|
export function SessionBoundary<TSession, TClient>({
|
|
34
33
|
session,
|
|
35
34
|
runtime,
|
|
36
|
-
liveCoalesceWindow,
|
|
37
35
|
queryRetention,
|
|
38
36
|
identify,
|
|
39
37
|
connect,
|
|
@@ -55,7 +53,6 @@ export function SessionBoundary<TSession, TClient>({
|
|
|
55
53
|
children,
|
|
56
54
|
connect,
|
|
57
55
|
identity: id,
|
|
58
|
-
liveCoalesceWindow,
|
|
59
56
|
queryRetention,
|
|
60
57
|
recheck: retry,
|
|
61
58
|
session,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLiveWindow.d.ts","sourceRoot":"","sources":["../../../src/client/adapters/useLiveWindow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAU,MAAM,QAAQ,CAAC;AAC/C,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAMpD,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,KAAK,GAAG,SAAS,GAAG,IAAI,CAQhG"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { RegistryContext } from "@effect/atom-react";
|
|
2
|
-
import { Effect } from "effect";
|
|
3
|
-
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
4
|
-
import { useContext, useEffect } from "react";
|
|
5
|
-
import { queryCoalesceWindow } from "@shivaedev/contract/queryCoalesceWindow.ts";
|
|
6
|
-
import { registerLiveWindow } from "#registerLiveWindow.ts";
|
|
7
|
-
export function useLiveWindow(atom, window) {
|
|
8
|
-
const registry = useContext(RegistryContext);
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
if (window === undefined) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
return Effect.runSync(registerLiveWindow(queryCoalesceWindow(atom), window).pipe(Effect.provideService(AtomRegistry.AtomRegistry, registry)));
|
|
14
|
-
}, [registry, atom, window]);
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=useLiveWindow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLiveWindow.js","sourceRoot":"","sources":["../../../src/client/adapters/useLiveWindow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAiB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,UAAU,aAAa,CAAC,IAAwB,EAAE,MAAkC;IACzF,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAC7C,SAAS,CAAC,GAAG,EAAE;QACd,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO;QACR,CAAC;QACD,OAAO,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC/I,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { type Duration, Effect } from "effect";
|
|
2
|
-
import type * as Atom from "effect/reactivity/Atom";
|
|
3
|
-
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
4
|
-
export declare const registerLiveWindow: <A extends Duration.Input | undefined>(atom: Atom.Writable<A, A>, value: A) => Effect.Effect<() => void, never, AtomRegistry.AtomRegistry>;
|
|
5
|
-
//# sourceMappingURL=registerLiveWindow.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registerLiveWindow.d.ts","sourceRoot":"","sources":["../src/registerLiveWindow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAS/D,eAAO,MAAM,kBAAkB,GAAyD,CAAC,SAAS,QAAQ,CAAC,KAAK,GAAG,SAAS,qGA6B1H,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
|
-
const registries = new WeakMap();
|
|
4
|
-
export const registerLiveWindow = Effect.fn("LiveWindow.registerLiveWindow")(function* (atom, value) {
|
|
5
|
-
const registry = yield* AtomRegistry.AtomRegistry;
|
|
6
|
-
let windows = registries.get(registry);
|
|
7
|
-
if (windows === undefined) {
|
|
8
|
-
windows = new WeakMap();
|
|
9
|
-
registries.set(registry, windows);
|
|
10
|
-
}
|
|
11
|
-
let current = windows.get(atom);
|
|
12
|
-
if (current === undefined) {
|
|
13
|
-
const original = registry.get(atom);
|
|
14
|
-
current = { readers: new Map(), restore: () => registry.set(atom, original) };
|
|
15
|
-
windows.set(atom, current);
|
|
16
|
-
}
|
|
17
|
-
const reader = {};
|
|
18
|
-
function apply() {
|
|
19
|
-
registry.set(atom, value);
|
|
20
|
-
}
|
|
21
|
-
current.readers.set(reader, apply);
|
|
22
|
-
apply();
|
|
23
|
-
return () => {
|
|
24
|
-
current.readers.delete(reader);
|
|
25
|
-
([...current.readers.values()].at(-1) ?? current.restore)();
|
|
26
|
-
if (current.readers.size === 0) {
|
|
27
|
-
windows.delete(atom);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
//# sourceMappingURL=registerLiveWindow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registerLiveWindow.js","sourceRoot":"","sources":["../src/registerLiveWindow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAO/D,MAAM,UAAU,GAAG,IAAI,OAAO,EAAmE,CAAC;AAElG,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,EAAE,CAAC,+BAA+B,CAAC,CAAC,QAAQ,CAAC,EACrF,IAAsB,EACtB,KAAQ;IAER,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC;IAClD,IAAI,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACvC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;QACxB,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC;IACD,IAAI,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,OAAO,GAAG,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;QAC9E,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5B,CAAC;IACD,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,SAAS,KAAK;QACb,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnC,KAAK,EAAE,CAAC;IACR,OAAO,GAAG,EAAE;QACX,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/B,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5D,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;IACF,CAAC,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { RegistryContext } from "@effect/atom-react";
|
|
2
|
-
import { type Duration, Effect } from "effect";
|
|
3
|
-
import type * as Atom from "effect/reactivity/Atom";
|
|
4
|
-
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
5
|
-
import { useContext, useEffect } from "react";
|
|
6
|
-
import { queryCoalesceWindow } from "@shivaedev/contract/queryCoalesceWindow.ts";
|
|
7
|
-
import { registerLiveWindow } from "#registerLiveWindow.ts";
|
|
8
|
-
|
|
9
|
-
export function useLiveWindow(atom: Atom.Atom<unknown>, window: Duration.Input | undefined): void {
|
|
10
|
-
const registry = useContext(RegistryContext);
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (window === undefined) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
return Effect.runSync(registerLiveWindow(queryCoalesceWindow(atom), window).pipe(Effect.provideService(AtomRegistry.AtomRegistry, registry)));
|
|
16
|
-
}, [registry, atom, window]);
|
|
17
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type Duration, Effect } from "effect";
|
|
2
|
-
import type * as Atom from "effect/reactivity/Atom";
|
|
3
|
-
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
4
|
-
|
|
5
|
-
interface Windows {
|
|
6
|
-
readonly readers: Map<object, () => void>;
|
|
7
|
-
readonly restore: () => void;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const registries = new WeakMap<AtomRegistry.AtomRegistry, WeakMap<Atom.Atom<unknown>, Windows>>();
|
|
11
|
-
|
|
12
|
-
export const registerLiveWindow = Effect.fn("LiveWindow.registerLiveWindow")(function* <A extends Duration.Input | undefined>(
|
|
13
|
-
atom: Atom.Writable<A>,
|
|
14
|
-
value: A,
|
|
15
|
-
) {
|
|
16
|
-
const registry = yield* AtomRegistry.AtomRegistry;
|
|
17
|
-
let windows = registries.get(registry);
|
|
18
|
-
if (windows === undefined) {
|
|
19
|
-
windows = new WeakMap();
|
|
20
|
-
registries.set(registry, windows);
|
|
21
|
-
}
|
|
22
|
-
let current = windows.get(atom);
|
|
23
|
-
if (current === undefined) {
|
|
24
|
-
const original = registry.get(atom);
|
|
25
|
-
current = { readers: new Map(), restore: () => registry.set(atom, original) };
|
|
26
|
-
windows.set(atom, current);
|
|
27
|
-
}
|
|
28
|
-
const reader = {};
|
|
29
|
-
function apply() {
|
|
30
|
-
registry.set(atom, value);
|
|
31
|
-
}
|
|
32
|
-
current.readers.set(reader, apply);
|
|
33
|
-
apply();
|
|
34
|
-
return () => {
|
|
35
|
-
current.readers.delete(reader);
|
|
36
|
-
([...current.readers.values()].at(-1) ?? current.restore)();
|
|
37
|
-
if (current.readers.size === 0) {
|
|
38
|
-
windows.delete(atom);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
});
|