@fozy-labs/rx-toolkit 0.5.4 → 0.6.2
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/LICENSE +1 -1
- package/README.md +22 -13
- package/dist/common/devtools/reduxDevtools.js +17 -2
- package/dist/common/react/index.d.ts +1 -0
- package/dist/common/react/index.js +1 -0
- package/dist/common/react/useIsomorphicLayoutEffect.d.ts +17 -0
- package/dist/common/react/useIsomorphicLayoutEffect.js +17 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/query/api/createApi.d.ts +4 -0
- package/dist/query/api/createApi.js +9 -0
- package/dist/query/api/index.d.ts +1 -0
- package/dist/query/api/index.js +1 -0
- package/dist/query/constants.d.ts +12 -0
- package/dist/query/constants.js +15 -0
- package/dist/query/core/api/Api.d.ts +20 -0
- package/dist/query/core/api/Api.js +129 -0
- package/dist/query/core/api/constants.d.ts +2 -0
- package/dist/query/core/api/constants.js +3 -0
- package/dist/query/core/api/index.d.ts +3 -0
- package/dist/query/core/api/index.js +3 -0
- package/dist/query/core/api/mergeHooks.d.ts +2 -0
- package/dist/query/core/api/mergeHooks.js +26 -0
- package/dist/query/core/api/normalizeLinks.d.ts +2 -0
- package/dist/query/core/api/normalizeLinks.js +11 -0
- package/dist/query/core/cache/CacheEntry.d.ts +21 -0
- package/dist/query/core/cache/CacheEntry.js +54 -0
- package/dist/query/core/cache/CacheMap.d.ts +19 -0
- package/dist/query/core/cache/CacheMap.js +32 -0
- package/dist/query/core/cache/QueryCacheEntry.d.ts +21 -0
- package/dist/query/core/cache/QueryCacheEntry.js +136 -0
- package/dist/query/core/cache/index.d.ts +3 -0
- package/dist/query/core/cache/index.js +3 -0
- package/dist/query/core/command/Command.d.ts +67 -0
- package/dist/query/core/command/Command.js +253 -0
- package/dist/query/core/command/CommandAgent.d.ts +17 -0
- package/dist/query/core/command/CommandAgent.js +67 -0
- package/dist/query/core/command/LinkManager.d.ts +24 -0
- package/dist/query/core/command/LinkManager.js +71 -0
- package/dist/query/core/command/index.d.ts +2 -0
- package/dist/query/core/command/index.js +2 -0
- package/dist/query/core/errors/CacheEntryRemovedError.d.ts +7 -0
- package/dist/query/core/errors/CacheEntryRemovedError.js +9 -0
- package/dist/query/core/errors/MachineStateError.d.ts +8 -0
- package/dist/query/core/errors/MachineStateError.js +10 -0
- package/dist/query/core/errors/MachineTransitionError.d.ts +7 -0
- package/dist/query/core/errors/MachineTransitionError.js +9 -0
- package/dist/query/core/errors/index.d.ts +3 -0
- package/dist/query/core/errors/index.js +3 -0
- package/dist/query/core/index.d.ts +8 -0
- package/dist/query/core/index.js +8 -0
- package/dist/query/core/machine/Machine.d.ts +21 -0
- package/dist/query/core/machine/Machine.js +42 -0
- package/dist/query/core/machine/MachineBase.d.ts +31 -0
- package/dist/query/core/machine/MachineBase.js +176 -0
- package/dist/query/core/machine/MachineError.d.ts +10 -0
- package/dist/query/core/machine/MachineError.js +19 -0
- package/dist/query/core/machine/MachinePending.d.ts +13 -0
- package/dist/query/core/machine/MachinePending.js +32 -0
- package/dist/query/core/machine/MachineRefreshError.d.ts +12 -0
- package/dist/query/core/machine/MachineRefreshError.js +23 -0
- package/dist/query/core/machine/MachineRefreshing.d.ts +15 -0
- package/dist/query/core/machine/MachineRefreshing.js +43 -0
- package/dist/query/core/machine/MachineSuccess.d.ts +12 -0
- package/dist/query/core/machine/MachineSuccess.js +23 -0
- package/dist/query/core/machine/MachineWithData.d.ts +25 -0
- package/dist/query/core/machine/MachineWithData.js +73 -0
- package/dist/query/core/machine/index.d.ts +9 -0
- package/dist/query/core/machine/index.js +9 -0
- package/dist/query/core/machine/machine-helpers.d.ts +9 -0
- package/dist/query/core/machine/machine-helpers.js +80 -0
- package/dist/query/core/patcher/Patcher.d.ts +30 -0
- package/dist/query/core/patcher/Patcher.js +122 -0
- package/dist/query/core/patcher/index.d.ts +1 -0
- package/dist/query/core/patcher/index.js +1 -0
- package/dist/query/core/resource/Resource.d.ts +105 -0
- package/dist/query/core/resource/Resource.js +340 -0
- package/dist/query/core/resource/ResourceAgent.d.ts +37 -0
- package/dist/query/core/resource/ResourceAgent.js +179 -0
- package/dist/query/core/resource/index.d.ts +2 -0
- package/dist/query/core/resource/index.js +2 -0
- package/dist/query/core/snapshoter/Snapshoter.d.ts +22 -0
- package/dist/query/core/snapshoter/Snapshoter.js +78 -0
- package/dist/query/core/snapshoter/index.d.ts +2 -0
- package/dist/query/core/snapshoter/index.js +1 -0
- package/dist/query/core/syncer/Syncer.d.ts +32 -0
- package/dist/query/core/syncer/Syncer.js +85 -0
- package/dist/query/core/syncer/index.d.ts +2 -0
- package/dist/query/core/syncer/index.js +1 -0
- package/dist/query/index.d.ts +5 -10
- package/dist/query/index.js +5 -13
- package/dist/query/lib/broadcastSyncDriver.d.ts +5 -0
- package/dist/query/lib/broadcastSyncDriver.js +46 -0
- package/dist/query/lib/index.d.ts +3 -0
- package/dist/query/lib/index.js +3 -0
- package/dist/{query-v2 → query}/lib/stableStringify.js +5 -3
- package/dist/query/lib/toKeyed.d.ts +11 -0
- package/dist/query/lib/toKeyed.js +18 -0
- package/dist/query/react/ReactHooksPlugin.d.ts +31 -0
- package/dist/query/react/ReactHooksPlugin.js +21 -0
- package/dist/query/react/index.d.ts +3 -0
- package/dist/query/react/index.js +3 -0
- package/dist/query/react/useCommand.d.ts +2 -0
- package/dist/query/react/useCommand.js +14 -0
- package/dist/query/react/useResource.d.ts +2 -0
- package/dist/query/react/useResource.js +16 -0
- package/dist/query/types/api.d.ts +39 -0
- package/dist/query/types/cache.d.ts +51 -0
- package/dist/query/types/command.d.ts +52 -0
- package/dist/query/types/common.d.ts +65 -0
- package/dist/query/types/index.d.ts +8 -4
- package/dist/query/types/index.js +8 -5
- package/dist/query/types/plugin-hkt.d.ts +64 -0
- package/dist/query/types/resource.d.ts +49 -0
- package/dist/query/types/snapshot.d.ts +27 -0
- package/dist/query/types/snapshot.js +2 -0
- package/dist/query/types/state.d.ts +24 -0
- package/dist/signals/base/ComputeCache.js +1 -1
- package/dist/signals/base/Devtools.js +2 -6
- package/dist/signals/signals/Computed.d.ts +1 -0
- package/dist/signals/signals/Computed.js +5 -1
- package/dist/signals/signals/Effect.d.ts +0 -4
- package/dist/signals/signals/Effect.js +0 -6
- package/dist/signals/signals/LocalState.d.ts +1 -10
- package/dist/signals/signals/LocalState.js +0 -12
- package/dist/signals/signals/Signal.d.ts +2 -8
- package/dist/signals/signals/Signal.js +1 -10
- package/dist/signals/signals/State.d.ts +2 -1
- package/dist/signals/signals/State.js +9 -0
- package/dist/signals/types/SignalOptions.d.ts +0 -2
- package/dist/signals/types/normalizeSignalOptions.js +0 -3
- package/dist/signals/types/signals.types.d.ts +3 -1
- package/docs/CHANGELOG.md +54 -2
- package/docs/contributing/release/README.md +2 -8
- package/docs/migrations/0.6.0.md +224 -0
- package/docs/query/README.md +52 -562
- package/docs/query/api/README.md +59 -0
- package/docs/query/api/_CacheEntry.md +39 -0
- package/docs/query/api/_CacheMap.md +30 -0
- package/docs/query/api/_QueryCacheEntry.md +81 -0
- package/docs/query/api/command-agent.md +60 -0
- package/docs/query/api/command.md +76 -0
- package/docs/query/api/resource-agent.md +68 -0
- package/docs/query/api/resource.md +77 -0
- package/docs/query/concepts/agent.md +70 -0
- package/docs/query/concepts/architecture.md +139 -0
- package/docs/query/concepts/cache.md +81 -0
- package/docs/query/concepts/dataflows.md +473 -0
- package/docs/query/concepts/keyed.md +42 -0
- package/docs/query/concepts/machine.md +106 -0
- package/docs/query/concepts/patching.md +85 -0
- package/docs/query/usage/broadcast.md +188 -0
- package/docs/query/usage/command.md +203 -0
- package/docs/query/usage/lifecycle.md +114 -0
- package/docs/query/usage/links.md +125 -0
- package/docs/query/usage/plugins.md +96 -0
- package/docs/query/usage/resource.md +206 -0
- package/docs/query/usage/snapshot.md +80 -0
- package/docs/usage/react/README.md +45 -91
- package/package.json +5 -7
- package/dist/query/SKIP_TOKEN.d.ts +0 -1
- package/dist/query/SKIP_TOKEN.js +0 -1
- package/dist/query/api/createCommand.d.ts +0 -21
- package/dist/query/api/createCommand.js +0 -20
- package/dist/query/api/createOperation.d.ts +0 -5
- package/dist/query/api/createOperation.js +0 -6
- package/dist/query/api/createResource.d.ts +0 -3
- package/dist/query/api/createResource.js +0 -2
- package/dist/query/api/createResourceDuplicator.d.ts +0 -4
- package/dist/query/api/createResourceDuplicator.js +0 -2
- package/dist/query/api/resetAllQueriesCache.d.ts +0 -1
- package/dist/query/api/resetAllQueriesCache.js +0 -4
- package/dist/query/core/Command/Command.d.ts +0 -35
- package/dist/query/core/Command/Command.js +0 -210
- package/dist/query/core/Command/CommandAgent.d.ts +0 -19
- package/dist/query/core/Command/CommandAgent.js +0 -54
- package/dist/query/core/Command/index.d.ts +0 -2
- package/dist/query/core/Command/index.js +0 -2
- package/dist/query/core/Operation/Operation.d.ts +0 -8
- package/dist/query/core/Operation/Operation.js +0 -4
- package/dist/query/core/Operation/OperationAgent.d.ts +0 -4
- package/dist/query/core/Operation/OperationAgent.js +0 -4
- package/dist/query/core/QueriesCache.d.ts +0 -9
- package/dist/query/core/QueriesCache.js +0 -28
- package/dist/query/core/QueriesLifetimeHooks.d.ts +0 -22
- package/dist/query/core/QueriesLifetimeHooks.js +0 -86
- package/dist/query/core/ResetAllQueriesSignal.d.ts +0 -6
- package/dist/query/core/ResetAllQueriesSignal.js +0 -11
- package/dist/query/core/Resource/Resource.d.ts +0 -51
- package/dist/query/core/Resource/Resource.js +0 -232
- package/dist/query/core/Resource/ResourceAgent.d.ts +0 -35
- package/dist/query/core/Resource/ResourceAgent.js +0 -110
- package/dist/query/core/Resource/ResourceDuplicator.d.ts +0 -73
- package/dist/query/core/Resource/ResourceDuplicator.js +0 -227
- package/dist/query/core/Resource/ResourceDuplicatorAgent.d.ts +0 -35
- package/dist/query/core/Resource/ResourceDuplicatorAgent.js +0 -110
- package/dist/query/core/Resource/ResourceRef.d.ts +0 -16
- package/dist/query/core/Resource/ResourceRef.js +0 -136
- package/dist/query/lib/IndirectMap.d.ts +0 -19
- package/dist/query/lib/IndirectMap.js +0 -88
- package/dist/query/lib/ReactiveCache.d.ts +0 -62
- package/dist/query/lib/ReactiveCache.js +0 -80
- package/dist/query/react/useCommandAgent.d.ts +0 -24
- package/dist/query/react/useCommandAgent.js +0 -39
- package/dist/query/react/useOperationAgent.d.ts +0 -6
- package/dist/query/react/useOperationAgent.js +0 -6
- package/dist/query/react/useResourceAgent.d.ts +0 -6
- package/dist/query/react/useResourceAgent.js +0 -31
- package/dist/query/react/useResourceRef.d.ts +0 -5
- package/dist/query/react/useResourceRef.js +0 -13
- package/dist/query/types/Command.types.d.ts +0 -154
- package/dist/query/types/Command.types.js +0 -1
- package/dist/query/types/Operation.types.d.ts +0 -13
- package/dist/query/types/Operation.types.js +0 -1
- package/dist/query/types/Resource.types.d.ts +0 -129
- package/dist/query/types/Resource.types.js +0 -1
- package/dist/query/types/shared.types.d.ts +0 -26
- package/dist/query/types/shared.types.js +0 -1
- package/dist/query-v2/api/createApi.d.ts +0 -10
- package/dist/query-v2/api/createApi.js +0 -83
- package/dist/query-v2/core/common/CacheEntry.d.ts +0 -29
- package/dist/query-v2/core/common/CacheEntry.js +0 -71
- package/dist/query-v2/core/common/CacheMap.d.ts +0 -38
- package/dist/query-v2/core/common/CacheMap.js +0 -127
- package/dist/query-v2/core/common/LifecycleHooks.d.ts +0 -22
- package/dist/query-v2/core/common/LifecycleHooks.js +0 -104
- package/dist/query-v2/core/common/index.d.ts +0 -3
- package/dist/query-v2/core/common/index.js +0 -3
- package/dist/query-v2/core/index.d.ts +0 -3
- package/dist/query-v2/core/index.js +0 -3
- package/dist/query-v2/core/machines/Machine.d.ts +0 -14
- package/dist/query-v2/core/machines/Machine.js +0 -33
- package/dist/query-v2/core/machines/MachineError.d.ts +0 -11
- package/dist/query-v2/core/machines/MachineError.js +0 -26
- package/dist/query-v2/core/machines/MachineIdle.d.ts +0 -8
- package/dist/query-v2/core/machines/MachineIdle.js +0 -19
- package/dist/query-v2/core/machines/MachinePending.d.ts +0 -12
- package/dist/query-v2/core/machines/MachinePending.js +0 -29
- package/dist/query-v2/core/machines/MachineRefreshing.d.ts +0 -14
- package/dist/query-v2/core/machines/MachineRefreshing.js +0 -46
- package/dist/query-v2/core/machines/MachineSuccess.d.ts +0 -16
- package/dist/query-v2/core/machines/MachineSuccess.js +0 -42
- package/dist/query-v2/core/machines/MachineWithData.d.ts +0 -18
- package/dist/query-v2/core/machines/MachineWithData.js +0 -40
- package/dist/query-v2/core/machines/Patcher.d.ts +0 -20
- package/dist/query-v2/core/machines/Patcher.js +0 -104
- package/dist/query-v2/core/machines/index.d.ts +0 -8
- package/dist/query-v2/core/machines/index.js +0 -8
- package/dist/query-v2/core/resource/ResourceV2.d.ts +0 -120
- package/dist/query-v2/core/resource/ResourceV2.js +0 -464
- package/dist/query-v2/core/resource/ResourceV2Agent.d.ts +0 -26
- package/dist/query-v2/core/resource/ResourceV2Agent.js +0 -132
- package/dist/query-v2/core/resource/index.d.ts +0 -2
- package/dist/query-v2/core/resource/index.js +0 -2
- package/dist/query-v2/index.d.ts +0 -11
- package/dist/query-v2/index.js +0 -17
- package/dist/query-v2/lib/NO_VALUE.d.ts +0 -2
- package/dist/query-v2/lib/NO_VALUE.js +0 -1
- package/dist/query-v2/lib/SKIP_TOKEN.d.ts +0 -2
- package/dist/query-v2/lib/SKIP_TOKEN.js +0 -1
- package/dist/query-v2/lib/index.d.ts +0 -4
- package/dist/query-v2/lib/index.js +0 -3
- package/dist/query-v2/plugins/ReactHooksPlugin.d.ts +0 -25
- package/dist/query-v2/plugins/ReactHooksPlugin.js +0 -19
- package/dist/query-v2/plugins/types.d.ts +0 -1
- package/dist/query-v2/react/__tests__/helpers.d.ts +0 -12
- package/dist/query-v2/react/__tests__/helpers.js +0 -33
- package/dist/query-v2/react/index.d.ts +0 -2
- package/dist/query-v2/react/index.js +0 -2
- package/dist/query-v2/react/useResourceV2Agent.d.ts +0 -12
- package/dist/query-v2/react/useResourceV2Agent.js +0 -36
- package/dist/query-v2/react/useResourceV2Ref.d.ts +0 -12
- package/dist/query-v2/react/useResourceV2Ref.js +0 -57
- package/dist/query-v2/snapshot/Snapshot.d.ts +0 -13
- package/dist/query-v2/snapshot/Snapshot.js +0 -76
- package/dist/query-v2/types/agent.types.d.ts +0 -54
- package/dist/query-v2/types/api.types.d.ts +0 -22
- package/dist/query-v2/types/cache.types.d.ts +0 -37
- package/dist/query-v2/types/index.d.ts +0 -9
- package/dist/query-v2/types/index.js +0 -9
- package/dist/query-v2/types/lifecycle.types.d.ts +0 -25
- package/dist/query-v2/types/machine.types.d.ts +0 -67
- package/dist/query-v2/types/plugin.types.d.ts +0 -38
- package/dist/query-v2/types/resource.types.d.ts +0 -35
- package/dist/query-v2/types/resource.types.js +0 -1
- package/dist/query-v2/types/shared.types.d.ts +0 -20
- package/dist/query-v2/types/shared.types.js +0 -1
- package/dist/query-v2/types/snapshot.types.d.ts +0 -21
- package/dist/query-v2/types/snapshot.types.js +0 -1
- package/docs/contributing/query-v2/README.md +0 -379
- package/docs/migrations/query-v2.md +0 -171
- package/docs/query-v2/README.md +0 -280
- package/docs/query-v2/api-reference.md +0 -235
- package/docs/query-v2/optimistic-updates.md +0 -148
- package/docs/query-v2/ssr.md +0 -130
- /package/dist/{query-v2 → query}/lib/stableStringify.d.ts +0 -0
- /package/dist/{query-v2/plugins/types.js → query/types/api.js} +0 -0
- /package/dist/{query-v2/types/agent.types.js → query/types/cache.js} +0 -0
- /package/dist/{query-v2/types/api.types.js → query/types/command.js} +0 -0
- /package/dist/{query-v2/types/cache.types.js → query/types/common.js} +0 -0
- /package/dist/{query-v2/types/lifecycle.types.js → query/types/plugin-hkt.js} +0 -0
- /package/dist/{query-v2/types/machine.types.js → query/types/resource.js} +0 -0
- /package/dist/{query-v2/types/plugin.types.js → query/types/state.js} +0 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# Миграция с версии 0.5.x на 0.6.0
|
|
2
|
+
|
|
3
|
+
## Signals
|
|
4
|
+
|
|
5
|
+
### `Signal.create()` → `Signal.state()`
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// Было
|
|
9
|
+
const count = Signal.create(0); // ❌
|
|
10
|
+
|
|
11
|
+
// Стало
|
|
12
|
+
const count = Signal.state(0); // ✅
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### `LocalSignal` → `LocalState`
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
// Было
|
|
19
|
+
const count = new LocalSignal(0); // ❌
|
|
20
|
+
|
|
21
|
+
// Стало
|
|
22
|
+
const count = LocalState.create({ key: 'count', defaultValue: 0 }); // ✅
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Query
|
|
26
|
+
|
|
27
|
+
Модуль Query полностью переписан в v0.6.0. Главное архитектурное изменение — переход от **standalone-функций** к **централизованному API** через `createApi()`.
|
|
28
|
+
|
|
29
|
+
### 1. Переход на `createApi`
|
|
30
|
+
|
|
31
|
+
Все ресурсы и команды теперь создаются через объект API:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// ❌ Было (v0.5.x) — standalone функции
|
|
35
|
+
import { createResource, createCommand } from '@fozy-labs/rx-toolkit';
|
|
36
|
+
|
|
37
|
+
const getUsers = createResource({
|
|
38
|
+
queryFn: (page: number) => fetch(`/api/users?page=${page}`).then(r => r.json()),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const updateUser = createCommand({
|
|
42
|
+
queryFn: (data: UserUpdate) => fetch('/api/users', { method: 'PUT', body: JSON.stringify(data) }).then(r => r.json()),
|
|
43
|
+
link: (link) => {
|
|
44
|
+
link({ resource: getUsers, forwardArgs: () => 1 });
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// ✅ Стало (v0.6.0) — централизованный API
|
|
51
|
+
import { createApi, reactHooksPlugin } from '@fozy-labs/rx-toolkit';
|
|
52
|
+
|
|
53
|
+
const api = createApi({
|
|
54
|
+
plugins: [reactHooksPlugin()],
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const getUsers = api.createResource({
|
|
58
|
+
queryFn: (page: number) => fetch(`/api/users?page=${page}`).then(r => r.json()),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const updateUser = api.createCommand({
|
|
62
|
+
queryFn: (data: UserUpdate) => fetch('/api/users', { method: 'PUT', body: JSON.stringify(data) }).then(r => r.json()),
|
|
63
|
+
links: [
|
|
64
|
+
{ resource: getUsers, forwardArgs: () => 1 },
|
|
65
|
+
],
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 2. Удалённые standalone-функции
|
|
70
|
+
|
|
71
|
+
| v0.5.x | v0.6.0 |
|
|
72
|
+
|--------|--------|
|
|
73
|
+
| `createResource(options)` | `api.createResource(options)` |
|
|
74
|
+
| `createCommand(options)` | `api.createCommand(options)` |
|
|
75
|
+
| `createOperation(options)` _(deprecated)_ | `api.createCommand(options)` |
|
|
76
|
+
| `createResourceDuplicator(resource)` | удалён без замены |
|
|
77
|
+
| `resetAllQueriesCache()` | `api.resetAll()` |
|
|
78
|
+
|
|
79
|
+
### 3. React хуки
|
|
80
|
+
|
|
81
|
+
Все старые хуки удалены. Новые доступны двумя способами — как standalone-хуки или через плагин `reactHooksPlugin()`.
|
|
82
|
+
|
|
83
|
+
#### `useResourceAgent` → `useResource`
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
// ❌ Было
|
|
87
|
+
import { useResourceAgent } from '@fozy-labs/rx-toolkit';
|
|
88
|
+
const query = useResourceAgent(getUsers, { page: 1 });
|
|
89
|
+
|
|
90
|
+
// ✅ Стало — standalone хук
|
|
91
|
+
import { useResource } from '@fozy-labs/rx-toolkit';
|
|
92
|
+
const query = useResource(getUsers, { page: 1 });
|
|
93
|
+
|
|
94
|
+
// ✅ Стало — через плагин (если createApi с reactHooksPlugin)
|
|
95
|
+
const query = getUsers.useResource({ page: 1 });
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### `useCommandAgent` / `useOperationAgent` → `useCommand`
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
// ❌ Было
|
|
102
|
+
import { useCommandAgent } from '@fozy-labs/rx-toolkit';
|
|
103
|
+
const [trigger] = useCommandAgent(updateUser);
|
|
104
|
+
// или deprecated:
|
|
105
|
+
const [trigger] = useOperationAgent(updateUser);
|
|
106
|
+
|
|
107
|
+
// ✅ Стало — standalone хук
|
|
108
|
+
import { useCommand } from '@fozy-labs/rx-toolkit';
|
|
109
|
+
const [trigger, state] = useCommand(updateUser);
|
|
110
|
+
|
|
111
|
+
// ✅ Стало — через плагин
|
|
112
|
+
const [trigger, state] = updateUser.useCommand();
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### `useResourceRef` → `resource.getEntry()`
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
// ❌ Было
|
|
119
|
+
const ref = useResourceRef(todoResource, args);
|
|
120
|
+
|
|
121
|
+
// ✅ Стало — прямой замены в виде хука нет
|
|
122
|
+
const entry = todoResource.getEntry(args, true); // true = инициировать запрос если записи нет
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 4. Links API
|
|
126
|
+
|
|
127
|
+
Свойство `link` (callback) переименовано в `links` (массив или callback). Колбэки `optimisticUpdate` и `update` больше **не принимают объект**, а получают аргументы напрямую:
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
// ❌ Было (v0.5.x) — link (singular, callback)
|
|
131
|
+
const updateUser = createCommand({
|
|
132
|
+
queryFn: (data) => fetch('/api/users', { method: 'PUT', body: JSON.stringify(data) }).then(r => r.json()),
|
|
133
|
+
link: (link) => {
|
|
134
|
+
link({
|
|
135
|
+
resource: getUsers,
|
|
136
|
+
forwardArgs: (cmdArgs) => cmdArgs.userId,
|
|
137
|
+
optimisticUpdate: ({ draft, args }) => {
|
|
138
|
+
draft.name = args.newName;
|
|
139
|
+
},
|
|
140
|
+
update: ({ draft, args, data }) => {
|
|
141
|
+
Object.assign(draft, data);
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// ✅ Стало (v0.6.0) — links (plural, массив)
|
|
148
|
+
const updateUser = api.createCommand({
|
|
149
|
+
queryFn: (data) => fetch('/api/users', { method: 'PUT', body: JSON.stringify(data) }).then(r => r.json()),
|
|
150
|
+
links: [
|
|
151
|
+
{
|
|
152
|
+
resource: getUsers,
|
|
153
|
+
forwardArgs: (cmdArgs) => cmdArgs.userId,
|
|
154
|
+
optimisticUpdate: (draft, args) => {
|
|
155
|
+
draft.name = args.newName;
|
|
156
|
+
},
|
|
157
|
+
update: (draft, args, result) => {
|
|
158
|
+
Object.assign(draft, result);
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
> **Изменения:**
|
|
166
|
+
> - `link` → `links` (принимает массив объектов или callback)
|
|
167
|
+
> - `optimisticUpdate: ({ draft, args }) =>` → `optimisticUpdate: (draft, args) =>`
|
|
168
|
+
> - `update: ({ draft, args, data }) =>` → `update: (draft, args, result) =>` (`data` → `result`)
|
|
169
|
+
|
|
170
|
+
### 5. Machine — иммутабельные подтипы
|
|
171
|
+
|
|
172
|
+
`Machine` теперь — иммутабельное дискриминированное объединение из пяти подтипов:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
type Machine<TArgs, TData> =
|
|
176
|
+
| MachinePending<TArgs, TData> // status: 'pending'
|
|
177
|
+
| MachineSuccess<TArgs, TData> // status: 'success'
|
|
178
|
+
| MachineError<TArgs, TData> // status: 'error'
|
|
179
|
+
| MachineRefreshing<TArgs, TData> // status: 'refreshing'
|
|
180
|
+
| MachineRefreshError<TArgs, TData> // status: 'refresh-error'
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Проверка состояния:
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
const machine = entry.machine$();
|
|
187
|
+
|
|
188
|
+
if (machine.state.status === 'success') {
|
|
189
|
+
console.log(machine.state.data); // типизировано как TData
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (machine.state.status === 'error') {
|
|
193
|
+
console.log(machine.state.error); // типизировано как Error
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### 6. Новые возможности `createApi`
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
const api = createApi({
|
|
201
|
+
// Плагины для расширения resource/command (например, React-хуки)
|
|
202
|
+
plugins: [reactHooksPlugin()],
|
|
203
|
+
// Префикс ключей для изоляции нескольких API-инстансов
|
|
204
|
+
keyPrefix: 'myApp',
|
|
205
|
+
// Драйвер синхронизации между вкладками
|
|
206
|
+
syncDriver: broadcastSyncDriver(),
|
|
207
|
+
// Какие данные синхронизировать: 'none' | 'resources' | 'all'
|
|
208
|
+
defaultSync: 'all',
|
|
209
|
+
// Время жизни кеша ресурсов (мс), false = бессрочно
|
|
210
|
+
resourceRetentionTime: 30_000,
|
|
211
|
+
// Время жизни кеша команд (мс), false = бессрочно
|
|
212
|
+
commandRetentionTime: 5_000,
|
|
213
|
+
// SSR: время валидности снапшота (мс)
|
|
214
|
+
snapshotValidTime: 60_000,
|
|
215
|
+
// SSR: начальный снапшот с сервера
|
|
216
|
+
initialSnapshot: getServerSnapshot(),
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// Снапшот для SSR
|
|
220
|
+
const snapshot = api.getSnapshot();
|
|
221
|
+
|
|
222
|
+
// Сброс всего кеша (замена resetAllQueriesCache)
|
|
223
|
+
api.resetAll();
|
|
224
|
+
```
|