@ersbeth/picoflow 2.0.2 → 2.1.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.
Files changed (244) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/SKILL.md +106 -0
  4. package/dist/picoflow.js +204 -60
  5. package/dist/types/api/base/flowObservable.d.ts +3 -3
  6. package/dist/types/api/base/flowObservable.d.ts.map +1 -1
  7. package/dist/types/api/base/flowSubscribable.d.ts +2 -2
  8. package/dist/types/api/base/flowSubscribable.d.ts.map +1 -1
  9. package/dist/types/api/base/flowTracker.d.ts +1 -1
  10. package/dist/types/api/base/flowTracker.d.ts.map +1 -1
  11. package/dist/types/api/base/index.d.ts +4 -4
  12. package/dist/types/api/base/index.d.ts.map +1 -1
  13. package/dist/types/api/index.d.ts +2 -2
  14. package/dist/types/api/index.d.ts.map +1 -1
  15. package/dist/types/api/nodes/async/flowConstantAsync.d.ts +1 -1
  16. package/dist/types/api/nodes/async/flowConstantAsync.d.ts.map +1 -1
  17. package/dist/types/api/nodes/async/flowDerivationAsync.d.ts +3 -3
  18. package/dist/types/api/nodes/async/flowDerivationAsync.d.ts.map +1 -1
  19. package/dist/types/api/nodes/async/flowStateAsync.d.ts +3 -3
  20. package/dist/types/api/nodes/async/flowStateAsync.d.ts.map +1 -1
  21. package/dist/types/api/nodes/async/flowWritableDerivationAsync.d.ts +2 -2
  22. package/dist/types/api/nodes/async/flowWritableDerivationAsync.d.ts.map +1 -1
  23. package/dist/types/api/nodes/async/index.d.ts +4 -4
  24. package/dist/types/api/nodes/async/index.d.ts.map +1 -1
  25. package/dist/types/api/nodes/collections/flowArray.d.ts +7 -4
  26. package/dist/types/api/nodes/collections/flowArray.d.ts.map +1 -1
  27. package/dist/types/api/nodes/collections/flowMap.d.ts +3 -2
  28. package/dist/types/api/nodes/collections/flowMap.d.ts.map +1 -1
  29. package/dist/types/api/nodes/collections/index.d.ts +2 -2
  30. package/dist/types/api/nodes/collections/index.d.ts.map +1 -1
  31. package/dist/types/api/nodes/flowEffect.d.ts +2 -2
  32. package/dist/types/api/nodes/flowEffect.d.ts.map +1 -1
  33. package/dist/types/api/nodes/flowSignal.d.ts +1 -1
  34. package/dist/types/api/nodes/flowSignal.d.ts.map +1 -1
  35. package/dist/types/api/nodes/flowValue.d.ts +2 -2
  36. package/dist/types/api/nodes/flowValue.d.ts.map +1 -1
  37. package/dist/types/api/nodes/index.d.ts +7 -7
  38. package/dist/types/api/nodes/index.d.ts.map +1 -1
  39. package/dist/types/api/nodes/sync/flowConstant.d.ts +2 -2
  40. package/dist/types/api/nodes/sync/flowConstant.d.ts.map +1 -1
  41. package/dist/types/api/nodes/sync/flowDerivation.d.ts +3 -3
  42. package/dist/types/api/nodes/sync/flowDerivation.d.ts.map +1 -1
  43. package/dist/types/api/nodes/sync/flowState.d.ts +3 -3
  44. package/dist/types/api/nodes/sync/flowState.d.ts.map +1 -1
  45. package/dist/types/api/nodes/sync/flowWritableDerivation.d.ts +2 -2
  46. package/dist/types/api/nodes/sync/flowWritableDerivation.d.ts.map +1 -1
  47. package/dist/types/api/nodes/sync/index.d.ts +4 -4
  48. package/dist/types/api/nodes/sync/index.d.ts.map +1 -1
  49. package/dist/types/api/nodes/utils.d.ts +1 -1
  50. package/dist/types/api/nodes/utils.d.ts.map +1 -1
  51. package/dist/types/base/disposable.d.ts +1 -1
  52. package/dist/types/base/disposable.d.ts.map +1 -1
  53. package/dist/types/base/executionStack.d.ts +22 -1
  54. package/dist/types/base/executionStack.d.ts.map +1 -1
  55. package/dist/types/base/index.d.ts +5 -5
  56. package/dist/types/base/index.d.ts.map +1 -1
  57. package/dist/types/base/node.d.ts +4 -4
  58. package/dist/types/base/node.d.ts.map +1 -1
  59. package/dist/types/base/observable.d.ts +3 -3
  60. package/dist/types/base/observable.d.ts.map +1 -1
  61. package/dist/types/base/observer.d.ts +2 -2
  62. package/dist/types/base/observer.d.ts.map +1 -1
  63. package/dist/types/converters/index.d.ts +1 -1
  64. package/dist/types/converters/index.d.ts.map +1 -1
  65. package/dist/types/converters/solid.d.ts +12 -8
  66. package/dist/types/converters/solid.d.ts.map +1 -1
  67. package/dist/types/index.d.ts +2 -2
  68. package/dist/types/index.d.ts.map +1 -1
  69. package/dist/types/nodes/actionNode.d.ts +23 -0
  70. package/dist/types/nodes/actionNode.d.ts.map +1 -0
  71. package/dist/types/nodes/arrayNode.d.ts +4 -3
  72. package/dist/types/nodes/arrayNode.d.ts.map +1 -1
  73. package/dist/types/nodes/effectNode.d.ts +18 -2
  74. package/dist/types/nodes/effectNode.d.ts.map +1 -1
  75. package/dist/types/nodes/index.d.ts +8 -7
  76. package/dist/types/nodes/index.d.ts.map +1 -1
  77. package/dist/types/nodes/mapNode.d.ts +4 -3
  78. package/dist/types/nodes/mapNode.d.ts.map +1 -1
  79. package/dist/types/nodes/signalNode.d.ts +2 -2
  80. package/dist/types/nodes/signalNode.d.ts.map +1 -1
  81. package/dist/types/nodes/valueAsyncNode.d.ts +3 -3
  82. package/dist/types/nodes/valueAsyncNode.d.ts.map +1 -1
  83. package/dist/types/nodes/valueNode.d.ts +3 -3
  84. package/dist/types/nodes/valueNode.d.ts.map +1 -1
  85. package/dist/types/nodes/valueSyncNode.d.ts +3 -3
  86. package/dist/types/nodes/valueSyncNode.d.ts.map +1 -1
  87. package/dist/types/schedulers/asyncScheduler.d.ts +2 -1
  88. package/dist/types/schedulers/asyncScheduler.d.ts.map +1 -1
  89. package/dist/types/schedulers/index.d.ts +4 -4
  90. package/dist/types/schedulers/index.d.ts.map +1 -1
  91. package/dist/types/schedulers/syncResolver.d.ts +1 -2
  92. package/dist/types/schedulers/syncResolver.d.ts.map +1 -1
  93. package/dist/types/schedulers/syncScheduler.d.ts +1 -1
  94. package/dist/types/schedulers/syncScheduler.d.ts.map +1 -1
  95. package/package.json +24 -1
  96. package/.gitlab-ci.yml +0 -24
  97. package/.vscode/settings.json +0 -5
  98. package/CHANGELOG.md +0 -94
  99. package/biome.json +0 -47
  100. package/docs/.vitepress/config.mts +0 -145
  101. package/docs/api/functions/array.md +0 -35
  102. package/docs/api/functions/constant.md +0 -33
  103. package/docs/api/functions/constantAsync.md +0 -69
  104. package/docs/api/functions/derivation.md +0 -34
  105. package/docs/api/functions/derivationAsync.md +0 -34
  106. package/docs/api/functions/from.md +0 -129
  107. package/docs/api/functions/isDisposable.md +0 -27
  108. package/docs/api/functions/map.md +0 -36
  109. package/docs/api/functions/signal.md +0 -21
  110. package/docs/api/functions/state.md +0 -67
  111. package/docs/api/functions/stateAsync.md +0 -69
  112. package/docs/api/functions/subscribe.md +0 -40
  113. package/docs/api/functions/writableDerivation.md +0 -33
  114. package/docs/api/functions/writableDerivationAsync.md +0 -34
  115. package/docs/api/index.md +0 -61
  116. package/docs/api/interfaces/FlowArray.md +0 -439
  117. package/docs/api/interfaces/FlowConstant.md +0 -220
  118. package/docs/api/interfaces/FlowConstantAsync.md +0 -221
  119. package/docs/api/interfaces/FlowDerivation.md +0 -241
  120. package/docs/api/interfaces/FlowDerivationAsync.md +0 -242
  121. package/docs/api/interfaces/FlowDisposable.md +0 -59
  122. package/docs/api/interfaces/FlowEffect.md +0 -64
  123. package/docs/api/interfaces/FlowMap.md +0 -374
  124. package/docs/api/interfaces/FlowObservable.md +0 -155
  125. package/docs/api/interfaces/FlowSignal.md +0 -156
  126. package/docs/api/interfaces/FlowState.md +0 -269
  127. package/docs/api/interfaces/FlowStateAsync.md +0 -268
  128. package/docs/api/interfaces/FlowSubscribable.md +0 -55
  129. package/docs/api/interfaces/FlowTracker.md +0 -61
  130. package/docs/api/interfaces/FlowValue.md +0 -222
  131. package/docs/api/interfaces/FlowWritableDerivation.md +0 -292
  132. package/docs/api/interfaces/FlowWritableDerivationAsync.md +0 -293
  133. package/docs/api/type-aliases/DerivationFunction.md +0 -28
  134. package/docs/api/type-aliases/DerivationFunctionAsync.md +0 -28
  135. package/docs/api/type-aliases/FlowArrayAction.md +0 -60
  136. package/docs/api/type-aliases/FlowDataTracker.md +0 -33
  137. package/docs/api/type-aliases/FlowMapAction.md +0 -48
  138. package/docs/api/type-aliases/FlowOnDataListener.md +0 -33
  139. package/docs/api/type-aliases/FlowOnErrorListener.md +0 -27
  140. package/docs/api/type-aliases/FlowOnPendingListener.md +0 -21
  141. package/docs/api/type-aliases/FlowReadonly.md +0 -22
  142. package/docs/api/type-aliases/InitFunction.md +0 -21
  143. package/docs/api/type-aliases/InitFunctionAsync.md +0 -21
  144. package/docs/api/type-aliases/NotPromise.md +0 -21
  145. package/docs/api/type-aliases/UpdateFunction.md +0 -27
  146. package/docs/api/type-aliases/UpdateFunctionAsync.md +0 -27
  147. package/docs/api/typedoc-sidebar.json +0 -65
  148. package/docs/examples/examples.md +0 -2311
  149. package/docs/examples/patterns.md +0 -649
  150. package/docs/guide/advanced/architecture.md +0 -1234
  151. package/docs/guide/advanced/disposal.md +0 -426
  152. package/docs/guide/advanced/migration-v1.md +0 -464
  153. package/docs/guide/advanced/migration-v2.md +0 -204
  154. package/docs/guide/advanced/solidjs.md +0 -135
  155. package/docs/guide/introduction/concepts.md +0 -57
  156. package/docs/guide/introduction/conventions.md +0 -30
  157. package/docs/guide/introduction/getting-started.md +0 -139
  158. package/docs/guide/introduction/lifecycle.md +0 -368
  159. package/docs/guide/primitives/array.md +0 -286
  160. package/docs/guide/primitives/constant.md +0 -207
  161. package/docs/guide/primitives/derivations.md +0 -281
  162. package/docs/guide/primitives/effects.md +0 -372
  163. package/docs/guide/primitives/map.md +0 -265
  164. package/docs/guide/primitives/overview.md +0 -92
  165. package/docs/guide/primitives/signal.md +0 -222
  166. package/docs/guide/primitives/state.md +0 -272
  167. package/docs/index.md +0 -47
  168. package/docs/public/logo.svg +0 -1
  169. package/src/api/base/flowDisposable.ts +0 -44
  170. package/src/api/base/flowObservable.ts +0 -28
  171. package/src/api/base/flowSubscribable.ts +0 -87
  172. package/src/api/base/flowTracker.ts +0 -7
  173. package/src/api/base/index.ts +0 -4
  174. package/src/api/index.ts +0 -2
  175. package/src/api/nodes/async/flowConstantAsync.ts +0 -36
  176. package/src/api/nodes/async/flowDerivationAsync.ts +0 -42
  177. package/src/api/nodes/async/flowStateAsync.ts +0 -47
  178. package/src/api/nodes/async/flowWritableDerivationAsync.ts +0 -33
  179. package/src/api/nodes/async/index.ts +0 -4
  180. package/src/api/nodes/collections/flowArray.ts +0 -155
  181. package/src/api/nodes/collections/flowMap.ts +0 -115
  182. package/src/api/nodes/collections/index.ts +0 -2
  183. package/src/api/nodes/flowEffect.ts +0 -42
  184. package/src/api/nodes/flowSignal.ts +0 -28
  185. package/src/api/nodes/flowValue.ts +0 -37
  186. package/src/api/nodes/index.ts +0 -7
  187. package/src/api/nodes/sync/flowConstant.ts +0 -33
  188. package/src/api/nodes/sync/flowDerivation.ts +0 -41
  189. package/src/api/nodes/sync/flowState.ts +0 -45
  190. package/src/api/nodes/sync/flowWritableDerivation.ts +0 -31
  191. package/src/api/nodes/sync/index.ts +0 -4
  192. package/src/api/nodes/utils.ts +0 -24
  193. package/src/base/disposable.ts +0 -18
  194. package/src/base/executionStack.ts +0 -42
  195. package/src/base/index.ts +0 -5
  196. package/src/base/node.ts +0 -98
  197. package/src/base/observable.ts +0 -92
  198. package/src/base/observer.ts +0 -51
  199. package/src/converters/index.ts +0 -1
  200. package/src/converters/solid.ts +0 -109
  201. package/src/index.ts +0 -2
  202. package/src/nodes/arrayNode.ts +0 -180
  203. package/src/nodes/effectNode.ts +0 -58
  204. package/src/nodes/index.ts +0 -7
  205. package/src/nodes/mapNode.ts +0 -125
  206. package/src/nodes/signalNode.ts +0 -19
  207. package/src/nodes/valueAsyncNode.ts +0 -85
  208. package/src/nodes/valueNode.ts +0 -148
  209. package/src/nodes/valueSyncNode.ts +0 -125
  210. package/src/schedulers/asyncResolver.ts +0 -78
  211. package/src/schedulers/asyncScheduler.ts +0 -66
  212. package/src/schedulers/index.ts +0 -4
  213. package/src/schedulers/pendingError.ts +0 -13
  214. package/src/schedulers/scheduler.ts +0 -9
  215. package/src/schedulers/syncResolver.ts +0 -69
  216. package/src/schedulers/syncScheduler.ts +0 -55
  217. package/test/base/pendingError.test.ts +0 -67
  218. package/test/converters/solid.derivation.browser.test.tsx +0 -69
  219. package/test/converters/solid.node.test.ts +0 -654
  220. package/test/converters/solid.state.browser.test.tsx +0 -1592
  221. package/test/reactivity/flowSignal.test.ts +0 -226
  222. package/test/reactivity/nodes/async/asyncScheduler/asyncResolver.test.ts +0 -593
  223. package/test/reactivity/nodes/async/asyncScheduler/asyncScheduler.test.ts +0 -317
  224. package/test/reactivity/nodes/async/flowConstantAsync.test.ts +0 -652
  225. package/test/reactivity/nodes/async/flowDerivation.test.ts +0 -898
  226. package/test/reactivity/nodes/async/flowDerivationAsync.test.ts +0 -1716
  227. package/test/reactivity/nodes/async/flowStateAsync.test.ts +0 -708
  228. package/test/reactivity/nodes/async/flowWritableDerivationAsync.test.ts +0 -614
  229. package/test/reactivity/nodes/collections/flowArray.asyncStates.test.ts +0 -1289
  230. package/test/reactivity/nodes/collections/flowArray.scalars.test.ts +0 -961
  231. package/test/reactivity/nodes/collections/flowArray.states.test.ts +0 -1035
  232. package/test/reactivity/nodes/collections/flowMap.asyncStates.test.ts +0 -960
  233. package/test/reactivity/nodes/collections/flowMap.scalars.test.ts +0 -775
  234. package/test/reactivity/nodes/collections/flowMap.states.test.ts +0 -958
  235. package/test/reactivity/nodes/sync/flowConstant.test.ts +0 -377
  236. package/test/reactivity/nodes/sync/flowDerivation.test.ts +0 -896
  237. package/test/reactivity/nodes/sync/flowState.test.ts +0 -341
  238. package/test/reactivity/nodes/sync/flowWritableDerivation.test.ts +0 -603
  239. package/test/vitest.d.ts +0 -10
  240. package/tsconfig.json +0 -37
  241. package/typedoc.json +0 -37
  242. package/vite.config.ts +0 -31
  243. package/vitest.browser.config.ts +0 -21
  244. package/vitest.config.ts +0 -17
@@ -1,958 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import { type FlowState, map, state, subscribe } from "~";
3
-
4
- describe("FlowMap", () => {
5
- describe("unit", () => {
6
- describe("initialization", () => {
7
- it("should initialize with provided Record of FlowState values", async () => {
8
- const $map = map({
9
- key1: state(1),
10
- key2: state(2),
11
- key3: state(3),
12
- });
13
-
14
- const values = await Promise.all(
15
- Array.from((await $map.pick()).entries()).map(([_, value]) => value.pick()),
16
- );
17
-
18
- expect(values).toEqual([1, 2, 3]);
19
- });
20
-
21
- it("should initialize with provided Map of FlowState values", async () => {
22
- const $value1 = state(1);
23
- const $value2 = state(2);
24
- const initialMap = new Map([
25
- ["key1", $value1],
26
- ["key2", $value2],
27
- ]);
28
- const $map = map(initialMap);
29
-
30
- expect(Array.from((await $map.pick()).entries())).toEqual([
31
- ["key1", $value1],
32
- ["key2", $value2],
33
- ]);
34
- });
35
-
36
- it("should initialize with empty map when no value provided", async () => {
37
- const $map = map<string, FlowState<number>>();
38
-
39
- expect(Array.from((await $map.pick()).entries())).toEqual([]);
40
- expect((await $map.pick()).size).toBe(0);
41
- });
42
-
43
- it("should initialize $lastAction with set action on creation", async () => {
44
- const $value1 = state(1);
45
- const $value2 = state(2);
46
- const $map = map({
47
- key1: $value1,
48
- key2: $value2,
49
- });
50
- const action = await $map.$lastAction.pick();
51
- expect(action.type).toBe("set");
52
- if (action.type === "set") {
53
- expect(action.setMap.size).toBe(2);
54
- expect(action.setMap.get("key1")).toBe($value1);
55
- expect(action.setMap.get("key2")).toBe($value2);
56
- }
57
- });
58
-
59
- it("should initialize $lastAction with empty map when no value provided", async () => {
60
- const $map = map<string, FlowState<number>>();
61
- const action = await $map.$lastAction.pick();
62
- expect(action.type).toBe("set");
63
- if (action.type === "set") {
64
- expect(action.setMap.size).toBe(0);
65
- }
66
- });
67
- });
68
-
69
- describe("disposal", () => {
70
- it("should have disposed property set to false initially and true after disposal", () => {
71
- const $map = map({
72
- key1: state(1),
73
- key2: state(2),
74
- });
75
- expect($map.disposed).toBe(false);
76
- $map.dispose();
77
- expect($map.disposed).toBe(true);
78
- });
79
-
80
- it("should throw error when disposed twice", () => {
81
- const $map = map({
82
- key1: state(1),
83
- key2: state(2),
84
- });
85
- $map.dispose();
86
- expect(() => $map.dispose()).toThrow("[PicoFlow] Primitive is disposed");
87
- });
88
-
89
- it("should throw when pick is called after disposal", async () => {
90
- const $map = map<string, FlowState<number>>({
91
- key1: state(1),
92
- key2: state(2),
93
- key3: state(3),
94
- });
95
- $map.dispose();
96
- await expect($map.pick()).rejects.toThrow("[PicoFlow] Primitive is disposed");
97
- });
98
-
99
- it("should throw when set is called after disposal", () => {
100
- const $map = map<string, FlowState<number>>({
101
- key1: state(1),
102
- });
103
- $map.dispose();
104
- expect(() => $map.set(new Map([["key2", state(2)]]))).toThrow("[PicoFlow] Primitive is disposed");
105
- });
106
-
107
- it("should throw when add is called after disposal", () => {
108
- const $map = map<string, FlowState<number>>();
109
- $map.dispose();
110
- expect(() => $map.add("key1", state(2))).toThrow("[PicoFlow] Primitive is disposed");
111
- });
112
-
113
- it("should throw when update is called after disposal", () => {
114
- const $map = map<string, FlowState<number>>();
115
- $map.add("key1", state(1));
116
- $map.dispose();
117
- expect(() => $map.update("key1", state(2))).toThrow("[PicoFlow] Primitive is disposed");
118
- });
119
-
120
- it("should throw when delete is called after disposal", () => {
121
- const $map = map<string, FlowState<number>>({
122
- key1: state(1),
123
- key2: state(2),
124
- key3: state(3),
125
- });
126
- $map.dispose();
127
- expect(() => $map.delete("key1")).toThrow("[PicoFlow] Primitive is disposed");
128
- });
129
-
130
- it("should throw when clear is called after disposal", () => {
131
- const $map = map<string, FlowState<number>>({
132
- key1: state(1),
133
- key2: state(2),
134
- });
135
- $map.dispose();
136
- expect(() => $map.clear()).toThrow("[PicoFlow] Primitive is disposed");
137
- });
138
-
139
- it("should dispose values when FlowMap is disposed", () => {
140
- const $map = map<string, FlowState<number>>();
141
- const $value1 = state(1);
142
- const $value2 = state(2);
143
- const $value3 = state(3);
144
-
145
- $map.add("key1", $value1);
146
- $map.add("key2", $value2);
147
- $map.add("key3", $value3);
148
-
149
- expect($value1.disposed).toBe(false);
150
- expect($value2.disposed).toBe(false);
151
- expect($value3.disposed).toBe(false);
152
-
153
- $map.dispose();
154
-
155
- expect($value1.disposed).toBe(true);
156
- expect($value2.disposed).toBe(true);
157
- expect($value3.disposed).toBe(true);
158
- });
159
-
160
- it("should dispose values with provided options when FlowMap is disposed", () => {
161
- const $map = map<string, FlowState<number>>();
162
- const $value1 = state(1);
163
- const $value2 = state(2);
164
-
165
- $map.add("key1", $value1);
166
- $map.add("key2", $value2);
167
-
168
- const onData = vi.fn();
169
- const $effect = subscribe((t) => $value1.get(t), onData);
170
-
171
- expect($effect.disposed).toBe(false);
172
-
173
- $map.dispose();
174
-
175
- expect($value1.disposed).toBe(true);
176
- expect($value2.disposed).toBe(true);
177
- expect($effect.disposed).toBe(false);
178
-
179
- $effect.dispose();
180
- });
181
-
182
- it("should handle non-disposable values gracefully", async () => {
183
- const $map = map<string, FlowState<number>>();
184
- $map.add("key1", state(1));
185
- $map.add("key2", state(2));
186
- $map.add("key3", state(3));
187
-
188
- expect((await $map.pick()).size).toBe(3);
189
-
190
- expect(() => $map.dispose()).not.toThrow();
191
- });
192
- });
193
-
194
- describe("set", () => {
195
- it("should replace entire map when set is called", async () => {
196
- const $map = map<string, FlowState<number>>({
197
- key1: state(1),
198
- key2: state(2),
199
- });
200
- const $newValue1 = state(3);
201
- const $newValue2 = state(4);
202
- const newMap = new Map([
203
- ["key3", $newValue1],
204
- ["key4", $newValue2],
205
- ]);
206
-
207
- $map.set(newMap);
208
- expect(Array.from((await $map.pick()).entries())).toEqual([
209
- ["key3", $newValue1],
210
- ["key4", $newValue2],
211
- ]);
212
- });
213
-
214
- it("should update $lastAction with set action when set is called", async () => {
215
- const $map = map<string, FlowState<number>>({
216
- key1: state(1),
217
- key2: state(2),
218
- });
219
- const $newValue1 = state(3);
220
- const $newValue2 = state(4);
221
- const newMap = new Map([
222
- ["key3", $newValue1],
223
- ["key4", $newValue2],
224
- ]);
225
-
226
- $map.set(newMap);
227
- const action = await $map.$lastAction.pick();
228
- expect(action.type).toBe("set");
229
- if (action.type === "set") {
230
- expect(action.setMap).toBe(newMap);
231
- expect(action.clearedMap).toBeInstanceOf(Map);
232
- }
233
- });
234
- });
235
-
236
- describe("add", () => {
237
- it("should add key-value pair to map", async () => {
238
- const $map = map<string, FlowState<number>>();
239
-
240
- $map.add("key1", state(1));
241
- expect(await (await $map.pick()).get("key1")?.pick()).toBe(1);
242
- expect((await $map.pick()).size).toBe(1);
243
- });
244
-
245
- it("should add multiple keys successively", async () => {
246
- const $map = map<string, FlowState<number>>();
247
-
248
- $map.add("key1", state(1));
249
- $map.add("key2", state(2));
250
- $map.add("key3", state(3));
251
-
252
- expect((await $map.pick()).size).toBe(3);
253
- expect(await (await $map.pick()).get("key1")?.pick()).toBe(1);
254
- expect(await (await $map.pick()).get("key2")?.pick()).toBe(2);
255
- expect(await (await $map.pick()).get("key3")?.pick()).toBe(3);
256
- });
257
-
258
- it("should throw when key already exists", () => {
259
- const $map = map<string, FlowState<number>>();
260
- $map.add("key1", state(1));
261
- expect(() => $map.add("key1", state(2))).toThrow("[PicoFlow] Key already exists");
262
- });
263
-
264
- it("should update $lastAction with add action when add is called", async () => {
265
- const $map = map<string, FlowState<number>>();
266
- const $value = state(1);
267
- $map.add("key1", $value);
268
- const action = await $map.$lastAction.pick();
269
- expect(action).toEqual({
270
- type: "add",
271
- key: "key1",
272
- addedValue: $value,
273
- });
274
- });
275
-
276
- it("should have FlowState value in $lastAction when add is called", async () => {
277
- const $map = map<string, FlowState<number>>();
278
- const $value = state(100);
279
- $map.add("key1", $value);
280
- const action = await $map.$lastAction.pick();
281
- expect(action.type).toBe("add");
282
- if (action.type === "add") {
283
- expect(action.addedValue).toBe($value);
284
- expect(await action.addedValue.pick()).toBe(100);
285
- }
286
- });
287
-
288
- it("should trigger reactivity when add is called", async () => {
289
- const $map = map<string, FlowState<number>>();
290
- const onData = vi.fn();
291
- subscribe((t) => $map.get(t), onData);
292
-
293
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
294
-
295
- $map.add("key1", state(1));
296
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
297
- });
298
- });
299
-
300
- describe("update", () => {
301
- it("should update existing key-value pair", async () => {
302
- const $map = map<string, FlowState<number>>();
303
- $map.add("key1", state(1));
304
-
305
- const $newValue = state(2);
306
- $map.update("key1", $newValue);
307
- expect(await (await $map.pick()).get("key1")?.pick()).toBe(2);
308
- });
309
-
310
- it("should update multiple keys successively", async () => {
311
- const $map = map<string, FlowState<number>>();
312
- $map.add("key1", state(1));
313
- $map.add("key2", state(2));
314
-
315
- $map.update("key1", state(10));
316
- $map.update("key2", state(20));
317
-
318
- expect(await (await $map.pick()).get("key1")?.pick()).toBe(10);
319
- expect(await (await $map.pick()).get("key2")?.pick()).toBe(20);
320
- });
321
-
322
- it("should throw when key does not exist", () => {
323
- const $map = map<string, FlowState<number>>();
324
- expect(() => $map.update("key1", state(1))).toThrow("[PicoFlow] Key does not exist");
325
- });
326
-
327
- it("should update $lastAction with update action when update is called", async () => {
328
- const $map = map<string, FlowState<number>>();
329
- $map.add("key1", state(1));
330
- const $newValue = state(2);
331
- $map.update("key1", $newValue);
332
- const action = await $map.$lastAction.pick();
333
- expect(action).toEqual({
334
- type: "update",
335
- key: "key1",
336
- setValue: $newValue,
337
- clearedValue: expect.any(Object),
338
- });
339
- });
340
-
341
- it("should have FlowState value in $lastAction when update is called", async () => {
342
- const $map = map<string, FlowState<number>>();
343
- $map.add("key1", state(1));
344
- const $newValue = state(200);
345
- $map.update("key1", $newValue);
346
- const action = await $map.$lastAction.pick();
347
- expect(action.type).toBe("update");
348
- if (action.type === "update") {
349
- expect(action.setValue).toBe($newValue);
350
- expect(await action.setValue.pick()).toBe(200);
351
- }
352
- });
353
-
354
- it("should trigger reactivity when update is called", async () => {
355
- const $map = map<string, FlowState<number>>();
356
- $map.add("key1", state(1));
357
- const onData = vi.fn();
358
- subscribe((t) => $map.get(t), onData);
359
-
360
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
361
-
362
- $map.update("key1", state(2));
363
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
364
- });
365
- });
366
-
367
- describe("delete", () => {
368
- it("should delete key from map", async () => {
369
- const $map = map<string, FlowState<number>>();
370
- $map.add("key1", state(1));
371
- $map.add("key2", state(2));
372
-
373
- $map.delete("key1");
374
- expect(await (await $map.pick()).get("key1")?.pick()).toBe(undefined);
375
- expect(await (await $map.pick()).get("key2")?.pick()).toBe(2);
376
- expect((await $map.pick()).size).toBe(1);
377
- });
378
-
379
- it("should delete multiple keys successively", async () => {
380
- const $map = map<string, FlowState<number>>();
381
- $map.add("key1", state(1));
382
- $map.add("key2", state(2));
383
- $map.add("key3", state(3));
384
-
385
- $map.delete("key1");
386
- $map.delete("key2");
387
-
388
- expect((await $map.pick()).size).toBe(1);
389
- expect(await (await $map.pick()).get("key3")?.pick()).toBe(3);
390
- });
391
-
392
- it("should throw when key does not exist", () => {
393
- const $map = map<string, FlowState<number>>();
394
- expect(() => $map.delete("key1")).toThrow("[PicoFlow] Key does not exist");
395
- });
396
-
397
- it("should update $lastAction with delete action when delete is called", async () => {
398
- const $map = map<string, FlowState<number>>();
399
- const $value = state(1);
400
- $map.add("key1", $value);
401
- $map.delete("key1");
402
- const action = await $map.$lastAction.pick();
403
- expect(action.type).toBe("delete");
404
- if (action.type === "delete") {
405
- expect(action.key).toBe("key1");
406
- expect(action.removedValue).toBe($value);
407
- }
408
- });
409
-
410
- it("should trigger reactivity when delete is called", async () => {
411
- const $map = map<string, FlowState<number>>();
412
- $map.add("key1", state(1));
413
- const onData = vi.fn();
414
- subscribe((t) => $map.get(t), onData);
415
-
416
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
417
-
418
- $map.delete("key1");
419
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
420
- });
421
- });
422
-
423
- describe("clear", () => {
424
- it("should remove all entries from map", async () => {
425
- const $map = map<string, FlowState<number>>({
426
- key1: state(1),
427
- key2: state(2),
428
- key3: state(3),
429
- });
430
- expect((await $map.pick()).size).toBe(3);
431
-
432
- $map.clear();
433
- expect((await $map.pick()).size).toBe(0);
434
- });
435
-
436
- it("should update $lastAction with clear action when clear is called", async () => {
437
- const $map = map<string, FlowState<number>>({
438
- key1: state(1),
439
- key2: state(2),
440
- });
441
- $map.clear();
442
- const action = await $map.$lastAction.pick();
443
- expect(action.type).toBe("clear");
444
- if (action.type === "clear") {
445
- expect(action.clearedMap).toBeInstanceOf(Map);
446
- expect(action.clearedMap.size).toBe(2);
447
- }
448
- });
449
- });
450
-
451
- describe("$lastAction", () => {
452
- describe("set action", () => {
453
- it("should initialize $lastAction with set action on creation", async () => {
454
- const $value1 = state(1);
455
- const $value2 = state(2);
456
- const $map = map({
457
- key1: $value1,
458
- key2: $value2,
459
- });
460
- const action = await $map.$lastAction.pick();
461
- expect(action).toEqual({
462
- type: "set",
463
- setMap: expect.any(Map),
464
- clearedMap: expect.any(Map),
465
- });
466
- if (action.type === "set") {
467
- expect(action.setMap.get("key1")).toBe($value1);
468
- expect(action.setMap.get("key2")).toBe($value2);
469
- }
470
- });
471
-
472
- it("should update $lastAction with set action when set is called", async () => {
473
- const $map = map<string, FlowState<number>>({
474
- key1: state(1),
475
- });
476
- const $newValue = state(2);
477
- const newMap = new Map([["key2", $newValue]]);
478
- $map.set(newMap);
479
- const action = await $map.$lastAction.pick();
480
- expect(action).toEqual({
481
- type: "set",
482
- setMap: newMap,
483
- clearedMap: expect.any(Map),
484
- });
485
- });
486
-
487
- it("should have correct structure for set action (type + setMap + clearedMap with FlowState)", async () => {
488
- const $value = state(1);
489
- const $map = map({ key1: $value });
490
- const action = await $map.$lastAction.pick();
491
- expect(action).toHaveProperty("type", "set");
492
- if (action.type === "set") {
493
- expect(action).toHaveProperty("setMap");
494
- expect(action).toHaveProperty("clearedMap");
495
- expect(action.setMap).toBeInstanceOf(Map);
496
- expect(action.clearedMap).toBeInstanceOf(Map);
497
- expect(action.setMap.get("key1")).toBe($value);
498
- }
499
- });
500
- });
501
-
502
- describe("add action", () => {
503
- it("should update $lastAction with add action when add is called", async () => {
504
- const $map = map<string, FlowState<number>>();
505
- const $value = state(1);
506
- $map.add("key1", $value);
507
- const action = await $map.$lastAction.pick();
508
- expect(action).toEqual({
509
- type: "add",
510
- key: "key1",
511
- addedValue: $value,
512
- });
513
- });
514
-
515
- it("should have correct structure for add action (type + key + FlowState addedValue)", async () => {
516
- const $map = map<string, FlowState<number>>();
517
- const $value = state(100);
518
- $map.add("key1", $value);
519
- const action = await $map.$lastAction.pick();
520
- expect(action).toHaveProperty("type", "add");
521
- if (action.type === "add") {
522
- expect(action).toHaveProperty("key");
523
- expect(action).toHaveProperty("addedValue");
524
- expect(action.key).toBe("key1");
525
- expect(action.addedValue).toBe($value);
526
- expect(await action.addedValue.pick()).toBe(100);
527
- }
528
- });
529
- });
530
-
531
- describe("update action", () => {
532
- it("should update $lastAction with update action when update is called", async () => {
533
- const $map = map<string, FlowState<number>>();
534
- $map.add("key1", state(1));
535
- const $newValue = state(2);
536
- $map.update("key1", $newValue);
537
- const action = await $map.$lastAction.pick();
538
- expect(action).toEqual({
539
- type: "update",
540
- key: "key1",
541
- setValue: $newValue,
542
- clearedValue: expect.any(Object),
543
- });
544
- });
545
-
546
- it("should have correct structure for update action (type + key + FlowState setValue + clearedValue)", async () => {
547
- const $map = map<string, FlowState<number>>();
548
- $map.add("key1", state(1));
549
- const $newValue = state(200);
550
- $map.update("key1", $newValue);
551
- const action = await $map.$lastAction.pick();
552
- expect(action).toHaveProperty("type", "update");
553
- if (action.type === "update") {
554
- expect(action).toHaveProperty("key");
555
- expect(action).toHaveProperty("setValue");
556
- expect(action).toHaveProperty("clearedValue");
557
- expect(action.key).toBe("key1");
558
- expect(action.setValue).toBe($newValue);
559
- expect(await action.setValue.pick()).toBe(200);
560
- }
561
- });
562
- });
563
-
564
- describe("delete action", () => {
565
- it("should update $lastAction with delete action when delete is called", async () => {
566
- const $map = map<string, FlowState<number>>();
567
- const $value = state(1);
568
- $map.add("key1", $value);
569
- $map.delete("key1");
570
- const action = await $map.$lastAction.pick();
571
- expect(action).toEqual({
572
- type: "delete",
573
- key: "key1",
574
- removedValue: $value,
575
- });
576
- });
577
-
578
- it("should have correct structure for delete action (type + key + FlowState removedValue)", async () => {
579
- const $map = map<string, FlowState<number>>();
580
- const $value = state(300);
581
- $map.add("key1", $value);
582
- $map.delete("key1");
583
- const action = await $map.$lastAction.pick();
584
- expect(action).toHaveProperty("type", "delete");
585
- if (action.type === "delete") {
586
- expect(action).toHaveProperty("key");
587
- expect(action).toHaveProperty("removedValue");
588
- expect(action.key).toBe("key1");
589
- expect(action.removedValue).toBe($value);
590
- }
591
- });
592
- });
593
-
594
- describe("clear action", () => {
595
- it("should update $lastAction with clear action when clear is called", async () => {
596
- const $map = map<string, FlowState<number>>({
597
- key1: state(1),
598
- key2: state(2),
599
- });
600
- $map.clear();
601
- const action = await $map.$lastAction.pick();
602
- expect(action.type).toBe("clear");
603
- if (action.type === "clear") {
604
- expect(action.clearedMap).toBeInstanceOf(Map);
605
- expect(action.clearedMap.size).toBe(2);
606
- }
607
- });
608
-
609
- it("should have correct structure for clear action (type + clearedMap)", async () => {
610
- const $map = map<string, FlowState<number>>({
611
- key1: state(1),
612
- });
613
- $map.clear();
614
- const action = await $map.$lastAction.pick();
615
- expect(action).toHaveProperty("type", "clear");
616
- if (action.type === "clear") {
617
- expect(action).toHaveProperty("clearedMap");
618
- expect(action.clearedMap).toBeInstanceOf(Map);
619
- }
620
- });
621
- });
622
- });
623
-
624
- describe("edge cases", () => {
625
- it("should handle multiple rapid operations", async () => {
626
- const $map = map<string, FlowState<number>>();
627
- $map.add("key1", state(1));
628
- $map.add("key2", state(2));
629
- $map.add("key3", state(3));
630
- $map.update("key1", state(10));
631
- $map.delete("key2");
632
- $map.add("key4", state(4));
633
- $map.clear();
634
- $map.add("key5", state(5));
635
-
636
- expect((await $map.pick()).size).toBe(1);
637
- expect(await (await $map.pick()).get("key5")?.pick()).toBe(5);
638
- });
639
-
640
- it("should handle empty map operations", async () => {
641
- const $map = map<string, FlowState<number>>();
642
- expect((await $map.pick()).size).toBe(0);
643
-
644
- $map.add("key1", state(1));
645
- expect((await $map.pick()).size).toBe(1);
646
-
647
- $map.delete("key1");
648
- expect((await $map.pick()).size).toBe(0);
649
- });
650
-
651
- it("should handle map with single entry", async () => {
652
- const $map = map<string, FlowState<number>>({
653
- key1: state(1),
654
- });
655
- expect((await $map.pick()).size).toBe(1);
656
-
657
- $map.update("key1", state(2));
658
- expect(await (await $map.pick()).get("key1")?.pick()).toBe(2);
659
-
660
- $map.delete("key1");
661
- expect((await $map.pick()).size).toBe(0);
662
- });
663
-
664
- it("should handle map with many entries", async () => {
665
- const $map = map<string, FlowState<number>>();
666
- for (let i = 0; i < 100; i++) {
667
- $map.add(`key${i}`, state(i));
668
- }
669
- expect((await $map.pick()).size).toBe(100);
670
-
671
- for (let i = 0; i < 50; i++) {
672
- $map.delete(`key${i}`);
673
- }
674
- expect((await $map.pick()).size).toBe(50);
675
- });
676
-
677
- it("should handle disposed values in map", async () => {
678
- const $value = state(1);
679
- const $map = map(new Map([["key1", $value]]));
680
-
681
- $map.delete("key1");
682
-
683
- // In flow2, values are NOT automatically disposed
684
- expect($value.disposed).toBe(false);
685
- expect((await $map.pick()).size).toBe(0);
686
- });
687
-
688
- it("should handle effects on FlowState values in map", async () => {
689
- const $value = state(1);
690
- const $map = map(new Map([["key1", $value]]));
691
- const onData = vi.fn();
692
-
693
- subscribe(
694
- (t) => $map.get(t).get("key1")?.get(t),
695
- (data) => {
696
- if (data) {
697
- onData(data);
698
- }
699
- },
700
- );
701
-
702
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
703
- expect(onData).toHaveBeenLastCalledWith(1);
704
-
705
- $value.set(2);
706
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
707
- expect(onData).toHaveBeenLastCalledWith(2);
708
- });
709
- });
710
- });
711
-
712
- describe("integration", () => {
713
- describe("with effects", () => {
714
- describe("reactivity", () => {
715
- it("should call effect when initialized", async () => {
716
- const $map = map<string, FlowState<number>>({
717
- key1: state(1),
718
- key2: state(2),
719
- });
720
- const onData = vi.fn();
721
- subscribe((t) => $map.get(t), onData);
722
-
723
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
724
- expect(onData).toHaveBeenLastCalledWith(
725
- expect.objectContaining({
726
- size: 2,
727
- }),
728
- );
729
- });
730
-
731
- it("should call effect when updated with set", async () => {
732
- const $map = map<string, FlowState<number>>({
733
- key1: state(1),
734
- });
735
- const onData = vi.fn();
736
- subscribe((t) => $map.get(t), onData);
737
-
738
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
739
-
740
- const $newValue = state(2);
741
- $map.set(new Map([["key2", $newValue]]));
742
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
743
- expect(onData).toHaveBeenLastCalledWith(
744
- expect.objectContaining({
745
- size: 1,
746
- }),
747
- );
748
- });
749
-
750
- it("should call effect when updated with add", async () => {
751
- const $map = map<string, FlowState<number>>();
752
- const onData = vi.fn();
753
- subscribe((t) => $map.get(t), onData);
754
-
755
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
756
- expect(onData).toHaveBeenLastCalledWith(new Map());
757
-
758
- const $key1Value = state(1);
759
- $map.add("key1", $key1Value);
760
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
761
- expect(onData).toHaveBeenLastCalledWith(new Map([["key1", $key1Value]]));
762
-
763
- const $key2Value = state(2);
764
- $map.add("key2", $key2Value);
765
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(3));
766
- expect(onData).toHaveBeenLastCalledWith(
767
- new Map([
768
- ["key1", $key1Value],
769
- ["key2", $key2Value],
770
- ]),
771
- );
772
- });
773
-
774
- it("should call effect when updated with update", async () => {
775
- const $map = map<string, FlowState<number>>();
776
- $map.add("key1", state(1));
777
- const onData = vi.fn();
778
- subscribe((t) => $map.get(t), onData);
779
-
780
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
781
-
782
- const $newValue = state(2);
783
- $map.update("key1", $newValue);
784
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
785
- expect(onData).toHaveBeenLastCalledWith(new Map([["key1", $newValue]]));
786
- });
787
-
788
- it("should call effect when updated with delete", async () => {
789
- const $map = map<string, FlowState<number>>();
790
- $map.add("key1", state(1));
791
- $map.add("key2", state(2));
792
- const onData = vi.fn();
793
- subscribe((t) => $map.get(t), onData);
794
-
795
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
796
-
797
- $map.delete("key1");
798
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
799
- const mapAfterDelete = onData.mock.calls[1][0];
800
- expect(mapAfterDelete.size).toBe(1);
801
- expect(mapAfterDelete.has("key2")).toBe(true);
802
- });
803
-
804
- it("should call effect when updated with clear", async () => {
805
- const $map = map<string, FlowState<number>>({
806
- key1: state(1),
807
- key2: state(2),
808
- });
809
- const onData = vi.fn();
810
- subscribe((t) => $map.get(t), onData);
811
-
812
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
813
-
814
- $map.clear();
815
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
816
- expect(onData).toHaveBeenLastCalledWith(new Map());
817
- });
818
-
819
- it("should call effect when FlowState values in map are updated", async () => {
820
- const $value = state(1);
821
- const $map = map(new Map([["key1", $value]]));
822
- const onData = vi.fn();
823
-
824
- subscribe(
825
- (t) => $map.get(t).get("key1")?.get(t),
826
- (data) => {
827
- if (data) {
828
- onData(data);
829
- }
830
- },
831
- );
832
-
833
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
834
- expect(onData).toHaveBeenLastCalledWith(1);
835
-
836
- $value.set(2);
837
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
838
- expect(onData).toHaveBeenLastCalledWith(2);
839
- });
840
- });
841
-
842
- describe("$lastAction", () => {
843
- it("should call effect when $lastAction is updated with set action", async () => {
844
- const $map = map<string, FlowState<number>>({
845
- key1: state(1),
846
- });
847
- const onData = vi.fn();
848
- subscribe((t) => $map.$lastAction.get(t), onData);
849
-
850
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
851
-
852
- const $newValue = state(2);
853
- $map.set(new Map([["key2", $newValue]]));
854
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
855
- expect(onData).toHaveBeenLastCalledWith({
856
- type: "set",
857
- setMap: expect.any(Map),
858
- clearedMap: expect.any(Map),
859
- });
860
- });
861
-
862
- it("should call effect when $lastAction is updated with add action", async () => {
863
- const $map = map<string, FlowState<number>>();
864
- const onData = vi.fn();
865
- subscribe((t) => $map.$lastAction.get(t), onData);
866
-
867
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
868
-
869
- const $value = state(1);
870
- $map.add("key1", $value);
871
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
872
- expect(onData).toHaveBeenLastCalledWith({
873
- type: "add",
874
- key: "key1",
875
- addedValue: $value,
876
- });
877
- });
878
-
879
- it("should call effect when $lastAction is updated with update action", async () => {
880
- const $map = map<string, FlowState<number>>();
881
- $map.add("key1", state(1));
882
- const onData = vi.fn();
883
- subscribe((t) => $map.$lastAction.get(t), onData);
884
-
885
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
886
-
887
- const $newValue = state(2);
888
- $map.update("key1", $newValue);
889
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
890
- expect(onData).toHaveBeenLastCalledWith({
891
- type: "update",
892
- key: "key1",
893
- setValue: $newValue,
894
- clearedValue: expect.any(Object),
895
- });
896
- });
897
-
898
- it("should call effect when $lastAction is updated with delete action", async () => {
899
- const $map = map<string, FlowState<number>>();
900
- const $value = state(1);
901
- $map.add("key1", $value);
902
- const onData = vi.fn();
903
- subscribe((t) => $map.$lastAction.get(t), onData);
904
-
905
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
906
-
907
- $map.delete("key1");
908
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
909
- expect(onData).toHaveBeenLastCalledWith({
910
- type: "delete",
911
- key: "key1",
912
- removedValue: $value,
913
- });
914
- });
915
-
916
- it("should call effect when $lastAction is updated with clear action", async () => {
917
- const $map = map<string, FlowState<number>>({
918
- key1: state(1),
919
- key2: state(2),
920
- });
921
- const onData = vi.fn();
922
- subscribe((t) => $map.$lastAction.get(t), onData);
923
-
924
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
925
-
926
- $map.clear();
927
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
928
- expect(onData).toHaveBeenLastCalledWith({
929
- type: "clear",
930
- clearedMap: expect.any(Map),
931
- });
932
- });
933
-
934
- it("should call effect when FlowState value in $lastAction is updated", async () => {
935
- const $map = map<string, FlowState<number>>();
936
- const $value = state(1);
937
- $map.add("key1", $value);
938
- const onData = vi.fn();
939
-
940
- subscribe((t) => {
941
- const action = $map.$lastAction.get(t);
942
- if (action.type === "add") {
943
- return action.addedValue.get(t);
944
- }
945
- return undefined;
946
- }, onData);
947
-
948
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
949
- expect(onData).toHaveBeenLastCalledWith(1);
950
-
951
- $value.set(2);
952
- await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(2));
953
- expect(onData).toHaveBeenLastCalledWith(2);
954
- });
955
- });
956
- });
957
- });
958
- });