@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
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# RxToolkit
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Фреймворк-агностик набор инструментов для **реактивного** управления состоянием, построенный поверх RxJS.
|
|
4
4
|
|
|
5
5
|
[](https://badge.fury.io/js/%40fozy-labs%2Frx-toolkit)
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
|
@@ -14,7 +14,7 @@ npm install @fozy-labs/rx-toolkit rxjs
|
|
|
14
14
|
## 🎯 Цель
|
|
15
15
|
|
|
16
16
|
RxJS действительно мощный инструмент реактивного программирования,
|
|
17
|
-
он
|
|
17
|
+
он удобен, когда мы работаем с потоком событий, но когда речь заходит о состоянии приложения,
|
|
18
18
|
из-за асинхронной природы rx'а, его использование становится сложным и громоздким, не говоря уже о кешировании данных
|
|
19
19
|
(хотя некоторые разработчики "продают" rxjs, как альтернативу Query библиотекам,
|
|
20
20
|
на самом деле реализация подобного функционала выльется в создание отдельной библиотеки).
|
|
@@ -27,7 +27,7 @@ RxToolkit решает эти проблемы, предоставляя сво
|
|
|
27
27
|
- 🔧 **Framework-agnostic** — Стройте систему и описывайте логику в изолированном месте.
|
|
28
28
|
- ⚡ **Built on RxJS** — Наследует всю мощь RxJS.
|
|
29
29
|
- 💾 **Кеш-менеджер** — Предоставляет Query реализацию для работы с данными.
|
|
30
|
-
- 🧪 **Query
|
|
30
|
+
- 🧪 **Query** — Кеш-менеджер с machine states, плагинами и SSR snapshots.
|
|
31
31
|
- 🔷 **TypeScript-first** — Полная типизация.
|
|
32
32
|
- 🔗 **Интеграция с фреймворками** — Как и RxJS напрямую работает в Angular, Svelte и SolidJS.
|
|
33
33
|
Поставляется с React-хуками из коробки.
|
|
@@ -35,7 +35,6 @@ RxToolkit решает эти проблемы, предоставляя сво
|
|
|
35
35
|
## 📚 Документация
|
|
36
36
|
- [**RxSignals**](./docs/signals/README.md) - реактивные примитивы
|
|
37
37
|
- [**RxQuery**](./docs/query/README.md) - кеш-менеджер для работы с данными
|
|
38
|
-
- [**RxQuery v2**](./docs/query-v2/README.md) - кеш-менеджер v2 *(experimental)*
|
|
39
38
|
- [**React**](./docs/usage/react/README.md) - интеграция с React
|
|
40
39
|
- [**Devtools**](./docs/devtools/README.md) - инструменты разработчика
|
|
41
40
|
- [**DefaultOptions**](./docs/options/README.md) - глобальные настройки
|
|
@@ -96,7 +95,7 @@ const on10click$ = doubled$.obs.pipe(
|
|
|
96
95
|
);
|
|
97
96
|
|
|
98
97
|
const sub = on10click$.subscribe(() => {
|
|
99
|
-
console.log('Great!
|
|
98
|
+
console.log('Great! You first reached 10 clicks!');
|
|
100
99
|
});
|
|
101
100
|
// Не забываем отписаться
|
|
102
101
|
sub.unsubscribe();
|
|
@@ -104,17 +103,27 @@ sub.unsubscribe();
|
|
|
104
103
|
|
|
105
104
|
###### RxQuery (Корзина покупок)
|
|
106
105
|
```tsx
|
|
107
|
-
|
|
106
|
+
import {
|
|
107
|
+
createApi,
|
|
108
|
+
reactHooksPlugin,
|
|
109
|
+
} from '@fozy-labs/rx-toolkit';
|
|
110
|
+
|
|
111
|
+
const api = createApi({
|
|
112
|
+
plugins: [reactHooksPlugin()],
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const getCart = api.createResource({
|
|
116
|
+
key: 'cart',
|
|
108
117
|
queryFn: fetchCart,
|
|
109
118
|
});
|
|
110
119
|
|
|
111
|
-
const
|
|
112
|
-
queryFn:
|
|
113
|
-
link
|
|
114
|
-
|
|
120
|
+
const toggleCartItem = api.createCommand({
|
|
121
|
+
queryFn: fetchToggleCartItem,
|
|
122
|
+
links(link) {
|
|
123
|
+
link({
|
|
115
124
|
resource: getCart,
|
|
116
125
|
forwardArgs: () => undefined,
|
|
117
|
-
optimisticUpdate: (
|
|
126
|
+
optimisticUpdate: (draft, args) => {
|
|
118
127
|
const item = draft.items.find(i => i.id === args.id);
|
|
119
128
|
if (!item) return;
|
|
120
129
|
item.enabled = args.enabled;
|
|
@@ -124,8 +133,8 @@ const toggleCardItem = createCommand({
|
|
|
124
133
|
});
|
|
125
134
|
|
|
126
135
|
function ShoppingCart() {
|
|
127
|
-
const cartQuery =
|
|
128
|
-
const [toggleItem] =
|
|
136
|
+
const cartQuery = getCart.useResource();
|
|
137
|
+
const [toggleItem] = toggleCartItem.useCommand();
|
|
129
138
|
const cart = cartQuery.data;
|
|
130
139
|
|
|
131
140
|
return (
|
|
@@ -98,7 +98,7 @@ export function reduxDevtools(options = {}) {
|
|
|
98
98
|
return {
|
|
99
99
|
state(name, initState) {
|
|
100
100
|
const keys = name.split("/");
|
|
101
|
-
state = applyState(keys, initState, state);
|
|
101
|
+
state = applyState(keys, initState, state, existConsoleWarning);
|
|
102
102
|
pendingActionType = "create";
|
|
103
103
|
scheduler.schedule(flushToDevtools);
|
|
104
104
|
return (newState) => {
|
|
@@ -118,11 +118,26 @@ export function reduxDevtools(options = {}) {
|
|
|
118
118
|
},
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function existConsoleWarning(paths) {
|
|
122
|
+
if (typeof console === "undefined" || typeof console.warn !== "function") {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
const path = paths.join("/");
|
|
126
|
+
console.warn(`
|
|
127
|
+
[RxToolkit Redux Devtools] Warning: ${path} is already defined in the state.
|
|
128
|
+
This may lead to unexpected behavior in Redux Devtools.
|
|
129
|
+
Consider using a unique path for each state or ensure that states are properly clearedwhen completed.
|
|
130
|
+
`);
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
function applyState(keys, newState, state, warnFn) {
|
|
122
134
|
const acc = { ...state };
|
|
123
135
|
let current = acc;
|
|
124
136
|
keys.forEach((key, i, arr) => {
|
|
125
137
|
if (i === arr.length - 1) {
|
|
138
|
+
if (key in current && warnFn) {
|
|
139
|
+
warnFn(keys);
|
|
140
|
+
}
|
|
126
141
|
current[key] = newState;
|
|
127
142
|
}
|
|
128
143
|
else {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A hook that resolves to `useLayoutEffect` on the client and `useEffect` on the server.
|
|
4
|
+
*
|
|
5
|
+
* Used to prevent React hydration warnings when using layout effects with
|
|
6
|
+
* Server-Side Rendering (SSR).
|
|
7
|
+
*
|
|
8
|
+
* @param {React.EffectCallback} effect - Imperative function that can return a cleanup function.
|
|
9
|
+
* @param {React.DependencyList} [deps] - If present, effect will only activate if the values in the list change.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://react.dev React Docs: useLayoutEffect}
|
|
12
|
+
* @example
|
|
13
|
+
* useIsomorphicLayoutEffect(() => {
|
|
14
|
+
* console.log("Synchronous on client, standard on server");
|
|
15
|
+
* }, [data]);
|
|
16
|
+
*/
|
|
17
|
+
export declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A hook that resolves to `useLayoutEffect` on the client and `useEffect` on the server.
|
|
4
|
+
*
|
|
5
|
+
* Used to prevent React hydration warnings when using layout effects with
|
|
6
|
+
* Server-Side Rendering (SSR).
|
|
7
|
+
*
|
|
8
|
+
* @param {React.EffectCallback} effect - Imperative function that can return a cleanup function.
|
|
9
|
+
* @param {React.DependencyList} [deps] - If present, effect will only activate if the values in the list change.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://react.dev React Docs: useLayoutEffect}
|
|
12
|
+
* @example
|
|
13
|
+
* useIsomorphicLayoutEffect(() => {
|
|
14
|
+
* console.log("Synchronous on client, standard on server");
|
|
15
|
+
* }, [data]);
|
|
16
|
+
*/
|
|
17
|
+
export const useIsomorphicLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,5 @@ export * from "./common/options";
|
|
|
3
3
|
export * from "./common/react";
|
|
4
4
|
export * from "./common/utils/deepEqual";
|
|
5
5
|
export * from "./common/utils/shallowEqual";
|
|
6
|
-
export * from "./query";
|
|
7
6
|
export * from "./signals";
|
|
8
|
-
export *
|
|
7
|
+
export * from "./query";
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,5 @@ export * from "./common/options";
|
|
|
3
3
|
export * from "./common/react";
|
|
4
4
|
export * from "./common/utils/deepEqual";
|
|
5
5
|
export * from "./common/utils/shallowEqual";
|
|
6
|
-
export * from "./query";
|
|
7
6
|
export * from "./signals";
|
|
8
|
-
export *
|
|
7
|
+
export * from "./query";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IApi, IPlugin, TCreateApiOptions } from "../../query/types";
|
|
2
|
+
export declare function createApi<const TPlugins extends readonly IPlugin[] = readonly IPlugin[]>(options?: TCreateApiOptions<TPlugins>): IApi<TPlugins>;
|
|
3
|
+
/** @internal — re-exported for unit testing only */
|
|
4
|
+
export { mergeHooks } from "../core/api";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Api } from "../core/api";
|
|
2
|
+
export function createApi(options) {
|
|
3
|
+
// Safe cast: Api implements IApi (with default plugins). At runtime,
|
|
4
|
+
// plugin augmentations are applied via Object.assign in Api.createResource/createCommand.
|
|
5
|
+
// The generic TPlugins only affects the compile-time type of the returned object.
|
|
6
|
+
return new Api(options);
|
|
7
|
+
}
|
|
8
|
+
/** @internal — re-exported for unit testing only */
|
|
9
|
+
export { mergeHooks } from "../core/api";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createApi } from "./createApi";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createApi } from "./createApi";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentinel value passed as resource arguments to indicate that the query
|
|
3
|
+
* should be skipped (not executed). Useful for conditional fetching.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SKIP: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* Unique brand symbol used to distinguish {@link Keyed} wrappers
|
|
8
|
+
* from plain argument objects at runtime.
|
|
9
|
+
*/
|
|
10
|
+
export declare const KEYED_BRAND: unique symbol;
|
|
11
|
+
/** Current serialization version used by the snapshot/restore mechanism. */
|
|
12
|
+
export declare const CURRENT_SNAPSHOT_VERSION = 1;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// ==================== SKIP Sentinel ==
|
|
2
|
+
/**
|
|
3
|
+
* Sentinel value passed as resource arguments to indicate that the query
|
|
4
|
+
* should be skipped (not executed). Useful for conditional fetching.
|
|
5
|
+
*/
|
|
6
|
+
export const SKIP = Symbol("SKIP");
|
|
7
|
+
// ==================== Keyed Brand ====================
|
|
8
|
+
/**
|
|
9
|
+
* Unique brand symbol used to distinguish {@link Keyed} wrappers
|
|
10
|
+
* from plain argument objects at runtime.
|
|
11
|
+
*/
|
|
12
|
+
export const KEYED_BRAND = Symbol("KEYED_BRAND");
|
|
13
|
+
// ==================== Snapshot Version ====================
|
|
14
|
+
/** Current serialization version used by the snapshot/restore mechanism. */
|
|
15
|
+
export const CURRENT_SNAPSHOT_VERSION = 1;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IApi, ICommand, IResource, TApiSnapshot, TCommandOptions, TCreateApiOptions, TResourceOptions } from "../../../query/types";
|
|
2
|
+
export declare class Api implements IApi {
|
|
3
|
+
private readonly resources;
|
|
4
|
+
private readonly commands;
|
|
5
|
+
private readonly resourcesByKey;
|
|
6
|
+
private readonly keyPrefix;
|
|
7
|
+
private readonly plugins;
|
|
8
|
+
private readonly apiSerializeArgs;
|
|
9
|
+
private readonly apiResourceRetentionTime;
|
|
10
|
+
private readonly apiCommandRetentionTime;
|
|
11
|
+
private readonly snapshoter;
|
|
12
|
+
private readonly apiOnCacheEntryAdded;
|
|
13
|
+
private readonly apiOnQueryStarted;
|
|
14
|
+
private readonly syncer;
|
|
15
|
+
constructor(options?: TCreateApiOptions);
|
|
16
|
+
createResource: <TArgs = void, TData = unknown>(opts: TResourceOptions<TArgs, TData>) => IResource<TArgs, TData>;
|
|
17
|
+
createCommand: <TArgs = void, TData = unknown>(opts: TCommandOptions<TArgs, TData>) => ICommand<TArgs, TData>;
|
|
18
|
+
getSnapshot: () => TApiSnapshot;
|
|
19
|
+
resetAll: () => void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { stableStringify } from "../../../query/lib/stableStringify";
|
|
2
|
+
import { Command } from "../command/Command";
|
|
3
|
+
import { Resource } from "../resource/Resource";
|
|
4
|
+
import { Snapshoter } from "../snapshoter";
|
|
5
|
+
import { Syncer } from "../syncer";
|
|
6
|
+
import { DEFAULT_COMMAND_RETENTION_TIME, DEFAULT_RESOURCE_RETENTION_TIME } from "./constants";
|
|
7
|
+
import { mergeHooks } from "./mergeHooks";
|
|
8
|
+
import { normalizeLinks } from "./normalizeLinks";
|
|
9
|
+
export class Api {
|
|
10
|
+
resources = [];
|
|
11
|
+
commands = [];
|
|
12
|
+
resourcesByKey = new Map();
|
|
13
|
+
keyPrefix;
|
|
14
|
+
plugins;
|
|
15
|
+
apiSerializeArgs;
|
|
16
|
+
apiResourceRetentionTime;
|
|
17
|
+
apiCommandRetentionTime;
|
|
18
|
+
snapshoter;
|
|
19
|
+
apiOnCacheEntryAdded;
|
|
20
|
+
apiOnQueryStarted;
|
|
21
|
+
syncer;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.keyPrefix = options?.keyPrefix ?? null;
|
|
24
|
+
this.plugins = options?.plugins ?? [];
|
|
25
|
+
this.apiSerializeArgs = options?.serializeArgs ?? stableStringify;
|
|
26
|
+
this.apiResourceRetentionTime = options?.resourceRetentionTime ?? DEFAULT_RESOURCE_RETENTION_TIME;
|
|
27
|
+
this.apiCommandRetentionTime = options?.commandRetentionTime ?? DEFAULT_COMMAND_RETENTION_TIME;
|
|
28
|
+
this.snapshoter = new Snapshoter({
|
|
29
|
+
initialSnapshot: options?.initialSnapshot ?? null,
|
|
30
|
+
snapshotValidTime: options?.snapshotValidTime ?? false,
|
|
31
|
+
keyPrefix: this.keyPrefix,
|
|
32
|
+
});
|
|
33
|
+
this.apiOnCacheEntryAdded = options?.onCacheEntryAdded;
|
|
34
|
+
this.apiOnQueryStarted = options?.onQueryStarted;
|
|
35
|
+
const syncDriver = options?.syncDriver;
|
|
36
|
+
const defaultSync = options?.defaultSync ?? "none";
|
|
37
|
+
this.syncer = syncDriver
|
|
38
|
+
? new Syncer({ syncDriver, keyPrefix: this.keyPrefix, defaultSync, resourcesByKey: this.resourcesByKey })
|
|
39
|
+
: null;
|
|
40
|
+
// Install plugins
|
|
41
|
+
for (const plugin of this.plugins) {
|
|
42
|
+
plugin.install({ keyPrefix: this.keyPrefix ?? "" });
|
|
43
|
+
}
|
|
44
|
+
// Connect sync driver after setup
|
|
45
|
+
this.syncer?.connect();
|
|
46
|
+
}
|
|
47
|
+
createResource = (opts) => {
|
|
48
|
+
const effectiveRetentionTime = opts.retentionTime !== undefined ? opts.retentionTime : this.apiResourceRetentionTime;
|
|
49
|
+
const effectiveSerializeArgs = opts.serializeArgs ?? this.apiSerializeArgs;
|
|
50
|
+
const effectiveKey = this.keyPrefix != null && opts.key != null ? `${this.keyPrefix}/${opts.key}` : opts.key;
|
|
51
|
+
// Merge lifecycle hooks: API-level + resource-level
|
|
52
|
+
const mergedOnCacheEntryAdded = mergeHooks(this.apiOnCacheEntryAdded, opts.onCacheEntryAdded);
|
|
53
|
+
const mergedOnQueryStarted = mergeHooks(this.apiOnQueryStarted, opts.onQueryStarted);
|
|
54
|
+
// Snapshot hydration: build initialEntries if snapshot has matching resource data
|
|
55
|
+
const initialEntries = this.snapshoter.hydrateResource(opts.key, opts.snapshotValidTime);
|
|
56
|
+
const syncEnabled = this.syncer && this.syncer.isResourceSyncEnabled(opts);
|
|
57
|
+
const config = {
|
|
58
|
+
queryFn: opts.queryFn,
|
|
59
|
+
key: effectiveKey,
|
|
60
|
+
retentionTime: effectiveRetentionTime,
|
|
61
|
+
serializeArgs: effectiveSerializeArgs,
|
|
62
|
+
onCacheEntryAdded: mergedOnCacheEntryAdded,
|
|
63
|
+
onQueryStarted: mergedOnQueryStarted,
|
|
64
|
+
getDevtoolsKey: opts.getDevtoolsKey,
|
|
65
|
+
snapshot: initialEntries,
|
|
66
|
+
beforeQuery: syncEnabled
|
|
67
|
+
? this.syncer.beforeQuery
|
|
68
|
+
: undefined,
|
|
69
|
+
};
|
|
70
|
+
const resource = new Resource(config);
|
|
71
|
+
// Track for resetAll / getSnapshot
|
|
72
|
+
this.resources.push(resource);
|
|
73
|
+
if (effectiveKey) {
|
|
74
|
+
this.resourcesByKey.set(effectiveKey, resource);
|
|
75
|
+
}
|
|
76
|
+
// Plugin augmentation
|
|
77
|
+
let augmented = {};
|
|
78
|
+
for (const plugin of this.plugins) {
|
|
79
|
+
if (plugin.augmentResource) {
|
|
80
|
+
const additions = plugin.augmentResource(resource, opts);
|
|
81
|
+
augmented = { ...augmented, ...additions };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Spread augmented properties onto the resource object
|
|
85
|
+
Object.assign(resource, augmented);
|
|
86
|
+
return resource;
|
|
87
|
+
};
|
|
88
|
+
createCommand = (opts) => {
|
|
89
|
+
const effectiveRetentionTime = opts.retentionTime !== undefined ? opts.retentionTime : this.apiCommandRetentionTime;
|
|
90
|
+
const effectiveKey = this.keyPrefix != null && opts.key != null ? `${this.keyPrefix}/${opts.key}` : opts.key;
|
|
91
|
+
// Merge lifecycle hooks: API-level + command-level
|
|
92
|
+
const mergedOnCacheEntryAdded = mergeHooks(this.apiOnCacheEntryAdded, opts.onCacheEntryAdded);
|
|
93
|
+
const mergedOnQueryStarted = mergeHooks(this.apiOnQueryStarted, opts.onQueryStarted);
|
|
94
|
+
const config = {
|
|
95
|
+
queryFn: opts.queryFn,
|
|
96
|
+
key: effectiveKey,
|
|
97
|
+
links: normalizeLinks(opts.links),
|
|
98
|
+
retentionTime: effectiveRetentionTime,
|
|
99
|
+
onCacheEntryAdded: mergedOnCacheEntryAdded,
|
|
100
|
+
onQueryStarted: mergedOnQueryStarted,
|
|
101
|
+
};
|
|
102
|
+
const command = new Command(config);
|
|
103
|
+
// Track for resetAll
|
|
104
|
+
this.commands.push(command);
|
|
105
|
+
// Plugin augmentation
|
|
106
|
+
let augmented = {};
|
|
107
|
+
for (const plugin of this.plugins) {
|
|
108
|
+
if (plugin.augmentCommand) {
|
|
109
|
+
const additions = plugin.augmentCommand(command, opts);
|
|
110
|
+
augmented = { ...augmented, ...additions };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
Object.assign(command, augmented);
|
|
114
|
+
return command;
|
|
115
|
+
};
|
|
116
|
+
getSnapshot = () => {
|
|
117
|
+
return this.snapshoter.getSnapshot(this.resources);
|
|
118
|
+
};
|
|
119
|
+
resetAll = () => {
|
|
120
|
+
for (const resource of this.resources) {
|
|
121
|
+
resource.reset();
|
|
122
|
+
}
|
|
123
|
+
for (const command of this.commands) {
|
|
124
|
+
command.reset();
|
|
125
|
+
}
|
|
126
|
+
// Clean up sync state and reconnect
|
|
127
|
+
this.syncer?.cleanup();
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** @internal — exported for unit testing only */
|
|
2
|
+
export function mergeHooks(apiHook, localHook) {
|
|
3
|
+
if (!apiHook && !localHook)
|
|
4
|
+
return undefined;
|
|
5
|
+
if (!apiHook)
|
|
6
|
+
return localHook;
|
|
7
|
+
if (!localHook)
|
|
8
|
+
return apiHook;
|
|
9
|
+
// Both hooks may be async. The callers use sync try/catch and suppress
|
|
10
|
+
// lifecycle errors, so the merged function must never produce an unhandled
|
|
11
|
+
// rejection — catch each hook independently.
|
|
12
|
+
return (async (...args) => {
|
|
13
|
+
try {
|
|
14
|
+
await apiHook(...args);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
/* lifecycle error suppressed */
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
await localHook(...args);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
/* lifecycle error suppressed */
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Observable, Subject } from "rxjs";
|
|
2
|
+
import type { ICacheEntry, ICacheEntryOptions } from "../../../query/types";
|
|
3
|
+
/**
|
|
4
|
+
* Internal reactive container wrapping a Signal.state<TState>.
|
|
5
|
+
* Implements ICacheEntry<TState>.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CacheEntry<TState> implements ICacheEntry<TState> {
|
|
8
|
+
private _state$;
|
|
9
|
+
private _isCompleted;
|
|
10
|
+
readonly completed$: Subject<void>;
|
|
11
|
+
readonly obs: Observable<TState>;
|
|
12
|
+
readonly state$: import("../../../signals").ReadableSignalFnLike<TState>;
|
|
13
|
+
constructor(initialState: TState, options: ICacheEntryOptions<TState>);
|
|
14
|
+
/** Non-reactive read */
|
|
15
|
+
peek(): TState;
|
|
16
|
+
/** Update stored state (no-op if completed) */
|
|
17
|
+
set(state: TState): void;
|
|
18
|
+
/** Fire onClean$ and mark completed. Subsequent set() calls are no-ops. */
|
|
19
|
+
complete(): void;
|
|
20
|
+
private _getResetOnRefCountZero;
|
|
21
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { finalize, ReplaySubject, share, Subject, timer } from "rxjs";
|
|
2
|
+
import { signalize, State } from "../../../signals";
|
|
3
|
+
/**
|
|
4
|
+
* Internal reactive container wrapping a Signal.state<TState>.
|
|
5
|
+
* Implements ICacheEntry<TState>.
|
|
6
|
+
*/
|
|
7
|
+
export class CacheEntry {
|
|
8
|
+
_state$;
|
|
9
|
+
_isCompleted = false;
|
|
10
|
+
completed$ = new Subject();
|
|
11
|
+
obs;
|
|
12
|
+
state$;
|
|
13
|
+
constructor(initialState, options) {
|
|
14
|
+
this._state$ = new State(initialState, {
|
|
15
|
+
key: options?.devtoolsKey,
|
|
16
|
+
beforeDevtoolsPush: options?.beforeDevtoolsPush,
|
|
17
|
+
});
|
|
18
|
+
this.obs = this._state$.obs.pipe(finalize(() => {
|
|
19
|
+
this.complete();
|
|
20
|
+
}), share({
|
|
21
|
+
connector: () => new ReplaySubject(1),
|
|
22
|
+
resetOnRefCountZero: this._getResetOnRefCountZero(options.retentionTime),
|
|
23
|
+
resetOnComplete: true,
|
|
24
|
+
}));
|
|
25
|
+
this.state$ = signalize(this.obs);
|
|
26
|
+
}
|
|
27
|
+
/** Non-reactive read */
|
|
28
|
+
peek() {
|
|
29
|
+
return this._state$.peek();
|
|
30
|
+
}
|
|
31
|
+
/** Update stored state (no-op if completed) */
|
|
32
|
+
set(state) {
|
|
33
|
+
if (this._isCompleted)
|
|
34
|
+
return;
|
|
35
|
+
this._state$.set(state);
|
|
36
|
+
}
|
|
37
|
+
/** Fire onClean$ and mark completed. Subsequent set() calls are no-ops. */
|
|
38
|
+
complete() {
|
|
39
|
+
if (this._isCompleted)
|
|
40
|
+
return;
|
|
41
|
+
this._isCompleted = true;
|
|
42
|
+
this.completed$.next();
|
|
43
|
+
this.completed$.complete();
|
|
44
|
+
this._state$.complete();
|
|
45
|
+
}
|
|
46
|
+
_getResetOnRefCountZero(retentionTime) {
|
|
47
|
+
if (retentionTime === false)
|
|
48
|
+
return false;
|
|
49
|
+
if (retentionTime <= 0)
|
|
50
|
+
return true;
|
|
51
|
+
const lifetime = retentionTime;
|
|
52
|
+
return () => timer(lifetime);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ICacheMap } from "../../../query/types";
|
|
2
|
+
/** Simple key→value container mapping string keys to cache entries. */
|
|
3
|
+
export declare class CacheMap<TValue> implements ICacheMap<TValue> {
|
|
4
|
+
private readonly _map;
|
|
5
|
+
/** Number of entries currently stored. */
|
|
6
|
+
get size(): number;
|
|
7
|
+
/** Return entry by key, or `undefined` if absent. */
|
|
8
|
+
get(key: string): TValue | undefined;
|
|
9
|
+
/** Store an entry under the given key. */
|
|
10
|
+
set(key: string, value: TValue): void;
|
|
11
|
+
/** Remove an entry. Returns `true` if the entry existed. */
|
|
12
|
+
delete(key: string): boolean;
|
|
13
|
+
/** Check whether an entry with the given key exists. */
|
|
14
|
+
has(key: string): boolean;
|
|
15
|
+
/** Remove all entries. */
|
|
16
|
+
clear(): void;
|
|
17
|
+
/** Iterate over all stored values. */
|
|
18
|
+
values(): IterableIterator<TValue>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Simple key→value container mapping string keys to cache entries. */
|
|
2
|
+
export class CacheMap {
|
|
3
|
+
_map = new Map();
|
|
4
|
+
/** Number of entries currently stored. */
|
|
5
|
+
get size() {
|
|
6
|
+
return this._map.size;
|
|
7
|
+
}
|
|
8
|
+
/** Return entry by key, or `undefined` if absent. */
|
|
9
|
+
get(key) {
|
|
10
|
+
return this._map.get(key);
|
|
11
|
+
}
|
|
12
|
+
/** Store an entry under the given key. */
|
|
13
|
+
set(key, value) {
|
|
14
|
+
this._map.set(key, value);
|
|
15
|
+
}
|
|
16
|
+
/** Remove an entry. Returns `true` if the entry existed. */
|
|
17
|
+
delete(key) {
|
|
18
|
+
return this._map.delete(key);
|
|
19
|
+
}
|
|
20
|
+
/** Check whether an entry with the given key exists. */
|
|
21
|
+
has(key) {
|
|
22
|
+
return this._map.has(key);
|
|
23
|
+
}
|
|
24
|
+
/** Remove all entries. */
|
|
25
|
+
clear() {
|
|
26
|
+
this._map.clear();
|
|
27
|
+
}
|
|
28
|
+
/** Iterate over all stored values. */
|
|
29
|
+
values() {
|
|
30
|
+
return this._map.values();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IPatchHandle, IQueryCacheEntry, IQueryCacheEntryOptions, Keyed } from "../../../query/types";
|
|
2
|
+
import type { ReadableSignalFnLike } from "../../../signals/types";
|
|
3
|
+
import { Machine } from "../machine/Machine";
|
|
4
|
+
import { CacheEntry } from "./CacheEntry";
|
|
5
|
+
export declare class QueryCacheEntry<TArgs, TData> extends CacheEntry<Machine<TArgs, TData>> implements IQueryCacheEntry<TArgs, TData> {
|
|
6
|
+
readonly keyedArgs: Keyed<TArgs>;
|
|
7
|
+
readonly machine$: ReadableSignalFnLike<Machine<TArgs, TData>>;
|
|
8
|
+
private _queryFn;
|
|
9
|
+
private _abortController;
|
|
10
|
+
constructor(options: IQueryCacheEntryOptions<TArgs, TData>);
|
|
11
|
+
/** Transition to refreshing and re-fetch data. Valid from success or refresh-error. */
|
|
12
|
+
refresh(): void;
|
|
13
|
+
/** Re-execute query after error. Valid from error state only. */
|
|
14
|
+
retry(): void;
|
|
15
|
+
/** Create an optimistic patch. Returns null if state has no data. */
|
|
16
|
+
createPatch(patchFn: (data: TData) => void): IPatchHandle | null;
|
|
17
|
+
/** Abort any in-flight request before completing the entry. */
|
|
18
|
+
complete(): void;
|
|
19
|
+
/** @internal Called by Resource when beforeQuery intercept needs to trigger the query. */
|
|
20
|
+
_execute(): void;
|
|
21
|
+
}
|