@fozy-labs/rx-toolkit 0.4.1 → 0.4.3

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.
Files changed (112) hide show
  1. package/README.md +44 -39
  2. package/dist/common/devtools/combineDevtools.d.ts +2 -0
  3. package/dist/common/devtools/combineDevtools.js +10 -0
  4. package/dist/common/devtools/index.d.ts +3 -0
  5. package/dist/common/devtools/index.js +3 -0
  6. package/dist/common/devtools/reduxDevtools.d.ts +2 -0
  7. package/dist/common/devtools/reduxDevtools.js +24 -0
  8. package/dist/common/devtools/types.d.ts +6 -0
  9. package/dist/{query/api → common/options}/DefaultOptions.d.ts +2 -2
  10. package/dist/{query/api → common/options}/DefaultOptions.js +1 -1
  11. package/dist/common/options/SharedOptions.d.ts +5 -0
  12. package/dist/common/options/index.d.ts +1 -0
  13. package/dist/common/options/index.js +1 -0
  14. package/dist/{react-hooks → common/react}/index.d.ts +2 -3
  15. package/dist/{react-hooks → common/react}/index.js +2 -3
  16. package/dist/{react-hooks → common/react}/useObservable.js +2 -2
  17. package/dist/{react-hooks → common/react}/useSyncObservable.js +2 -1
  18. package/dist/index.d.ts +4 -2
  19. package/dist/index.js +4 -2
  20. package/dist/query/api/createOperation.d.ts +1 -5
  21. package/dist/query/api/createOperation.js +0 -4
  22. package/dist/query/api/createResource.d.ts +1 -1
  23. package/dist/query/core/Opertation/Operation.d.ts +2 -3
  24. package/dist/query/core/Opertation/Operation.js +6 -5
  25. package/dist/query/core/Opertation/OperationAgent.d.ts +3 -3
  26. package/dist/query/core/Opertation/OperationAgent.js +3 -3
  27. package/dist/query/core/QueriesCache.js +12 -6
  28. package/dist/query/core/Resource/Resource.d.ts +15 -3
  29. package/dist/query/core/Resource/Resource.js +36 -4
  30. package/dist/query/core/Resource/ResourceAgent.d.ts +2 -2
  31. package/dist/query/core/Resource/ResourceAgent.js +3 -3
  32. package/dist/query/core/Resource/ResourceRef.d.ts +2 -1
  33. package/dist/query/core/Resource/ResourceRef.js +96 -2
  34. package/dist/query/index.d.ts +1 -2
  35. package/dist/query/index.js +1 -2
  36. package/dist/query/lib/IndirectMap.js +1 -1
  37. package/dist/query/lib/ReactiveCache.js +2 -2
  38. package/dist/query/react/useOperationAgent.d.ts +1 -2
  39. package/dist/query/react/useOperationAgent.js +2 -1
  40. package/dist/query/react/useResourceAgent.d.ts +2 -3
  41. package/dist/query/react/useResourceAgent.js +4 -3
  42. package/dist/query/react/useResourceRef.d.ts +5 -0
  43. package/dist/query/react/useResourceRef.js +8 -0
  44. package/dist/query/types/Operation.types.d.ts +44 -3
  45. package/dist/query/types/Resource.types.d.ts +17 -2
  46. package/dist/query/types/index.d.ts +3 -0
  47. package/dist/query/types/index.js +3 -0
  48. package/dist/signals/base/Batcher.d.ts +6 -0
  49. package/dist/signals/base/Batcher.js +55 -0
  50. package/dist/{signal → signals}/base/Computed.d.ts +5 -2
  51. package/dist/{signal → signals}/base/Computed.js +7 -3
  52. package/dist/{signal → signals}/base/Effect.d.ts +3 -3
  53. package/dist/signals/base/Effect.js +51 -0
  54. package/dist/signals/base/Indexer.d.ts +4 -0
  55. package/dist/signals/base/Indexer.js +6 -0
  56. package/dist/{signal → signals}/base/ReadonlySignal.d.ts +4 -1
  57. package/dist/signals/base/ReadonlySignal.js +46 -0
  58. package/dist/{signal → signals}/base/Signal.d.ts +14 -3
  59. package/dist/{signal → signals}/base/Signal.js +23 -3
  60. package/dist/signals/base/Tracker.d.ts +10 -0
  61. package/dist/signals/base/Tracker.js +7 -0
  62. package/dist/{signal → signals}/base/types.d.ts +9 -1
  63. package/dist/signals/base/types.js +1 -0
  64. package/dist/{signal → signals}/extends/LocalSignal.d.ts +1 -1
  65. package/dist/{signal → signals}/extends/LocalSignal.js +3 -3
  66. package/dist/{signal → signals}/index.d.ts +1 -0
  67. package/dist/{signal → signals}/index.js +1 -0
  68. package/dist/{signal → signals}/operators/filterUpdates.js +1 -1
  69. package/dist/signals/operators/index.d.ts +3 -0
  70. package/dist/signals/operators/index.js +3 -0
  71. package/dist/{signal → signals}/operators/mapSignals.js +1 -1
  72. package/dist/{signal → signals}/operators/signalize.d.ts +1 -1
  73. package/dist/{signal → signals}/operators/signalize.js +1 -1
  74. package/dist/signals/react/index.d.ts +1 -0
  75. package/dist/signals/react/index.js +1 -0
  76. package/dist/{react-hooks → signals/react}/useSignal.d.ts +1 -1
  77. package/dist/{react-hooks → signals/react}/useSignal.js +1 -1
  78. package/docs/devtools/README.md +95 -0
  79. package/docs/query/README.md +25 -14
  80. package/docs/signals/README.md +11 -8
  81. package/package.json +13 -8
  82. package/dist/query/api/createDevtools.d.ts +0 -1
  83. package/dist/query/api/createDevtools.js +0 -6
  84. package/dist/query/api/createSubResource.d.ts +0 -0
  85. package/dist/query/api/createSubResource.js +0 -1
  86. package/dist/query/core/SharedOptions.d.ts +0 -5
  87. package/dist/signal/base/Batcher.d.ts +0 -7
  88. package/dist/signal/base/Batcher.js +0 -21
  89. package/dist/signal/base/Effect.js +0 -69
  90. package/dist/signal/base/ReadonlySignal.js +0 -20
  91. package/dist/signal/base/Tracker.d.ts +0 -5
  92. package/dist/signal/base/Tracker.js +0 -7
  93. package/dist/signal/operators/batch.d.ts +0 -2
  94. package/dist/signal/operators/batch.js +0 -27
  95. package/dist/signal/operators/index.d.ts +0 -4
  96. package/dist/signal/operators/index.js +0 -4
  97. /package/dist/{signal/base → common/devtools}/types.js +0 -0
  98. /package/dist/{query/core → common/options}/SharedOptions.js +0 -0
  99. /package/dist/{react-hooks → common/react}/useConstant.d.ts +0 -0
  100. /package/dist/{react-hooks → common/react}/useConstant.js +0 -0
  101. /package/dist/{react-hooks → common/react}/useEventHandler.d.ts +0 -0
  102. /package/dist/{react-hooks → common/react}/useEventHandler.js +0 -0
  103. /package/dist/{react-hooks → common/react}/useObservable.d.ts +0 -0
  104. /package/dist/{react-hooks → common/react}/useSyncObservable.d.ts +0 -0
  105. /package/dist/{signal → signals}/base/SyncObservable.d.ts +0 -0
  106. /package/dist/{signal → signals}/base/SyncObservable.js +0 -0
  107. /package/dist/{signal → signals}/base/index.d.ts +0 -0
  108. /package/dist/{signal → signals}/base/index.js +0 -0
  109. /package/dist/{signal → signals}/extends/index.d.ts +0 -0
  110. /package/dist/{signal → signals}/extends/index.js +0 -0
  111. /package/dist/{signal → signals}/operators/filterUpdates.d.ts +0 -0
  112. /package/dist/{signal → signals}/operators/mapSignals.d.ts +0 -0
package/README.md CHANGED
@@ -27,24 +27,25 @@ RxToolkit решает эти проблемы, предоставляя сво
27
27
  - 🔧 **Framework-agnostic** — Стройте систему и описывайте логику в изолированном месте.
28
28
  - ⚡ **Built on RxJS** — Наследует всю мощь RxJS.
29
29
  - 💾 **Кеш-менеджер** — Предоставляет Query реализацию для работы с данными.
30
- - 🔷 **TypeScript-first** — Полная типизация из коробки.
31
- - 🔗 **Интеграция с фреймворками** — Как и RxJS напрямую работает в Angular, Svelte и SolidJS.
32
- Для React предоставляет хуки из коробки.
30
+ - 🔷 **TypeScript-first** — Полная типизация.
31
+ - 🔗 **Интеграция с фреймворками** — Как и RxJS напрямую работает в Angular, Svelte и SolidJS.
32
+ Поставляется с React-хуками из коробки.
33
33
 
34
34
  ## 📚 Документация
35
35
  - [**RxSignals**](./docs/signals/README.md) - реактивные примитивы
36
36
  - [**RxQuery**](./docs/query/README.md) - кеш-менеджер для работы с данными
37
37
  - [**React**](./docs/usage/react/README.md) - интеграция с React
38
+ - [**Devtools**](./docs/devtools/README.md) - инструменты разработчика
38
39
 
39
40
  ## 🌟 Примеры
40
41
 
41
42
  ###### Создаем сигнал
42
43
  ```typescript
43
- // Описываете логику в обычном JavaScript
44
+ // Описываем логику в обычном JavaScript
44
45
  const store = {
45
- count$: new Signal(0),
46
- doubled$: new Computed(() => store.count$.value * 2),
47
- increment: () => store.count$.next(store.count$.value + 1)
46
+ count$: new Signal(0),
47
+ doubled$: new Computed(() => store.count$.value * 2),
48
+ increment: () => store.count$.value++,
48
49
  };
49
50
  ```
50
51
 
@@ -59,20 +60,25 @@ count$ = toSignal(store.count$);
59
60
  // Angular pipe
60
61
  {{ store.count$ | async }}
61
62
 
63
+ // SolidJS
64
+ const count$ = from(store.count$)
65
+
62
66
  // Svelte
63
67
  $: count = store.count$;
64
68
  ```
65
69
 
66
70
  ###### Работаем с RxJS
71
+
67
72
  ```typescript
68
73
  // Создаем Observable
69
74
  const clicker$ = fromEvent(document, 'click').pipe(
70
75
  debounceTime(300),
71
- scan(count => count + 1, 0)
76
+ scan(count => count + 1, 0),
77
+ startWith(0),
72
78
  );
73
79
 
74
80
  // Получаем сигнал из Observable
75
- const clickCount$ = new ReadonlySignal(clicker$);
81
+ const clickCount$ = signalize(clicker$);
76
82
  const doubled$ = new Computed(() => clickCount$.value * 2);
77
83
 
78
84
  console.log(doubled$.value); // Всегда актуальное значение
@@ -84,7 +90,7 @@ const on10click$ = doubled$.pipe(
84
90
  );
85
91
 
86
92
  on10click$.subscribe(() => {
87
- console.log('Great! That you first reached 10 clicks');
93
+ console.log('Great! That you first reached 10 clicks!');
88
94
  });
89
95
 
90
96
  ```
@@ -92,40 +98,39 @@ on10click$.subscribe(() => {
92
98
  ###### RxQuery (Корзина покупок)
93
99
  ```tsx
94
100
  const getCart = createResource({
95
- queryFn: fetchCart,
101
+ queryFn: fetchCart,
96
102
  });
97
103
 
98
104
  const toggleCardItem = createOperation({
99
- queryFn: fetchToggleItem,
100
- link(add) {
101
- add({
102
- resource: getCart,
103
- forwardArgs: () => undefined,
104
- optimisticUpdate: ({ draft, data, args }) => {
105
- const item = draft.items.find(i => i.id === data.id);
106
- if (!item) return;
107
- item.enabled = args.enabled;
108
- }
109
- })
110
- }
105
+ queryFn: fetchToggleCardItem,
106
+ link(add) {
107
+ add({
108
+ resource: getCart,
109
+ forwardArgs: () => undefined,
110
+ optimisticUpdate: ({ draft, data, args }) => {
111
+ const item = draft.items.find(i => i.id === data.id);
112
+ if (!item) return;
113
+ item.enabled = args.enabled;
114
+ }
115
+ })
116
+ }
111
117
  });
112
118
 
113
119
  function ShoppingCart() {
114
- const cartQuery = useResourceAgent(getCart);
115
- const [toggleItem] = useOperationAgent(toggleCardItem);
116
- const cart = cartQuery.data;
117
-
118
- return (
119
- <Container isLoading={cartQuery.isLoading}>
120
- {cart?.items.map(item => (
121
- <CartItem
122
- key={item.id}
123
- item={item}
124
- onToggle={() => toggleItem({ id: item.id, enabled: !item.enabled })}
125
- />
126
- ))}
127
- <Total amount={cart?.total} />
128
- </Container>
129
- );
120
+ const cartQuery = useResourceAgent(getCart);
121
+ const [toggleItem] = useOperationAgent(toggleCardItem);
122
+ const cart = cartQuery.data;
123
+
124
+ return (
125
+ <Container isLoading={cartQuery.isLoading}>
126
+ {cart?.items.map(item => (
127
+ <CartItem
128
+ key={item.id}
129
+ item={item}
130
+ onToggle={() => toggleItem({ id: item.id, enabled: !item.enabled })}
131
+ />
132
+ ))}
133
+ </Container>
134
+ );
130
135
  }
131
136
  ```
@@ -0,0 +1,2 @@
1
+ import { DevtoolsLike } from "./types";
2
+ export declare function combineDevtools(...devtools: DevtoolsLike[]): DevtoolsLike;
@@ -0,0 +1,10 @@
1
+ export function combineDevtools(...devtools) {
2
+ return {
3
+ state(name, initState) {
4
+ const updaters = devtools.map(d => d.state(name, initState));
5
+ return (newState) => {
6
+ updaters.forEach(update => update(newState));
7
+ };
8
+ }
9
+ };
10
+ }
@@ -0,0 +1,3 @@
1
+ export * from './reduxDevtools';
2
+ export * from './combineDevtools';
3
+ export * from './types';
@@ -0,0 +1,3 @@
1
+ export * from './reduxDevtools';
2
+ export * from './combineDevtools';
3
+ export * from './types';
@@ -0,0 +1,2 @@
1
+ import { DevtoolsLike } from "./types";
2
+ export declare function reduxDevtools(): DevtoolsLike;
@@ -0,0 +1,24 @@
1
+ import { Batcher } from "../../signals";
2
+ export function reduxDevtools() {
3
+ let state = {};
4
+ // @ts-ignore
5
+ const reduxDevtools = window.__REDUX_DEVTOOLS_EXTENSION__.connect({ name: 'RxToolkit' });
6
+ reduxDevtools.init(state);
7
+ const scheduler = Batcher.scheduler(Infinity);
8
+ const updateFn = () => {
9
+ reduxDevtools.send({ type: 'update' }, state);
10
+ };
11
+ const createFn = () => {
12
+ reduxDevtools.send({ type: 'create' }, state);
13
+ };
14
+ return {
15
+ state(name, initState) {
16
+ state = { ...state, [name]: initState };
17
+ scheduler.schedule(createFn);
18
+ return (newState) => {
19
+ state = { ...state, [name]: newState };
20
+ scheduler.schedule(updateFn);
21
+ };
22
+ }
23
+ };
24
+ }
@@ -0,0 +1,6 @@
1
+ export interface DevtoolsStateLike<T = any> {
2
+ (newState: T): void;
3
+ }
4
+ export interface DevtoolsLike {
5
+ state<T>(name: string, initState: T): DevtoolsStateLike<T>;
6
+ }
@@ -1,6 +1,6 @@
1
- import { Devtools } from "@reatom/devtools";
1
+ import type { DevtoolsLike } from "../../common/devtools";
2
2
  type Update = Partial<{
3
- DEVTOOLS: Devtools | null;
3
+ DEVTOOLS: DevtoolsLike | null;
4
4
  onError: (error: unknown) => void;
5
5
  }>;
6
6
  export declare class DefaultOptions {
@@ -1,4 +1,4 @@
1
- import { SharedOptions } from "../../query/core/SharedOptions";
1
+ import { SharedOptions } from "./SharedOptions";
2
2
  export class DefaultOptions {
3
3
  static update(part) {
4
4
  if (part.DEVTOOLS !== undefined)
@@ -0,0 +1,5 @@
1
+ import { DevtoolsLike } from "../../common/devtools";
2
+ export declare class SharedOptions {
3
+ static DEVTOOLS: DevtoolsLike | null;
4
+ static onError: ((error: unknown) => void) | null;
5
+ }
@@ -0,0 +1 @@
1
+ export * from './DefaultOptions';
@@ -0,0 +1 @@
1
+ export * from './DefaultOptions';
@@ -1,5 +1,4 @@
1
- export * from './useSignal';
1
+ export * from './useConstant';
2
+ export * from './useEventHandler';
2
3
  export * from './useObservable';
3
4
  export * from './useSyncObservable';
4
- export * from './useEventHandler';
5
- export * from './useConstant';
@@ -1,5 +1,4 @@
1
- export * from './useSignal';
1
+ export * from './useConstant';
2
+ export * from './useEventHandler';
2
3
  export * from './useObservable';
3
4
  export * from './useSyncObservable';
4
- export * from './useEventHandler';
5
- export * from './useConstant';
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
- import { useEventHandler } from "../react-hooks/useEventHandler";
3
2
  import { BehaviorSubject } from 'rxjs';
4
- import { useConstant } from "../react-hooks/useConstant";
3
+ import { useConstant } from "./useConstant";
4
+ import { useEventHandler } from "./useEventHandler";
5
5
  const NONE = Symbol('NONE');
6
6
  /**
7
7
  * Hook for automatically subscribing and unsubscribing from an Observable.
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { BehaviorSubject } from 'rxjs';
3
- import { useConstant, useEventHandler } from "../react-hooks";
3
+ import { useConstant } from "./useConstant";
4
+ import { useEventHandler } from "./useEventHandler";
4
5
  const NONE = Symbol('NONE');
5
6
  /**
6
7
  * Hook for automatically subscribing and unsubscribing from an Observable.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './common/devtools';
2
+ export * from './common/options';
3
+ export * from './common/react';
1
4
  export * from './query';
2
- export * from './signal';
3
- export * from './react-hooks';
5
+ export * from './signals';
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './common/devtools';
2
+ export * from './common/options';
3
+ export * from './common/react';
1
4
  export * from './query';
2
- export * from './signal';
3
- export * from './react-hooks';
5
+ export * from './signals';
@@ -1,7 +1,3 @@
1
- import type { OperationCreateOptions, OperationDefinition } from "../../query/types/Operation.types";
1
+ import type { OperationCreateOptions, OperationDefinition } from "../../query/types";
2
2
  import { Operation } from "../../query/core/Opertation/Operation";
3
3
  export declare const createOperation: <ARGS, RESULT, SELECTED = never>(options: OperationCreateOptions<OperationDefinition<ARGS, RESULT, SELECTED>>) => Operation<OperationDefinition<ARGS, RESULT, SELECTED>>;
4
- /**
5
- * @deprecated Use `createOperation` instead.
6
- */
7
- export declare const createMutationApi: <ARGS, RESULT, SELECTED = never>(options: OperationCreateOptions<OperationDefinition<ARGS, RESULT, SELECTED>>) => Operation<OperationDefinition<ARGS, RESULT, SELECTED>>;
@@ -1,6 +1,2 @@
1
1
  import { Operation } from "../../query/core/Opertation/Operation";
2
2
  export const createOperation = ((options) => new Operation(options));
3
- /**
4
- * @deprecated Use `createOperation` instead.
5
- */
6
- export const createMutationApi = createOperation;
@@ -1,3 +1,3 @@
1
- import type { ResourceCreateOptions, ResourceDefinition } from "../../query/types/Resource.types";
1
+ import type { ResourceCreateOptions, ResourceDefinition } from "../../query/types";
2
2
  import { Resource } from "../../query/core/Resource/Resource";
3
3
  export declare const createResource: <ARGS, RESULT, SELECTED = never>(options: ResourceCreateOptions<ResourceDefinition<ARGS, RESULT, SELECTED>>) => Resource<ResourceDefinition<ARGS, RESULT, SELECTED>>;
@@ -1,6 +1,5 @@
1
- import { ReactiveCache } from "../../../query/lib/ReactiveCache";
2
- import { FallbackOnNever } from "../../../query/types/shared.types";
3
- import { OperationCreateOptions, OperationDefinition, OperationInstance } from "../../../query/types/Operation.types";
1
+ import type { ReactiveCache } from "../../../query/lib/ReactiveCache";
2
+ import type { FallbackOnNever, OperationCreateOptions, OperationDefinition, OperationInstance } from "../../../query/types";
4
3
  import { QueriesCache } from "../QueriesCache";
5
4
  import { OperationAgent } from "./OperationAgent";
6
5
  export type CoreOperationQueryState<D extends OperationDefinition> = {
@@ -1,5 +1,5 @@
1
+ import { SharedOptions } from "../../../common/options/SharedOptions";
1
2
  import { QueriesCache } from "../QueriesCache";
2
- import { SharedOptions } from "../SharedOptions";
3
3
  import { OperationAgent } from "./OperationAgent";
4
4
  class OperationQueryState {
5
5
  static create() {
@@ -50,7 +50,7 @@ class OperationQueryState {
50
50
  }
51
51
  export class Operation {
52
52
  _options;
53
- _queriesCache = new QueriesCache('opr');
53
+ _queriesCache = new QueriesCache('Operation');
54
54
  _links = [];
55
55
  constructor(_options) {
56
56
  this._options = _options;
@@ -89,7 +89,7 @@ export class Operation {
89
89
  state.unlocker = ref.lock();
90
90
  }
91
91
  if (link.optimisticUpdate && ref.has) {
92
- state.patch = ref.update((draft) => {
92
+ state.patch = ref.patch((draft) => {
93
93
  return link.optimisticUpdate({ draft, args });
94
94
  });
95
95
  }
@@ -102,7 +102,7 @@ export class Operation {
102
102
  /**
103
103
  * Обновляем связанные ресурсы
104
104
  */
105
- linksMeta.forEach(({ link, ref }) => {
105
+ linksMeta.forEach(({ link, ref, state }) => {
106
106
  if (link.update && ref.has) {
107
107
  ref.update((draft) => {
108
108
  return link.update({ draft, args, data });
@@ -111,6 +111,7 @@ export class Operation {
111
111
  if (link.create && !ref.has) {
112
112
  ref.create(link.create({ args, data }));
113
113
  }
114
+ state.patch?.commit();
114
115
  });
115
116
  })
116
117
  .catch((error) => {
@@ -120,7 +121,7 @@ export class Operation {
120
121
  * Обновляем связанные ресурсы
121
122
  */
122
123
  linksMeta.forEach(({ state }) => {
123
- state.patch?.rollback();
124
+ state.patch?.abort();
124
125
  });
125
126
  })
126
127
  .finally(() => {
@@ -1,5 +1,5 @@
1
- import { Computed } from "../../../signal";
2
- import { OperationAgentInstanse, OperationDefinition } from "../../../query/types/Operation.types";
1
+ import { OperationAgentInstanse, OperationDefinition } from "../../../query/types";
2
+ import { Computed } from "../../../signals";
3
3
  import type { Operation } from "./Operation";
4
4
  export declare class OperationAgent<D extends OperationDefinition> implements OperationAgentInstanse<D> {
5
5
  private _operation;
@@ -10,7 +10,7 @@ export declare class OperationAgent<D extends OperationDefinition> implements Op
10
10
  isSuccess: boolean;
11
11
  isError: boolean;
12
12
  error: {} | undefined;
13
- data: NonNullable<import("../../types/shared.types").FallbackOnNever<D["Selected"], D["Result"]>> | undefined;
13
+ data: NonNullable<import("../../../query/types").FallbackOnNever<D["Selected"], D["Result"]>> | undefined;
14
14
  args: D["Args"];
15
15
  }>;
16
16
  constructor(_operation: Operation<D>);
@@ -1,9 +1,9 @@
1
- import { Computed, Signal } from "../../../signal";
1
+ import { Computed, Signal } from "../../../signals";
2
2
  export class OperationAgent {
3
3
  _operation;
4
4
  _operations$ = new Signal({
5
5
  current$: null,
6
- });
6
+ }, { disableDevtools: true });
7
7
  state$ = new Computed(() => {
8
8
  const operations = this._operations$.value;
9
9
  const currState = operations.current$?.value;
@@ -28,7 +28,7 @@ export class OperationAgent {
28
28
  data: currState.data ?? undefined,
29
29
  args: currState.arg,
30
30
  };
31
- });
31
+ }, { disableDevtools: true });
32
32
  constructor(_operation) {
33
33
  this._operation = _operation;
34
34
  }
@@ -1,6 +1,7 @@
1
+ import { SharedOptions } from "../../common/options/SharedOptions";
2
+ import { Indexer } from "../../signals/base/Indexer";
1
3
  import { IndirectMap } from "../../query/lib/IndirectMap";
2
4
  import { ReactiveCache } from "../../query/lib/ReactiveCache";
3
- import { SharedOptions } from "./SharedOptions";
4
5
  export class QueriesCache {
5
6
  _logname;
6
7
  _cache = new IndirectMap();
@@ -14,12 +15,17 @@ export class QueriesCache {
14
15
  const cache = new ReactiveCache({
15
16
  initialState,
16
17
  });
17
- const devtoolsState = SharedOptions.DEVTOOLS?.state;
18
- if (devtoolsState) {
19
- const randomId = Math.random().toString(36).substring(2, 16);
20
- const key = `rxt:${this._logname}:${JSON.stringify(args)}:${randomId}`;
18
+ const stateDevtools = SharedOptions.DEVTOOLS?.state;
19
+ if (stateDevtools) {
20
+ const key = `${this._logname}:${JSON.stringify(args)}:i=${Indexer.getIndex()}`;
21
+ let devtools = stateDevtools(key, initialState);
21
22
  cache.spy$.subscribe((state) => {
22
- devtoolsState(key, state);
23
+ if (state === initialState)
24
+ return;
25
+ devtools(state);
26
+ });
27
+ cache.onClean$.subscribe(() => {
28
+ devtools('$CLEANED');
23
29
  });
24
30
  }
25
31
  cache.onClean$.subscribe(() => {
@@ -1,10 +1,12 @@
1
1
  import { ReactiveCache } from "../../../query/lib/ReactiveCache";
2
- import type { ResourceCreateOptions, ResourceDefinition, ResourceInstance, ResourceRefInstanse } from "../../../query/types/Resource.types";
3
- import { QueriesCache } from "../QueriesCache";
2
+ import type { ResourceCreateOptions, ResourceDefinition, ResourceInstance, ResourceRefInstanse, ResourceTransaction } from "../../../query/types";
3
+ import { QueriesCache } from "../../../query/core/QueriesCache";
4
4
  import { ResourceAgent } from "./ResourceAgent";
5
5
  export type CoreResourceQueryState<D extends ResourceDefinition> = {
6
+ transactions: ResourceTransaction[] | null;
6
7
  abortController: AbortController | null;
7
8
  args: D['Args'] | null;
9
+ savedData: D['Data'] | null;
8
10
  data: D['Data'] | null;
9
11
  error: unknown | null;
10
12
  isError: boolean;
@@ -31,7 +33,17 @@ export declare class Resource<D extends ResourceDefinition> implements ResourceI
31
33
  decrementLock(args: D['Args'], options?: {
32
34
  cache?: CoreResourceQueryCache<D>;
33
35
  }): CoreResourceQueryCache<D> | null;
34
- updateData(args: D['Args'], updateFn: (data: D['Data']) => D['Data'], options?: {
36
+ /**
37
+ * @deprecated
38
+ */
39
+ updateData_legacy(args: D['Args'], updateFn: (data: D['Data']) => D['Data'], options?: {
40
+ cache?: CoreResourceQueryCache<D>;
41
+ }): CoreResourceQueryCache<D> | null;
42
+ update(args: D['Args'], updateFn: (data: D['Data'], savedData: D['Data'] | null, transactions: ResourceTransaction[] | null) => {
43
+ data: D['Data'];
44
+ transactions: ResourceTransaction[] | null;
45
+ savedData: D['Data'] | null;
46
+ }, options?: {
35
47
  cache?: CoreResourceQueryCache<D>;
36
48
  }): CoreResourceQueryCache<D> | null;
37
49
  initiate(args: D['Args'], options?: {
@@ -1,10 +1,12 @@
1
- import { QueriesCache } from "../QueriesCache";
2
- import { SharedOptions } from "../SharedOptions";
1
+ import { SharedOptions } from "../../../common/options/SharedOptions";
2
+ import { QueriesCache } from "../../../query/core/QueriesCache";
3
3
  import { ResourceAgent } from "./ResourceAgent";
4
4
  import { ResourceRef } from "./ResourceRef";
5
5
  class ResourceQueryState {
6
6
  static create() {
7
7
  return {
8
+ transactions: null,
9
+ savedData: null,
8
10
  abortController: null,
9
11
  args: null,
10
12
  data: null,
@@ -31,6 +33,8 @@ class ResourceQueryState {
31
33
  static success(state, data) {
32
34
  return {
33
35
  ...state,
36
+ savedData: null,
37
+ transactions: null,
34
38
  data,
35
39
  isLoading: false,
36
40
  isReloading: false,
@@ -67,16 +71,28 @@ class ResourceQueryState {
67
71
  lockCount
68
72
  };
69
73
  }
74
+ static update(state, data, savedData, transactions) {
75
+ return {
76
+ ...state,
77
+ transactions,
78
+ savedData,
79
+ data
80
+ };
81
+ }
82
+ /**
83
+ * @deprecated
84
+ */
70
85
  static setData(state, data) {
71
86
  return {
72
87
  ...state,
88
+ transactions: null,
73
89
  data
74
90
  };
75
91
  }
76
92
  }
77
93
  export class Resource {
78
94
  _options;
79
- _queriesCache = new QueriesCache('res');
95
+ _queriesCache = new QueriesCache('Resource');
80
96
  constructor(_options) {
81
97
  this._options = _options;
82
98
  }
@@ -108,7 +124,10 @@ export class Resource {
108
124
  cache.next(ResourceQueryState.decrementLock(cache.value));
109
125
  return cache;
110
126
  }
111
- updateData(args, updateFn, options) {
127
+ /**
128
+ * @deprecated
129
+ */
130
+ updateData_legacy(args, updateFn, options) {
112
131
  let cache = options?.cache ?? this.getQueryCache(args);
113
132
  if (!cache) {
114
133
  return null;
@@ -121,6 +140,19 @@ export class Resource {
121
140
  cache.next(ResourceQueryState.setData(cache.value, newData));
122
141
  return cache;
123
142
  }
143
+ update(args, updateFn, options) {
144
+ let cache = options?.cache ?? this.getQueryCache(args);
145
+ if (!cache) {
146
+ return null;
147
+ }
148
+ const cacheValue = cache.value;
149
+ if (!cacheValue.isDone) {
150
+ return cache;
151
+ }
152
+ const { data, transactions, savedData } = updateFn(cacheValue.data, cacheValue.savedData, cacheValue.transactions);
153
+ cache.next(ResourceQueryState.update(cache.value, data, savedData, transactions));
154
+ return cache;
155
+ }
124
156
  initiate(args, options) {
125
157
  let cache = options?.cache ?? this._queriesCache.getQueryCache(args);
126
158
  const state = ResourceQueryState.load(cache?.value, args);
@@ -1,5 +1,5 @@
1
- import { Computed } from "../../../signal";
2
- import { ResourceAgentInstance, ResourceDefinition } from "../../../query/types/Resource.types";
1
+ import { Computed } from "../../../signals";
2
+ import { ResourceAgentInstance, ResourceDefinition } from "../../../query/types";
3
3
  import type { Resource } from "./Resource";
4
4
  export declare class ResourceAgent<D extends ResourceDefinition> implements ResourceAgentInstance<D> {
5
5
  private _resource;
@@ -1,10 +1,10 @@
1
- import { Computed, Signal } from "../../../signal";
1
+ import { Computed, Signal } from "../../../signals";
2
2
  export class ResourceAgent {
3
3
  _resource;
4
4
  _resources$ = new Signal({
5
5
  previous$: null,
6
6
  current$: null,
7
- });
7
+ }, { disableDevtools: true });
8
8
  state$ = new Computed(() => {
9
9
  const resources = this._resources$.value;
10
10
  let prevState;
@@ -41,7 +41,7 @@ export class ResourceAgent {
41
41
  data: isShowPrev ? prevState.data ?? undefined : currState.data ?? undefined,
42
42
  args: currState.args ?? undefined,
43
43
  };
44
- });
44
+ }, { disableDevtools: true });
45
45
  constructor(_resource) {
46
46
  this._resource = _resource;
47
47
  }
@@ -1,5 +1,5 @@
1
+ import { ResourceDefinition, ResourceRefInstanse, ResourceTransaction } from "../../../query/types";
1
2
  import { Resource } from "./Resource";
2
- import { ResourceDefinition, ResourceRefInstanse } from "../../types/Resource.types";
3
3
  export declare class ResourceRef<D extends ResourceDefinition> implements ResourceRefInstanse<D> {
4
4
  private readonly _resource;
5
5
  private readonly _args;
@@ -13,6 +13,7 @@ export declare class ResourceRef<D extends ResourceDefinition> implements Resour
13
13
  update(updateFn: (data: D["Data"]) => D["Data"]): {
14
14
  rollback: () => void;
15
15
  };
16
+ patch(patchFn: (data: D["Data"]) => void): ResourceTransaction | null;
16
17
  create(data: D["Data"]): void;
17
18
  invalidate(): void;
18
19
  }