@fozy-labs/rx-toolkit 0.5.4 → 0.6.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/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 +4 -0
- package/dist/query/core/api/index.js +4 -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 +48 -2
- 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
|
@@ -9,7 +9,7 @@ RxToolkit предоставляет набор React хуков для эффе
|
|
|
9
9
|
Подписывается на изменения сигнала и возвращает текущее значение.
|
|
10
10
|
|
|
11
11
|
```tsx
|
|
12
|
-
import { Signal,
|
|
12
|
+
import { Signal, useSignal } from '@fozy-labs/rx-toolkit';
|
|
13
13
|
|
|
14
14
|
const counter$ = Signal.state(0);
|
|
15
15
|
const doubled$ = Signal.compute(() => counter$() * 2);
|
|
@@ -38,16 +38,16 @@ function Counter() {
|
|
|
38
38
|
|
|
39
39
|
## RxQuery хуки
|
|
40
40
|
|
|
41
|
-
###
|
|
41
|
+
### useResource
|
|
42
42
|
|
|
43
43
|
Подписывается на состояние ресурса и автоматически инициирует запрос при монтировании или изменении аргументов.
|
|
44
44
|
|
|
45
45
|
```tsx
|
|
46
|
-
import {
|
|
46
|
+
import { useResource, SKIP } from '@fozy-labs/rx-toolkit';
|
|
47
47
|
import { userResource } from '../api/userResource';
|
|
48
48
|
|
|
49
49
|
function UserProfile({ userId }: { userId: string | null }) {
|
|
50
|
-
const userQuery =
|
|
50
|
+
const userQuery = useResource(
|
|
51
51
|
userResource,
|
|
52
52
|
userId ? { id: userId } : SKIP
|
|
53
53
|
);
|
|
@@ -60,7 +60,7 @@ function UserProfile({ userId }: { userId: string | null }) {
|
|
|
60
60
|
return <div>Ошибка: {String(userQuery.error)}</div>;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
if (userQuery.
|
|
63
|
+
if (userQuery.isRefreshing) {
|
|
64
64
|
// Показываем данные + индикатор перезагрузки
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -73,20 +73,22 @@ function UserProfile({ userId }: { userId: string | null }) {
|
|
|
73
73
|
}
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
**Возвращаемое значение (
|
|
77
|
-
|
|
78
|
-
| Поле | Тип
|
|
79
|
-
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
76
|
+
**Возвращаемое значение (TResourceAgentState):**
|
|
77
|
+
|
|
78
|
+
| Поле | Тип | Описание |
|
|
79
|
+
|--------------------|------------------|---------------------------------------|
|
|
80
|
+
| `status` | `TAgentStatus` | Текущий статус агента |
|
|
81
|
+
| `data` | `TData \| null` | Данные ресурса |
|
|
82
|
+
| `error` | `unknown` | Объект ошибки |
|
|
83
|
+
| `args` | `TArgs \| null` | Аргументы последнего запроса |
|
|
84
|
+
| `isLoading` | `boolean` | Любая загрузка (первая или повторная) |
|
|
85
|
+
| `isInitialLoading` | `boolean` | Первая загрузка (данных еще нет) |
|
|
86
|
+
| `isRefreshing` | `boolean` | Перезагрузка (данные уже есть) |
|
|
87
|
+
| `isRefreshError` | `boolean` | Ошибка при перезагрузке |
|
|
88
|
+
| `isSuccess` | `boolean` | Успешно ли завершен последний запрос |
|
|
89
|
+
| `isError` | `boolean` | Произошла ли ошибка |
|
|
90
|
+
| `retry()` | `() => void` | Повторить последний запрос |
|
|
91
|
+
| `refresh()` | `() => void` | Принудительно обновить данные |
|
|
90
92
|
|
|
91
93
|
**Особенности:**
|
|
92
94
|
- Автоматическая подписка на состояние ресурса
|
|
@@ -94,18 +96,16 @@ function UserProfile({ userId }: { userId: string | null }) {
|
|
|
94
96
|
- Поддержка `SKIP` токена для условного пропуска запроса
|
|
95
97
|
- При смене аргументов показывает предыдущие данные во время загрузки новых
|
|
96
98
|
|
|
97
|
-
###
|
|
99
|
+
### useCommand
|
|
98
100
|
|
|
99
101
|
Создает агент команды и возвращает кортеж `[trigger, state]`.
|
|
100
102
|
|
|
101
|
-
> **Note:** `useOperationAgent` является deprecated-алиасом для `useCommandAgent` и будет удалён в v0.6.0.
|
|
102
|
-
|
|
103
103
|
```tsx
|
|
104
|
-
import {
|
|
104
|
+
import { useCommand } from '@fozy-labs/rx-toolkit';
|
|
105
105
|
import { updateUserCommand } from '../api/updateUserCommand';
|
|
106
106
|
|
|
107
107
|
function EditUserForm({ user }: { user: User }) {
|
|
108
|
-
const [updateUser, updateState] =
|
|
108
|
+
const [updateUser, updateState] = useCommand(updateUserCommand);
|
|
109
109
|
|
|
110
110
|
const handleSubmit = async (event: React.FormEvent) => {
|
|
111
111
|
event.preventDefault();
|
|
@@ -143,7 +143,7 @@ function EditUserForm({ user }: { user: User }) {
|
|
|
143
143
|
```typescript
|
|
144
144
|
[
|
|
145
145
|
trigger: (args: Args) => Promise<Data>, // Функция запуска команды
|
|
146
|
-
state:
|
|
146
|
+
state: TCommandAgentState // Текущее состояние
|
|
147
147
|
]
|
|
148
148
|
```
|
|
149
149
|
|
|
@@ -154,86 +154,40 @@ function EditUserForm({ user }: { user: User }) {
|
|
|
154
154
|
|
|
155
155
|
**state объект:**
|
|
156
156
|
|
|
157
|
-
| Поле
|
|
158
|
-
|
|
159
|
-
| `
|
|
160
|
-
| `
|
|
161
|
-
| `
|
|
162
|
-
| `
|
|
163
|
-
| `
|
|
164
|
-
| `
|
|
165
|
-
| `
|
|
157
|
+
| Поле | Тип | Описание |
|
|
158
|
+
|-------------|----------------------------------------------|------------------------|
|
|
159
|
+
| `status` | `"idle" \| "pending" \| "success" \| "error"` | Текущий статус команды |
|
|
160
|
+
| `data` | `TData \| null` | Результат команды |
|
|
161
|
+
| `error` | `unknown` | Объект ошибки |
|
|
162
|
+
| `args` | `TArgs \| null` | Аргументы запуска |
|
|
163
|
+
| `isLoading` | `boolean` | Выполняется ли команда |
|
|
164
|
+
| `isSuccess` | `boolean` | Успешно ли завершена |
|
|
165
|
+
| `isError` | `boolean` | Произошла ли ошибка |
|
|
166
166
|
|
|
167
|
-
### useResourceRef
|
|
167
|
+
### useResourceRef (удалён в v0.6.0)
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
> **Удалён:** Хук `useResourceRef` был удалён в v0.6.0. Для низкоуровневых операций с кэшем используйте `resource.getEntry(args, true)` или `resource.createAgent()` напрямую.
|
|
170
170
|
|
|
171
171
|
```tsx
|
|
172
|
-
import {
|
|
172
|
+
import { useResource } from '@fozy-labs/rx-toolkit';
|
|
173
173
|
import { todoResource } from '../api/todoResource';
|
|
174
174
|
|
|
175
175
|
function TodoItem({ todo }: { todo: Todo }) {
|
|
176
|
-
const todoQuery =
|
|
177
|
-
const todoRef = useResourceRef(todoResource, undefined);
|
|
176
|
+
const todoQuery = useResource(todoResource, undefined);
|
|
178
177
|
|
|
179
|
-
|
|
178
|
+
// Вместо useResourceRef — получаем entry напрямую:
|
|
179
|
+
const entry = todoResource.getEntry(undefined, true);
|
|
180
180
|
|
|
181
181
|
const handleToggle = () => {
|
|
182
|
-
|
|
183
|
-
const transaction = todoRef.patch((draft) => {
|
|
182
|
+
const transaction = entry.createPatch((draft) => {
|
|
184
183
|
const item = draft.items.find(i => i.id === todo.id);
|
|
185
184
|
if (item) item.completed = !item.completed;
|
|
186
185
|
});
|
|
187
|
-
|
|
188
|
-
if (transaction) {
|
|
189
|
-
setPendingTransaction(transaction);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const handleSave = async () => {
|
|
194
|
-
try {
|
|
195
|
-
await saveToServer(todo.id, !todo.completed);
|
|
196
|
-
pendingTransaction?.commit();
|
|
197
|
-
} catch {
|
|
198
|
-
pendingTransaction?.abort(); // Откатить изменения
|
|
199
|
-
}
|
|
200
|
-
setPendingTransaction(null);
|
|
186
|
+
// ...
|
|
201
187
|
};
|
|
202
|
-
|
|
203
|
-
return (
|
|
204
|
-
<div>
|
|
205
|
-
<input
|
|
206
|
-
type="checkbox"
|
|
207
|
-
checked={todo.completed}
|
|
208
|
-
onChange={handleToggle}
|
|
209
|
-
/>
|
|
210
|
-
{pendingTransaction && (
|
|
211
|
-
<>
|
|
212
|
-
<button onClick={handleSave}>Сохранить</button>
|
|
213
|
-
<button onClick={() => {
|
|
214
|
-
pendingTransaction.abort();
|
|
215
|
-
setPendingTransaction(null);
|
|
216
|
-
}}>
|
|
217
|
-
Отмена
|
|
218
|
-
</button>
|
|
219
|
-
</>
|
|
220
|
-
)}
|
|
221
|
-
</div>
|
|
222
|
-
);
|
|
223
188
|
}
|
|
224
189
|
```
|
|
225
190
|
|
|
226
|
-
**Возвращаемое значение (ResourceRefInstance):**
|
|
227
|
-
|
|
228
|
-
| Метод | Описание |
|
|
229
|
-
|-------|----------|
|
|
230
|
-
| `has` | Проверка наличия элемента в кэше |
|
|
231
|
-
| `lock()` | Блокировка ресурса, возвращает `{ unlock }` |
|
|
232
|
-
| `unlockOne()` | Снятие одной блокировки |
|
|
233
|
-
| `patch(fn)` | Создание patch-транзакции |
|
|
234
|
-
| `invalidate()` | Инвалидация кэша |
|
|
235
|
-
| `create(data)` | Создание элемента в кэше |
|
|
236
|
-
|
|
237
191
|
|
|
238
192
|
---
|
|
239
193
|
|
|
@@ -275,7 +229,7 @@ function Counter() {
|
|
|
275
229
|
|
|
276
230
|
```tsx
|
|
277
231
|
function UserStats({ userId, showStats }) {
|
|
278
|
-
const statsQuery =
|
|
232
|
+
const statsQuery = useResource(
|
|
279
233
|
statsResource,
|
|
280
234
|
showStats && userId ? { userId } : SKIP
|
|
281
235
|
);
|
|
@@ -290,8 +244,8 @@ function UserStats({ userId, showStats }) {
|
|
|
290
244
|
|
|
291
245
|
```tsx
|
|
292
246
|
function Dashboard() {
|
|
293
|
-
const userQuery =
|
|
294
|
-
const settingsQuery =
|
|
247
|
+
const userQuery = useResource(userResource, { id: currentUserId });
|
|
248
|
+
const settingsQuery = useResource(settingsResource, undefined);
|
|
295
249
|
|
|
296
250
|
const isLoading = userQuery.isLoading || settingsQuery.isLoading;
|
|
297
251
|
const isError = userQuery.isError || settingsQuery.isError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fozy-labs/rx-toolkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
"build": "rimraf ./dist && tsc && tsc-alias",
|
|
10
10
|
"build:watch": "npm run build && (concurrently \"tsc -w\" \"tsc-alias -w\")",
|
|
11
11
|
"ts-check": "tsc --noEmit",
|
|
12
|
-
"
|
|
13
|
-
"test": "vitest run",
|
|
12
|
+
"test": "tsc -p tsconfig.test.json && vitest run",
|
|
14
13
|
"test:watch": "vitest",
|
|
15
14
|
"test:coverage": "vitest run --coverage",
|
|
16
15
|
"test:ui": "vitest --ui",
|
|
17
16
|
"lint": "eslint src/",
|
|
18
17
|
"lint:fix": "eslint src/ --fix",
|
|
19
18
|
"format": "prettier --write src/",
|
|
20
|
-
"format:check": "prettier --check src/"
|
|
19
|
+
"format:check": "prettier --check src/",
|
|
20
|
+
"check:all": "npm run ts-check && npm run test && npm run lint && npm run format:check"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@fozy-labs/js-configs": "^0.1.3",
|
|
@@ -72,9 +72,7 @@
|
|
|
72
72
|
"types": "./dist/index.d.ts"
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
|
-
"sideEffects":
|
|
76
|
-
"./dist/query/core/Resource/ResourceRef.js"
|
|
77
|
-
],
|
|
75
|
+
"sideEffects": false,
|
|
78
76
|
"publishConfig": {
|
|
79
77
|
"access": "public"
|
|
80
78
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const SKIP: unique symbol;
|
package/dist/query/SKIP_TOKEN.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const SKIP = Symbol("SKIP");
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Command } from "../../query/core/Command/Command";
|
|
2
|
-
import type { CommandCreateOptions, CommandDefinition } from "../../query/types";
|
|
3
|
-
/**
|
|
4
|
-
* Создаёт команду (command) — единицу мутирующего запроса.
|
|
5
|
-
*
|
|
6
|
-
* Команда инкапсулирует асинхронную операцию с поддержкой кеширования,
|
|
7
|
-
* связывания с ресурсами (link) и оптимистичных обновлений.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* const updateUser = createCommand({
|
|
12
|
-
* queryFn: (args: { id: string; name: string }) => api.updateUser(args),
|
|
13
|
-
* link: (link) => link({
|
|
14
|
-
* resource: userResource,
|
|
15
|
-
* forwardArgs: (args) => ({ id: args.id }),
|
|
16
|
-
* invalidate: true,
|
|
17
|
-
* }),
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare const createCommand: <ARGS, RESULT, SELECTED = never>(options: CommandCreateOptions<CommandDefinition<ARGS, RESULT, SELECTED>>) => Command<CommandDefinition<ARGS, RESULT, SELECTED>>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Command } from "../../query/core/Command/Command";
|
|
2
|
-
/**
|
|
3
|
-
* Создаёт команду (command) — единицу мутирующего запроса.
|
|
4
|
-
*
|
|
5
|
-
* Команда инкапсулирует асинхронную операцию с поддержкой кеширования,
|
|
6
|
-
* связывания с ресурсами (link) и оптимистичных обновлений.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const updateUser = createCommand({
|
|
11
|
-
* queryFn: (args: { id: string; name: string }) => api.updateUser(args),
|
|
12
|
-
* link: (link) => link({
|
|
13
|
-
* resource: userResource,
|
|
14
|
-
* forwardArgs: (args) => ({ id: args.id }),
|
|
15
|
-
* invalidate: true,
|
|
16
|
-
* }),
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export const createCommand = ((options) => new Command(options));
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated Use `createCommand` instead. Will be removed in v0.6.0.
|
|
3
|
-
* @see createCommand
|
|
4
|
-
*/
|
|
5
|
-
export declare const createOperation: <ARGS, RESULT, SELECTED = never>(options: import("..").CommandCreateOptions<import("..").CommandDefinition<ARGS, RESULT, SELECTED>>) => import("../core/Command").Command<import("..").CommandDefinition<ARGS, RESULT, SELECTED>>;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { Resource } from "../../query/core/Resource/Resource";
|
|
2
|
-
import type { ResourceCreateOptions, ResourceDefinition } from "../../query/types";
|
|
3
|
-
export declare const createResource: <ARGS, RESULT, SELECTED = never>(options: ResourceCreateOptions<ResourceDefinition<ARGS, RESULT, SELECTED>>) => Resource<ResourceDefinition<ARGS, RESULT, SELECTED>>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { DuplicatorDefinition, DuplicatorOptions, ResourceDuplicator } from "../../query/core/Resource/ResourceDuplicator";
|
|
2
|
-
import { ResourceDefinition } from "../../query/types";
|
|
3
|
-
export declare const createResourceDuplicator: <ARGS, RESULT, SELECTED = never>(options: DuplicatorOptions<DuplicatorDefinition<ResourceDefinition<ARGS, RESULT, SELECTED>>>) => ResourceDuplicator<DuplicatorDefinition<ResourceDefinition<ARGS, RESULT, SELECTED>>>;
|
|
4
|
-
export type ResourceDuplicatorCreateFn<ARGS, RESULT, SELECTED = never> = (options: DuplicatorOptions<DuplicatorDefinition<ResourceDefinition<ARGS, RESULT, SELECTED>>>) => ResourceDuplicator<DuplicatorDefinition<ResourceDefinition<ARGS, RESULT, SELECTED>>>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function resetAllQueriesCache(): void;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { ReactiveCache } from "../../../query/lib/ReactiveCache";
|
|
2
|
-
import type { CommandCreateOptions, CommandDefinition, CommandInstance, FallbackOnNever } from "../../../query/types";
|
|
3
|
-
import { CommandAgent } from "./CommandAgent";
|
|
4
|
-
export type CoreCommandQueryState<D extends CommandDefinition> = {
|
|
5
|
-
arg: D["Args"] | null;
|
|
6
|
-
data: FallbackOnNever<D["Selected"], D["Result"]> | null;
|
|
7
|
-
error: unknown | null;
|
|
8
|
-
isError: boolean;
|
|
9
|
-
isLoading: boolean;
|
|
10
|
-
isRepeating: boolean;
|
|
11
|
-
isDone: boolean;
|
|
12
|
-
isSuccess: boolean;
|
|
13
|
-
isInitiated: boolean;
|
|
14
|
-
};
|
|
15
|
-
export declare class Command<D extends CommandDefinition> implements CommandInstance<D> {
|
|
16
|
-
private readonly _options;
|
|
17
|
-
private _queriesCache;
|
|
18
|
-
private _hooks;
|
|
19
|
-
private _links;
|
|
20
|
-
private _DEFAULT_CACHE_LIFETIME;
|
|
21
|
-
constructor(_options: CommandCreateOptions<D>);
|
|
22
|
-
private _createLinks;
|
|
23
|
-
createAgent(): CommandAgent<D>;
|
|
24
|
-
getQueryCache(args: D["Args"]): ReactiveCache<CoreCommandQueryState<D>> | undefined;
|
|
25
|
-
createQueryCache(args: D["Args"], state?: CoreCommandQueryState<D>): ReactiveCache<CoreCommandQueryState<D>>;
|
|
26
|
-
initiate(args: D["Args"], options?: {
|
|
27
|
-
cache?: ReactiveCache<CoreCommandQueryState<D>>;
|
|
28
|
-
}): ReactiveCache<CoreCommandQueryState<D>>;
|
|
29
|
-
private _initiate;
|
|
30
|
-
/**
|
|
31
|
-
* Используется для обратной совместимости
|
|
32
|
-
* @deprecated
|
|
33
|
-
*/
|
|
34
|
-
mutate(args: D["Args"]): Promise<D["Data"]>;
|
|
35
|
-
}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { PromiseResolver } from "../../../common/utils";
|
|
2
|
-
import { ResetAllQueriesSignal } from "../../../query/core/ResetAllQueriesSignal";
|
|
3
|
-
import { Batcher } from "../../../signals";
|
|
4
|
-
import { QueriesCache } from "../QueriesCache";
|
|
5
|
-
import { QueriesLifetimeHooks } from "../QueriesLifetimeHooks";
|
|
6
|
-
import { CommandAgent } from "./CommandAgent";
|
|
7
|
-
class CommandQueryState {
|
|
8
|
-
static create() {
|
|
9
|
-
return {
|
|
10
|
-
arg: null,
|
|
11
|
-
data: null,
|
|
12
|
-
error: null,
|
|
13
|
-
isError: false,
|
|
14
|
-
isRepeating: false,
|
|
15
|
-
isDone: false,
|
|
16
|
-
isSuccess: false,
|
|
17
|
-
isLoading: false,
|
|
18
|
-
isInitiated: false,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
static load(state = CommandQueryState.create(), args) {
|
|
22
|
-
return {
|
|
23
|
-
...state,
|
|
24
|
-
arg: args,
|
|
25
|
-
isLoading: true,
|
|
26
|
-
isRepeating: state.isDone,
|
|
27
|
-
isInitiated: true,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
static success(state, data) {
|
|
31
|
-
return {
|
|
32
|
-
...state,
|
|
33
|
-
data,
|
|
34
|
-
isLoading: false,
|
|
35
|
-
isRepeating: false,
|
|
36
|
-
isDone: true,
|
|
37
|
-
isSuccess: true,
|
|
38
|
-
isError: false,
|
|
39
|
-
error: null,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
static error(state, error) {
|
|
43
|
-
return {
|
|
44
|
-
...state,
|
|
45
|
-
isLoading: false,
|
|
46
|
-
isRepeating: false,
|
|
47
|
-
isDone: true,
|
|
48
|
-
isSuccess: false,
|
|
49
|
-
isError: true,
|
|
50
|
-
error,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
export class Command {
|
|
55
|
-
_options;
|
|
56
|
-
_queriesCache;
|
|
57
|
-
_hooks;
|
|
58
|
-
_links = [];
|
|
59
|
-
_DEFAULT_CACHE_LIFETIME = 1_000;
|
|
60
|
-
constructor(_options) {
|
|
61
|
-
this._options = _options;
|
|
62
|
-
this._queriesCache = new QueriesCache(this._options.cacheLifetime ?? this._DEFAULT_CACHE_LIFETIME);
|
|
63
|
-
this._hooks = new QueriesLifetimeHooks({
|
|
64
|
-
onCacheEntryAdded: _options.onCacheEntryAdded,
|
|
65
|
-
onQueryStarted: _options.onQueryStarted,
|
|
66
|
-
devtoolsName: _options.devtoolsName,
|
|
67
|
-
});
|
|
68
|
-
this._createLinks();
|
|
69
|
-
ResetAllQueriesSignal.clean$.subscribe(() => {
|
|
70
|
-
const caches = Array.from(this._queriesCache.values());
|
|
71
|
-
caches.forEach((cache) => {
|
|
72
|
-
cache.next(CommandQueryState.create());
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
_createLinks() {
|
|
77
|
-
this._options.link?.((linkOptions) => {
|
|
78
|
-
this._links.push(linkOptions);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
createAgent() {
|
|
82
|
-
return new CommandAgent(this);
|
|
83
|
-
}
|
|
84
|
-
getQueryCache(args) {
|
|
85
|
-
return this._queriesCache.getQueryCache(args);
|
|
86
|
-
}
|
|
87
|
-
createQueryCache(args, state = CommandQueryState.create()) {
|
|
88
|
-
const cache = this._queriesCache.createQueryCache(args, state);
|
|
89
|
-
const hookResolvers = this._hooks.onCacheEntryAdded(args);
|
|
90
|
-
const spySub = cache.spy$.subscribe((state) => {
|
|
91
|
-
if (!state.isDone)
|
|
92
|
-
return;
|
|
93
|
-
hookResolvers.cacheDataLoaded();
|
|
94
|
-
spySub.unsubscribe();
|
|
95
|
-
});
|
|
96
|
-
cache.spy$.subscribe((state) => {
|
|
97
|
-
hookResolvers.dataChanged$.next(state);
|
|
98
|
-
});
|
|
99
|
-
cache.onClean$.subscribe(() => {
|
|
100
|
-
hookResolvers.cacheEntryRemoved();
|
|
101
|
-
});
|
|
102
|
-
return cache;
|
|
103
|
-
}
|
|
104
|
-
initiate(args, options) {
|
|
105
|
-
return Batcher.run(() => this._initiate(args, options));
|
|
106
|
-
}
|
|
107
|
-
_initiate(args, options) {
|
|
108
|
-
let cache = options?.cache ?? this.getQueryCache(args);
|
|
109
|
-
const state = CommandQueryState.load(cache?.value, args);
|
|
110
|
-
if (!cache) {
|
|
111
|
-
cache = this.createQueryCache(args, state);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
cache.next(state);
|
|
115
|
-
}
|
|
116
|
-
const linksMeta = this._links.map((link) => {
|
|
117
|
-
const forwardedArgs = link.forwardArgs(args);
|
|
118
|
-
const ref = link.resource.createRef(forwardedArgs);
|
|
119
|
-
return { link, ref, state: {} };
|
|
120
|
-
});
|
|
121
|
-
const query = this._options.queryFn(args);
|
|
122
|
-
const hookResolvers = this._hooks.onQueryStarted(args);
|
|
123
|
-
linksMeta.forEach(({ link, ref, state }) => {
|
|
124
|
-
if (link.lock) {
|
|
125
|
-
state.unlocker = ref.lock();
|
|
126
|
-
}
|
|
127
|
-
if (link.optimisticUpdate && ref.has) {
|
|
128
|
-
state.patch = ref.patch((draft) => {
|
|
129
|
-
return link.optimisticUpdate({ draft, args });
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
query
|
|
134
|
-
.then((result) => {
|
|
135
|
-
Batcher.run(() => {
|
|
136
|
-
const data = this._options.select ? this._options.select(result) : result;
|
|
137
|
-
cache.next(CommandQueryState.success(state, data));
|
|
138
|
-
/**
|
|
139
|
-
* Обновляем связанные ресурсы
|
|
140
|
-
*/
|
|
141
|
-
linksMeta.forEach(({ link, ref, state }) => {
|
|
142
|
-
if (link.update && ref.has) {
|
|
143
|
-
ref.patch((draft) => {
|
|
144
|
-
return link.update({ draft, args, data });
|
|
145
|
-
})?.commit();
|
|
146
|
-
}
|
|
147
|
-
if (link.create && !ref.has) {
|
|
148
|
-
ref.create(link.create({ args, data }));
|
|
149
|
-
}
|
|
150
|
-
if (link.invalidate) {
|
|
151
|
-
ref.invalidate();
|
|
152
|
-
}
|
|
153
|
-
state.patch?.commit();
|
|
154
|
-
});
|
|
155
|
-
hookResolvers.fulfilledSuccess(data);
|
|
156
|
-
/**
|
|
157
|
-
* Обновляем связанные ресурсы
|
|
158
|
-
*/
|
|
159
|
-
linksMeta.forEach(({ state }) => {
|
|
160
|
-
state.unlocker?.unlock();
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
})
|
|
164
|
-
.catch((error) => {
|
|
165
|
-
Batcher.run(() => {
|
|
166
|
-
cache.next(CommandQueryState.error(state, error));
|
|
167
|
-
/**
|
|
168
|
-
* Обновляем связанные ресурсы
|
|
169
|
-
*/
|
|
170
|
-
linksMeta.forEach(({ state }) => {
|
|
171
|
-
state.patch?.abort();
|
|
172
|
-
});
|
|
173
|
-
hookResolvers.fulfilledError(error);
|
|
174
|
-
/**
|
|
175
|
-
* Обновляем связанные ресурсы
|
|
176
|
-
*/
|
|
177
|
-
linksMeta.forEach(({ state }) => {
|
|
178
|
-
state.unlocker?.unlock();
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
return cache;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Используется для обратной совместимости
|
|
186
|
-
* @deprecated
|
|
187
|
-
*/
|
|
188
|
-
mutate(args) {
|
|
189
|
-
const cache = this.initiate(args);
|
|
190
|
-
const resolver = new PromiseResolver();
|
|
191
|
-
const subscription = cache.value$.obs.subscribe((state) => {
|
|
192
|
-
if (!state.isInitiated || state.isLoading || state.isRepeating)
|
|
193
|
-
return;
|
|
194
|
-
if (state.isError) {
|
|
195
|
-
resolver.reject(state.error);
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (!state.isSuccess) {
|
|
199
|
-
console.error("Unexpected state in mutation:", state);
|
|
200
|
-
resolver.reject(new Error("Unexpected state in mutation"));
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
resolver.resolve(state.data);
|
|
204
|
-
});
|
|
205
|
-
resolver.promise.finally(() => {
|
|
206
|
-
subscription.unsubscribe();
|
|
207
|
-
});
|
|
208
|
-
return resolver.promise;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { CommandAgentInstance, CommandDefinition } from "../../../query/types";
|
|
2
|
-
import type { Command } from "./Command";
|
|
3
|
-
export declare class CommandAgent<D extends CommandDefinition> implements CommandAgentInstance<D> {
|
|
4
|
-
private _command;
|
|
5
|
-
private _commands$;
|
|
6
|
-
state$: import("../../../signals").ComputeFn<{
|
|
7
|
-
isLoading: boolean;
|
|
8
|
-
isDone: boolean;
|
|
9
|
-
isSuccess: boolean;
|
|
10
|
-
isError: boolean;
|
|
11
|
-
error: {} | undefined;
|
|
12
|
-
data: NonNullable<import("../../../query/types").FallbackOnNever<D["Selected"], D["Result"]>> | undefined;
|
|
13
|
-
args: D["Args"];
|
|
14
|
-
}>;
|
|
15
|
-
constructor(_command: Command<D>);
|
|
16
|
-
private _next;
|
|
17
|
-
initiate(args: D["Args"]): void;
|
|
18
|
-
createAgent(): CommandAgentInstance<D>;
|
|
19
|
-
}
|