@shivaedev/react 0.48.0 → 0.49.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 +13 -0
- package/README.md +11 -14
- package/dist/client/pendingCommand.d.ts +8 -2
- package/dist/client/pendingCommand.d.ts.map +1 -1
- package/dist/client/pendingCommand.js +14 -13
- package/dist/client/pendingCommand.js.map +1 -1
- package/package.json +11 -11
- package/src/client/pendingCommand.ts +25 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.49.0 - 2026-11-18
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- `usePendingCommand` holds the requested value until the command is reflected, when every live query open on the connection shows the server's state after it, in place of waiting for a watched query's next result. A command that changes nothing now frees its control. The hook takes the bound command and its client's runtime where it took an action atom: change `usePendingCommand(toggle(row.id), { queries: [list], value, wanted })`, with `toggle` an `Atom.family` of `ItemsClient.runtime.fn(...)`, to `usePendingCommand({ ...api.toggle, runtime: ItemsClient.runtime }, { value, wanted })`, pass the row's id in the dispatched input and delete the family. `queries` is optional: keep it, as an array with a stable identity, only for queries the client reloads itself, such as those of a `live: false` client. `result`, `data` and `cause` now settle when the command is reflected.
|
|
8
|
+
|
|
9
|
+
## 0.48.1 - 2026-11-18
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Update `@shivaedev/contract` from 0.45.0 to 0.46.0.
|
|
14
|
+
- Update `@shivaedev/identity` from 0.32.1 to 0.32.2.
|
|
15
|
+
|
|
3
16
|
## 0.48.0 - 2026-11-18
|
|
4
17
|
|
|
5
18
|
### Added
|
package/README.md
CHANGED
|
@@ -625,34 +625,31 @@ change.remove({ _tag: "edit", rows: selectedVersions, scale: 0.5, copies: true }
|
|
|
625
625
|
|
|
626
626
|
#### Commands with a pending display value
|
|
627
627
|
|
|
628
|
-
Use `usePendingCommand` for a command acting on a query row, such as a list toggle.
|
|
628
|
+
Use `usePendingCommand` for a command acting on a query row, such as a list toggle. Pass the bound command with its client's runtime, the row's current server value and the display value an input asks for:
|
|
629
629
|
|
|
630
630
|
```tsx
|
|
631
|
-
import * as Atom from "effect/reactivity/Atom";
|
|
632
631
|
import { usePendingCommand } from "@shivaedev/react/client/pendingCommand.ts";
|
|
633
632
|
|
|
634
|
-
const toggle = Atom.family((id: number) => ItemsClient.runtime.fn((input: { readonly enabled: boolean }) => api.toggle.run({ id, ...input })));
|
|
635
|
-
const list = api.list.query();
|
|
636
|
-
|
|
637
633
|
function EnabledToggle({ row }: { readonly row: { readonly id: number; readonly enabled: boolean } }) {
|
|
638
|
-
const command = usePendingCommand(toggle
|
|
639
|
-
queries: [list],
|
|
640
|
-
value: row.enabled,
|
|
641
|
-
wanted: (input) => input.enabled,
|
|
642
|
-
});
|
|
634
|
+
const command = usePendingCommand({ ...api.toggle, runtime: ItemsClient.runtime }, { value: row.enabled, wanted: (input) => input.enabled });
|
|
643
635
|
return (
|
|
644
|
-
<button
|
|
636
|
+
<button
|
|
637
|
+
aria-pressed={command.value}
|
|
638
|
+
disabled={command.pending}
|
|
639
|
+
onClick={() => command.dispatch({ enabled: !command.value, id: row.id })}
|
|
640
|
+
type="button"
|
|
641
|
+
>
|
|
645
642
|
Enabled
|
|
646
643
|
</button>
|
|
647
644
|
);
|
|
648
645
|
}
|
|
649
646
|
```
|
|
650
647
|
|
|
651
|
-
|
|
648
|
+
The example assumes a bound `api.toggle` whose `run` accepts `{ id, enabled }` and its native `ItemsClient`. `run` is the command's identity and must stay the same function between renders, as for `useAction`. Each use of the hook owns its action state, so one row can fail while another keeps its requested display.
|
|
652
649
|
|
|
653
|
-
|
|
650
|
+
`command.value` changes on dispatch and holds the requested value until the command is [reflected](https://github.com/ShivaeDev/platform/blob/main/packages/contract/README.md#when-a-commands-change-is-on-the-screen): every live query open on the connection shows the server's state after it. A switch backed by a live query therefore does not fall back to the old server value between the command's reply and the server's update, and a command that changes nothing frees the switch without an update. `pending` covers that whole interval, and `result`, `data` and `cause` settle when it ends. After the hold ends, `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`. This binding holds a display value; it applies no optimistic update and does not write to the query cache.
|
|
654
651
|
|
|
655
|
-
|
|
652
|
+
Queries the client reloads itself, such as those of a client made with `live: false`, are not part of a command's reflection. List them as `queries`, an array that keeps its identity between renders, and the hold also lasts while any of them is reloading; `result` can then already be successful while `pending` still waits. `queries` adds no invalidations.
|
|
656
653
|
|
|
657
654
|
#### Trace an action across RPCs
|
|
658
655
|
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import { type Effect } from "effect";
|
|
1
2
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
2
3
|
import * as Atom from "effect/reactivity/Atom";
|
|
4
|
+
import type { AtomServices } from "#AtomServices.ts";
|
|
3
5
|
import { type ActionState } from "#client/resultState.ts";
|
|
6
|
+
export interface PendingCommand<TInput, A, E, R, TRuntimeError> {
|
|
7
|
+
readonly run: (input: TInput) => Effect.Effect<A, E, AtomServices<R>>;
|
|
8
|
+
readonly runtime: Atom.AtomRuntime<R, TRuntimeError>;
|
|
9
|
+
}
|
|
4
10
|
export interface PendingCommandOptions<TInput, TValue> {
|
|
5
|
-
readonly queries
|
|
11
|
+
readonly queries?: readonly Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>>[];
|
|
6
12
|
readonly value: TValue;
|
|
7
13
|
readonly wanted: (input: TInput) => TValue;
|
|
8
14
|
}
|
|
9
15
|
export interface PendingCommandState<TInput, A, E, TValue> extends ActionState<TInput, A, E> {
|
|
10
16
|
readonly value: TValue;
|
|
11
17
|
}
|
|
12
|
-
export declare function usePendingCommand<TInput, A, E, TValue>(
|
|
18
|
+
export declare function usePendingCommand<TInput, A, E, R, TRuntimeError, TValue>(command: PendingCommand<TInput, A, E, R, TRuntimeError>, options: PendingCommandOptions<NoInfer<TInput>, TValue>): PendingCommandState<TInput, A, E | TRuntimeError, TValue>;
|
|
13
19
|
//# sourceMappingURL=pendingCommand.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pendingCommand.d.ts","sourceRoot":"","sources":["../../src/client/pendingCommand.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pendingCommand.d.ts","sourceRoot":"","sources":["../../src/client/pendingCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAU,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAG/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,WAAW,EAAa,MAAM,wBAAwB,CAAC;AAErE,MAAM,WAAW,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa;IAC7D,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IACtE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;CACrD;AACD,MAAM,WAAW,qBAAqB,CAAC,MAAM,EAAE,MAAM;IACpD,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;IACnF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AACD,MAAM,WAAW,mBAAmB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAE,SAAQ,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;IAC3F,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAID,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,EAAE,MAAM,EACvE,OAAO,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,EACvD,OAAO,EAAE,qBAAqB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,GACrD,mBAAmB,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,aAAa,EAAE,MAAM,CAAC,CAwB3D"}
|
|
@@ -3,27 +3,28 @@ import { Option } from "effect";
|
|
|
3
3
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
4
4
|
import * as Atom from "effect/reactivity/Atom";
|
|
5
5
|
import { useContext, useMemo, useState } from "react";
|
|
6
|
+
import { untilReflected } from "@shivaedev/contract/commandSignal.ts";
|
|
6
7
|
import { useAction } from "#client/resultState.ts";
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const NO_QUERIES = [];
|
|
9
|
+
export function usePendingCommand(command, options) {
|
|
10
|
+
const { run, runtime } = command;
|
|
11
|
+
const { queries = NO_QUERIES, value, wanted } = options;
|
|
12
|
+
// The reply arrives before the live queries the command changed are updated, so the action ends when the command is reflected.
|
|
13
|
+
const reflected = useMemo(() => (input) => untilReflected(run(input)), [run]);
|
|
14
|
+
const action = useAction(runtime, reflected);
|
|
9
15
|
const registry = useContext(RegistryContext);
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const [held, hold] = useState({ atom, before: results, registry, value: Option.none() });
|
|
14
|
-
const sameOwner = held.atom === atom && held.registry === registry;
|
|
16
|
+
const refreshing = useAtomValue(useMemo(() => Atom.make((get) => queries.some((query) => get(query).waiting)), [queries]));
|
|
17
|
+
const [held, hold] = useState({ reflected, registry, value: Option.none() });
|
|
18
|
+
const sameOwner = held.reflected === reflected && held.registry === registry;
|
|
15
19
|
const failed = AsyncResult.isFailure(action.result) && !action.pending;
|
|
16
|
-
const
|
|
17
|
-
// A live query answers with a pushed Result instead of a reload, so the hold waits for any new settled Result.
|
|
18
|
-
const answered = results.some((result, index) => !result.waiting && result !== held.before[index]);
|
|
19
|
-
const pending = sameOwner && Option.isSome(held.value) && !failed && (action.pending || refreshing || !answered);
|
|
20
|
+
const pending = sameOwner && Option.isSome(held.value) && !failed && (action.pending || refreshing);
|
|
20
21
|
if (!sameOwner || (Option.isSome(held.value) && !pending)) {
|
|
21
|
-
hold({
|
|
22
|
+
hold({ reflected, registry, value: Option.none() });
|
|
22
23
|
}
|
|
23
24
|
return {
|
|
24
25
|
...action,
|
|
25
26
|
dispatch: (input) => {
|
|
26
|
-
hold({
|
|
27
|
+
hold({ reflected, registry, value: Option.some(wanted(input)) });
|
|
27
28
|
action.dispatch(input);
|
|
28
29
|
},
|
|
29
30
|
pending: action.pending || pending,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pendingCommand.js","sourceRoot":"","sources":["../../src/client/pendingCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,
|
|
1
|
+
{"version":3,"file":"pendingCommand.js","sourceRoot":"","sources":["../../src/client/pendingCommand.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.0",
|
|
4
4
|
"description": "React query, action, editor and session hooks for native Effect atoms",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -46,25 +46,25 @@
|
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@shivaedev/access": "0.6.3",
|
|
49
|
-
"@shivaedev/contract": "0.
|
|
49
|
+
"@shivaedev/contract": "0.47.0",
|
|
50
50
|
"@shivaedev/errors": "0.12.0",
|
|
51
51
|
"@shivaedev/form": "0.19.3",
|
|
52
|
-
"@shivaedev/identity": "0.32.
|
|
52
|
+
"@shivaedev/identity": "0.32.3"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@effect/atom-react": "4.1.2",
|
|
56
56
|
"@effect/platform-node": "4.1.2",
|
|
57
57
|
"@effect/sql-pg": "4.1.2",
|
|
58
58
|
"@effect/sql-sqlite-node": "4.1.2",
|
|
59
|
-
"@shivaedev/changes": "0.
|
|
60
|
-
"@shivaedev/jobs": "0.42.
|
|
61
|
-
"@shivaedev/quality": "0.78.
|
|
62
|
-
"@shivaedev/server": "0.
|
|
59
|
+
"@shivaedev/changes": "0.13.0",
|
|
60
|
+
"@shivaedev/jobs": "0.42.4",
|
|
61
|
+
"@shivaedev/quality": "0.78.3",
|
|
62
|
+
"@shivaedev/server": "0.35.1",
|
|
63
63
|
"@shivaedev/service": "0.9.1",
|
|
64
|
-
"@shivaedev/sql": "0.
|
|
65
|
-
"@shivaedev/test-kits": "0.13.
|
|
66
|
-
"@shivaedev/test-sql": "0.25.
|
|
67
|
-
"@shivaedev/test-story": "0.
|
|
64
|
+
"@shivaedev/sql": "0.49.0",
|
|
65
|
+
"@shivaedev/test-kits": "0.13.2",
|
|
66
|
+
"@shivaedev/test-sql": "0.25.2",
|
|
67
|
+
"@shivaedev/test-story": "0.48.0",
|
|
68
68
|
"@tanstack/react-router": "1.170.46",
|
|
69
69
|
"@types/node": "24.19.2",
|
|
70
70
|
"@types/react": "19.3.0",
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { RegistryContext, useAtomValue } from "@effect/atom-react";
|
|
2
|
-
import { Option } from "effect";
|
|
2
|
+
import { type Effect, Option } from "effect";
|
|
3
3
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
4
4
|
import * as Atom from "effect/reactivity/Atom";
|
|
5
5
|
import { useContext, useMemo, useState } from "react";
|
|
6
|
+
import { untilReflected } from "@shivaedev/contract/commandSignal.ts";
|
|
7
|
+
import type { AtomServices } from "#AtomServices.ts";
|
|
6
8
|
import { type ActionState, useAction } from "#client/resultState.ts";
|
|
7
9
|
|
|
10
|
+
export interface PendingCommand<TInput, A, E, R, TRuntimeError> {
|
|
11
|
+
readonly run: (input: TInput) => Effect.Effect<A, E, AtomServices<R>>;
|
|
12
|
+
readonly runtime: Atom.AtomRuntime<R, TRuntimeError>;
|
|
13
|
+
}
|
|
8
14
|
export interface PendingCommandOptions<TInput, TValue> {
|
|
9
|
-
readonly queries
|
|
15
|
+
readonly queries?: readonly Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>>[];
|
|
10
16
|
readonly value: TValue;
|
|
11
17
|
readonly wanted: (input: TInput) => TValue;
|
|
12
18
|
}
|
|
@@ -14,29 +20,30 @@ export interface PendingCommandState<TInput, A, E, TValue> extends ActionState<T
|
|
|
14
20
|
readonly value: TValue;
|
|
15
21
|
}
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
const NO_QUERIES: readonly Atom.Atom<AsyncResult.AsyncResult<unknown, unknown>>[] = [];
|
|
24
|
+
|
|
25
|
+
export function usePendingCommand<TInput, A, E, R, TRuntimeError, TValue>(
|
|
26
|
+
command: PendingCommand<TInput, A, E, R, TRuntimeError>,
|
|
27
|
+
options: PendingCommandOptions<NoInfer<TInput>, TValue>,
|
|
28
|
+
): PendingCommandState<TInput, A, E | TRuntimeError, TValue> {
|
|
29
|
+
const { run, runtime } = command;
|
|
30
|
+
const { queries = NO_QUERIES, value, wanted } = options;
|
|
31
|
+
// The reply arrives before the live queries the command changed are updated, so the action ends when the command is reflected.
|
|
32
|
+
const reflected = useMemo(() => (input: TInput) => untilReflected(run(input)), [run]);
|
|
33
|
+
const action = useAction(runtime, reflected);
|
|
22
34
|
const registry = useContext(RegistryContext);
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const [held, hold] = useState({ atom, before: results, registry, value: Option.none<TValue>() });
|
|
27
|
-
const sameOwner = held.atom === atom && held.registry === registry;
|
|
35
|
+
const refreshing = useAtomValue(useMemo(() => Atom.make((get) => queries.some((query) => get(query).waiting)), [queries]));
|
|
36
|
+
const [held, hold] = useState({ reflected, registry, value: Option.none<TValue>() });
|
|
37
|
+
const sameOwner = held.reflected === reflected && held.registry === registry;
|
|
28
38
|
const failed = AsyncResult.isFailure(action.result) && !action.pending;
|
|
29
|
-
const
|
|
30
|
-
// A live query answers with a pushed Result instead of a reload, so the hold waits for any new settled Result.
|
|
31
|
-
const answered = results.some((result, index) => !result.waiting && result !== held.before[index]);
|
|
32
|
-
const pending = sameOwner && Option.isSome(held.value) && !failed && (action.pending || refreshing || !answered);
|
|
39
|
+
const pending = sameOwner && Option.isSome(held.value) && !failed && (action.pending || refreshing);
|
|
33
40
|
if (!sameOwner || (Option.isSome(held.value) && !pending)) {
|
|
34
|
-
hold({
|
|
41
|
+
hold({ reflected, registry, value: Option.none() });
|
|
35
42
|
}
|
|
36
43
|
return {
|
|
37
44
|
...action,
|
|
38
45
|
dispatch: (input) => {
|
|
39
|
-
hold({
|
|
46
|
+
hold({ reflected, registry, value: Option.some(wanted(input)) });
|
|
40
47
|
action.dispatch(input);
|
|
41
48
|
},
|
|
42
49
|
pending: action.pending || pending,
|