@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,654 +0,0 @@
1
- import { createEffect, createRoot } from "solid-js";
2
- import { describe, expect, it, vi } from "vitest";
3
- import type { FlowTracker } from "~";
4
- import { derivation, derivationAsync, from, state, stateAsync } from "~";
5
-
6
- describe("converters", () => {
7
- describe("from", () => {
8
- describe("unit", () => {
9
- describe("initialization", () => {
10
- it("should convert synchronous FlowNode to SolidResource", async () => {
11
- await createRoot(async (dispose) => {
12
- const $state = state(42);
13
- const solidResource = from($state);
14
-
15
- await vi.waitFor(() => expect(solidResource()).toBe(42));
16
- dispose();
17
- });
18
- });
19
-
20
- it("should convert FlowNodeAsync to SolidResource", async () => {
21
- await createRoot(async (dispose) => {
22
- const $stateAsync = stateAsync(Promise.resolve(42));
23
- const solidResource = from($stateAsync);
24
-
25
- await vi.waitFor(() => expect(solidResource()).toBe(42));
26
- dispose();
27
- });
28
- });
29
-
30
- it("should convert synchronous getter function to SolidResource", async () => {
31
- await createRoot(async (dispose) => {
32
- const $state = state(42);
33
- const getter = (t: FlowTracker) => $state.get(t);
34
- const solidResource = from(getter);
35
-
36
- await vi.waitFor(() => expect(solidResource()).toBe(42));
37
- dispose();
38
- });
39
- });
40
-
41
- it("should return a SolidResource instance", async () => {
42
- await createRoot(async (dispose) => {
43
- const $state = state(42);
44
- const solidResource = from($state);
45
-
46
- await vi.waitFor(() => expect(solidResource()).toBe(42));
47
- dispose();
48
- });
49
- });
50
- });
51
-
52
- describe("conversion from FlowNode (synchronous)", () => {
53
- it("should convert a FlowState to SolidResource", async () => {
54
- await createRoot(async (dispose) => {
55
- const $state = state(42);
56
- const solidResource = from($state);
57
-
58
- await vi.waitFor(() => expect(solidResource()).toBe(42));
59
- dispose();
60
- });
61
- });
62
-
63
- it("should convert a FlowDerivation to SolidResource", async () => {
64
- await createRoot(async (dispose) => {
65
- const $state = state(5);
66
- const $derivation = derivation((t) => $state.get(t) * 2);
67
- const solidResource = from($derivation);
68
-
69
- await vi.waitFor(() => expect(solidResource()).toBe(10));
70
- dispose();
71
- });
72
- });
73
-
74
- it("should initialize with FlowNode value", async () => {
75
- await createRoot(async (dispose) => {
76
- const $state = state(42);
77
- const solidResource = from($state);
78
-
79
- // Wait for resource to load
80
- await vi.waitFor(() => expect(solidResource()).toBe(42));
81
- dispose();
82
- });
83
- });
84
-
85
- it("should handle number values", async () => {
86
- await createRoot(async (dispose) => {
87
- const $state = state(42);
88
- const solidResource = from($state);
89
-
90
- await vi.waitFor(() => expect(solidResource()).toBe(42));
91
- dispose();
92
- });
93
- });
94
-
95
- it("should handle string values", async () => {
96
- await createRoot(async (dispose) => {
97
- const $state = state("hello");
98
- const solidResource = from($state);
99
-
100
- await vi.waitFor(() => expect(solidResource()).toBe("hello"));
101
- dispose();
102
- });
103
- });
104
-
105
- it("should handle object values", async () => {
106
- await createRoot(async (dispose) => {
107
- const obj = { a: 1, b: 2 };
108
- const $state = state(obj);
109
- const solidResource = from($state);
110
-
111
- await vi.waitFor(() => expect(solidResource()).toEqual({ a: 1, b: 2 }));
112
- dispose();
113
- });
114
- });
115
-
116
- it("should handle array values", async () => {
117
- await createRoot(async (dispose) => {
118
- const arr = [1, 2, 3];
119
- const $state = state(arr);
120
- const solidResource = from($state);
121
-
122
- await vi.waitFor(() => expect(solidResource()).toEqual([1, 2, 3]));
123
- dispose();
124
- });
125
- });
126
-
127
- it("should handle null values", async () => {
128
- await createRoot(async (dispose) => {
129
- const $stateNull = state(null);
130
- const solidResourceNull = from($stateNull);
131
-
132
- await vi.waitFor(() => expect(solidResourceNull()).toBeNull());
133
- dispose();
134
- });
135
- });
136
-
137
- it("should handle undefined values", async () => {
138
- await createRoot(async (dispose) => {
139
- const $stateUndefined = state(undefined);
140
- const solidResourceUndefined = from($stateUndefined);
141
-
142
- await vi.waitFor(() => expect(solidResourceUndefined()).toBeUndefined());
143
- dispose();
144
- });
145
- });
146
- });
147
-
148
- describe("conversion from FlowNodeAsync (asynchronous)", () => {
149
- it("should convert a FlowStateAsync to SolidResource", async () => {
150
- await createRoot(async (dispose) => {
151
- const $stateAsync = stateAsync(Promise.resolve(42));
152
- const solidResource = from($stateAsync);
153
-
154
- await vi.waitFor(() => expect(solidResource()).toBe(42));
155
- dispose();
156
- });
157
- });
158
-
159
- it("should convert a FlowDerivationAsync to SolidResource", async () => {
160
- await createRoot(async (dispose) => {
161
- const $stateAsync = stateAsync(Promise.resolve(5));
162
- const $derivationAsync = derivationAsync(async (t) => $stateAsync.get(t) * 2);
163
- const solidResource = from($derivationAsync);
164
-
165
- await vi.waitFor(() => expect(solidResource()).toBe(10));
166
- dispose();
167
- });
168
- });
169
-
170
- it("should initialize with FlowNodeAsync value", async () => {
171
- await createRoot(async (dispose) => {
172
- const $stateAsync = stateAsync(Promise.resolve(42));
173
- const solidResource = from($stateAsync);
174
-
175
- await vi.waitFor(() => expect(solidResource()).toBe(42));
176
- dispose();
177
- });
178
- });
179
-
180
- it("should handle resolved Promises", async () => {
181
- await createRoot(async (dispose) => {
182
- const $stateAsync = stateAsync(Promise.resolve(42));
183
- const solidResource = from($stateAsync);
184
-
185
- await vi.waitFor(() => expect(solidResource()).toBe(42));
186
- dispose();
187
- });
188
- });
189
-
190
- it("should handle rejected Promises", async () => {
191
- await createRoot(async (dispose) => {
192
- const error = new Error("Test error");
193
- const $stateAsync = stateAsync(Promise.reject(error));
194
-
195
- const solidResource = from($stateAsync);
196
- await vi.waitFor(() => expect(solidResource.error).toBe(error));
197
- dispose();
198
- });
199
- });
200
- });
201
-
202
- describe("conversion from getter function", () => {
203
- it("should convert a synchronous getter to SolidResource", async () => {
204
- await createRoot(async (dispose) => {
205
- const $state = state(42);
206
- const getter = (t: FlowTracker) => $state.get(t);
207
- const solidResource = from(getter);
208
-
209
- await vi.waitFor(() => expect(solidResource()).toBe(42));
210
- dispose();
211
- });
212
- });
213
-
214
- it("should track dependencies in the getter", async () => {
215
- await createRoot(async (dispose) => {
216
- const $state = state(5);
217
- const getter = (t: FlowTracker) => $state.get(t) * 2;
218
- const solidResource = from(getter);
219
-
220
- await vi.waitFor(() => expect(solidResource()).toBe(10));
221
-
222
- $state.set(6);
223
- await vi.waitFor(() => expect(solidResource()).toBe(12));
224
- dispose();
225
- });
226
- });
227
-
228
- it("should create a FlowNodeSync from the getter", async () => {
229
- await createRoot(async (dispose) => {
230
- const $state = state(42);
231
- const getter = (t: FlowTracker) => $state.get(t);
232
- const solidResource = from(getter);
233
-
234
- await vi.waitFor(() => expect(solidResource()).toBe(42));
235
- dispose();
236
- });
237
- });
238
- });
239
-
240
- describe("reactivity", () => {
241
- it("should update SolidResource when FlowState changes", async () => {
242
- await createRoot(async (dispose) => {
243
- const $state = state(0);
244
- const solidResource = from($state);
245
-
246
- // Wait for initial load
247
- await vi.waitFor(() => expect(solidResource()).toBe(0));
248
- const fn = vi.fn();
249
-
250
- createEffect(() => {
251
- fn(solidResource());
252
- });
253
-
254
- // Wait for effect to run
255
- await vi.waitFor(() => {
256
- expect(fn).toHaveBeenCalledTimes(1);
257
- });
258
- expect(fn).toHaveBeenLastCalledWith(0);
259
-
260
- // Update FlowState
261
- $state.set(1);
262
-
263
- // Wait for update
264
- await vi.waitFor(() => {
265
- expect(fn).toHaveBeenCalledTimes(2);
266
- });
267
- expect(fn).toHaveBeenLastCalledWith(1);
268
- dispose();
269
- });
270
- });
271
-
272
- it("should update SolidResource when FlowDerivation changes", async () => {
273
- await createRoot(async (dispose) => {
274
- const $state = state(5);
275
- const $derivation = derivation((t) => $state.get(t) * 2);
276
- const solidResource = from($derivation);
277
-
278
- // Wait for initial load
279
- await vi.waitFor(() => expect(solidResource()).toBe(10));
280
-
281
- const fn = vi.fn();
282
- createEffect(() => {
283
- fn(solidResource());
284
- });
285
-
286
- // Wait for effect to run
287
- await vi.waitFor(() => expect(fn).toHaveBeenCalledTimes(1));
288
- expect(fn).toHaveBeenLastCalledWith(10);
289
-
290
- // Update dependency
291
- $state.set(6);
292
-
293
- // Wait for update
294
- await vi.waitFor(() => {
295
- expect(fn).toHaveBeenCalledTimes(2);
296
- });
297
- expect(fn).toHaveBeenLastCalledWith(12);
298
- dispose();
299
- });
300
- });
301
-
302
- it("should update SolidResource when FlowStateAsync changes", async () => {
303
- await createRoot(async (dispose) => {
304
- const $stateAsync = stateAsync(Promise.resolve(0));
305
- const solidResource = from($stateAsync);
306
-
307
- // Wait for initial load
308
- await vi.waitFor(() => expect(solidResource()).toBe(0));
309
-
310
- const fn = vi.fn();
311
- createEffect(() => {
312
- fn(solidResource());
313
- });
314
-
315
- // Wait for effect to run
316
- await vi.waitFor(() => expect(fn).toHaveBeenCalledTimes(1));
317
- expect(fn).toHaveBeenLastCalledWith(0);
318
-
319
- // Update FlowStateAsync
320
- $stateAsync.set(Promise.resolve(1));
321
-
322
- // Wait for update
323
- await vi.waitFor(() => {
324
- expect(fn).toHaveBeenCalledTimes(2);
325
- });
326
- expect(fn).toHaveBeenLastCalledWith(1);
327
-
328
- dispose();
329
- });
330
- });
331
-
332
- it("should update SolidResource when FlowDerivationAsync changes", async () => {
333
- await createRoot(async (dispose) => {
334
- const $stateAsync = stateAsync(Promise.resolve(5));
335
- const $derivationAsync = derivationAsync(async (t) => (await $stateAsync.get(t)) * 2);
336
- const solidResource = from($derivationAsync);
337
-
338
- // Wait for initial load
339
- await vi.waitFor(() => expect(solidResource()).toBe(10));
340
-
341
- const fn = vi.fn();
342
- createEffect(() => {
343
- fn(solidResource());
344
- });
345
-
346
- // Wait for effect to run
347
- await vi.waitFor(() => expect(fn).toHaveBeenCalledTimes(1));
348
- expect(fn).toHaveBeenLastCalledWith(10);
349
-
350
- // Update async dependency
351
- $stateAsync.set(Promise.resolve(6));
352
-
353
- // Wait for update
354
- await vi.waitFor(() => {
355
- expect(fn).toHaveBeenCalledTimes(2);
356
- });
357
- expect(fn).toHaveBeenLastCalledWith(12);
358
- dispose();
359
- });
360
- });
361
-
362
- it("should update SolidResource when getter dependency changes", async () => {
363
- await createRoot(async (dispose) => {
364
- const $state = state(5);
365
- const getter = (t: FlowTracker) => $state.get(t) * 2;
366
- const solidResource = from(getter);
367
-
368
- // Wait for initial load
369
- await vi.waitFor(() => expect(solidResource()).toBe(10));
370
-
371
- const fn = vi.fn();
372
- createEffect(() => {
373
- fn(solidResource());
374
- });
375
-
376
- // Wait for effect to run
377
- await vi.waitFor(() => expect(fn).toHaveBeenCalledTimes(1));
378
- expect(fn).toHaveBeenLastCalledWith(10);
379
-
380
- // Update the tracked FlowNode
381
- $state.set(6);
382
-
383
- // Wait for update
384
- await vi.waitFor(() => {
385
- expect(fn).toHaveBeenCalledTimes(2);
386
- });
387
- expect(fn).toHaveBeenLastCalledWith(12);
388
-
389
- dispose();
390
- });
391
- });
392
-
393
- it("should propagate multiple sequential changes", async () => {
394
- await createRoot(async (dispose) => {
395
- const $state = state(0);
396
- const solidResource = from($state);
397
-
398
- // Wait for initial load
399
- await vi.waitFor(() => expect(solidResource()).toBe(0));
400
-
401
- const fn = vi.fn();
402
- createEffect(() => {
403
- fn(solidResource());
404
- });
405
-
406
- // Wait for initial effect
407
- await vi.waitFor(() => expect(fn).toHaveBeenCalledTimes(1));
408
- expect(fn).toHaveBeenLastCalledWith(0);
409
-
410
- // Make multiple changes
411
- $state.set(1);
412
- await vi.waitFor(() => expect(solidResource()).toBe(1));
413
-
414
- $state.set(2);
415
- await vi.waitFor(() => expect(solidResource()).toBe(2));
416
-
417
- $state.set(3);
418
- await vi.waitFor(() => {
419
- expect(solidResource()).toBe(3);
420
- });
421
- dispose();
422
- });
423
- });
424
-
425
- it("should be reactive within createRoot", async () => {
426
- await createRoot(async (dispose) => {
427
- const $state = state(0);
428
- const solidResource = from($state);
429
-
430
- // Wait for initial load
431
- await vi.waitFor(() => expect(solidResource()).toBe(0));
432
-
433
- $state.set(1);
434
- await vi.waitFor(() => expect(solidResource()).toBe(1));
435
-
436
- $state.set(2);
437
- await vi.waitFor(() => expect(solidResource()).toBe(2));
438
- dispose();
439
- });
440
- });
441
-
442
- it("should update SolidResource.get() value when FlowNode changes", async () => {
443
- await createRoot(async (dispose) => {
444
- const $state = state(0);
445
- const solidResource = from($state);
446
-
447
- // Wait for initial load
448
- await vi.waitFor(() => expect(solidResource()).toBe(0));
449
-
450
- $state.set(1);
451
- await vi.waitFor(() => expect(solidResource()).toBe(1));
452
-
453
- // Test async updates for FlowNodeAsync
454
- const $stateAsync = stateAsync(Promise.resolve(10));
455
- const solidResourceAsync = from($stateAsync);
456
-
457
- await vi.waitFor(() => expect(solidResourceAsync()).toBe(10));
458
-
459
- $stateAsync.set(Promise.resolve(20));
460
- await vi.waitFor(() => expect(solidResourceAsync()).toBe(20));
461
- dispose();
462
- });
463
- });
464
-
465
- it("should trigger createEffect when FlowNode value changes", async () => {
466
- await createRoot(async (dispose) => {
467
- const $state = state(0);
468
- const solidResource = from($state);
469
-
470
- // Wait for initial load
471
- await vi.waitFor(() => expect(solidResource()).toBe(0));
472
-
473
- const fn = vi.fn();
474
- createEffect(() => {
475
- fn(solidResource());
476
- });
477
-
478
- // Wait for initial effect
479
- await vi.waitFor(() => expect(fn).toHaveBeenCalledTimes(1));
480
- expect(fn).toHaveBeenLastCalledWith(0);
481
-
482
- // Change FlowNode
483
- $state.set(1);
484
- await vi.waitFor(() => expect(fn).toHaveBeenCalledTimes(2));
485
- expect(fn).toHaveBeenLastCalledWith(1);
486
-
487
- // Test with async FlowNode
488
- const $stateAsync = stateAsync(Promise.resolve(10));
489
- const solidResourceAsync = from($stateAsync);
490
-
491
- await vi.waitFor(() => expect(solidResourceAsync()).toBe(10));
492
-
493
- const fn2 = vi.fn();
494
- createEffect(() => {
495
- fn2(solidResourceAsync());
496
- });
497
-
498
- await vi.waitFor(() => expect(fn2).toHaveBeenCalledTimes(1));
499
- expect(fn2).toHaveBeenLastCalledWith(10);
500
-
501
- $stateAsync.set(Promise.resolve(20));
502
- await vi.waitFor(() => expect(fn2).toHaveBeenCalledTimes(2));
503
- expect(fn2).toHaveBeenLastCalledWith(20);
504
- dispose();
505
- });
506
- });
507
- });
508
-
509
- describe("cleanup", () => {
510
- it("should dispose FlowEffect on cleanup", async () => {
511
- await createRoot(async (dispose) => {
512
- const $state = state(0);
513
- const solidResource = from($state);
514
-
515
- // Wait for initial load
516
- await vi.waitFor(() => expect(solidResource()).toBe(0));
517
-
518
- const fn = vi.fn();
519
- createEffect(() => {
520
- fn(solidResource());
521
- });
522
-
523
- await vi.waitFor(() => expect(fn).toHaveBeenCalledTimes(1));
524
- expect(fn).toHaveBeenLastCalledWith(0);
525
-
526
- // Dispose
527
- dispose();
528
-
529
- // Try to update - should not trigger effects after dispose
530
- $state.set(1);
531
- await new Promise((resolve) => setTimeout(resolve, 20));
532
-
533
- // Effect count should not have increased after dispose
534
- expect(fn).toHaveBeenCalledTimes(1);
535
- });
536
- });
537
-
538
- it("should clean up subscriptions on unmount", async () => {
539
- await createRoot(async (dispose) => {
540
- const $state = state(0);
541
- const solidResource = from($state);
542
-
543
- // Wait for initial load
544
- await vi.waitFor(() => expect(solidResource()).toBe(0));
545
-
546
- const fn = vi.fn();
547
- createEffect(() => {
548
- fn(solidResource());
549
- });
550
-
551
- await vi.waitFor(() => expect(fn).toHaveBeenCalledTimes(1));
552
- expect(fn).toHaveBeenLastCalledWith(0);
553
-
554
- // Dispose (unmount)
555
- dispose();
556
-
557
- // Update should not trigger after unmount
558
- $state.set(1);
559
- await new Promise((resolve) => setTimeout(resolve, 20));
560
-
561
- expect(fn).toHaveBeenCalledTimes(1);
562
- });
563
- });
564
-
565
- it("should not update after dispose", async () => {
566
- await createRoot(async (dispose) => {
567
- const $state = state(0);
568
- const solidResource = from($state);
569
-
570
- // Wait for initial load
571
- await vi.waitFor(() => expect(solidResource()).toBe(0));
572
-
573
- const initialValue = solidResource();
574
- expect(initialValue).toBe(0);
575
-
576
- // Dispose
577
- dispose();
578
-
579
- // Update FlowNode
580
- $state.set(1);
581
-
582
- // Wait a bit
583
- await new Promise((resolve) => setTimeout(resolve, 20));
584
-
585
- // Value should not have changed after dispose
586
- // Note: The resource might still have the old value cached, but it shouldn't update
587
- // This test verifies that updates stop after dispose
588
- expect(solidResource()).toBe(initialValue);
589
- });
590
- });
591
- });
592
-
593
- describe("integration with SolidJS", () => {
594
- it("should work with createEffect", async () => {
595
- await createRoot(async (dispose) => {
596
- const $state = state(0);
597
- const solidResource = from($state);
598
-
599
- // Wait for initial load
600
- await vi.waitFor(() => expect(solidResource()).toBe(0));
601
-
602
- const values: number[] = [];
603
- createEffect(() => {
604
- values.push(solidResource() ?? 0);
605
- });
606
-
607
- await vi.waitFor(() => {
608
- expect(values.length).toBeGreaterThan(0);
609
- expect(values[0]).toBe(0);
610
- });
611
-
612
- $state.set(1);
613
- await vi.waitFor(() => {
614
- expect(solidResource()).toBe(1);
615
- expect(values.length).toBeGreaterThan(1);
616
- });
617
- dispose();
618
- });
619
- });
620
-
621
- it("should handle multiple simultaneous conversions", async () => {
622
- await createRoot(async (dispose) => {
623
- const $state1 = state(1);
624
- const $state2 = state(2);
625
- const $state3 = state(3);
626
-
627
- const solidResource1 = from($state1);
628
- const solidResource2 = from($state2);
629
- const solidResource3 = from($state3);
630
-
631
- // Wait for all to load
632
- await Promise.all([
633
- vi.waitFor(() => expect(solidResource1()).toBe(1)),
634
- vi.waitFor(() => expect(solidResource2()).toBe(2)),
635
- vi.waitFor(() => expect(solidResource3()).toBe(3)),
636
- ]);
637
-
638
- // Update all
639
- $state1.set(10);
640
- $state2.set(20);
641
- $state3.set(30);
642
-
643
- await Promise.all([
644
- vi.waitFor(() => expect(solidResource1()).toBe(10)),
645
- vi.waitFor(() => expect(solidResource2()).toBe(20)),
646
- vi.waitFor(() => expect(solidResource3()).toBe(30)),
647
- ]);
648
- dispose();
649
- });
650
- });
651
- });
652
- });
653
- });
654
- });