@ersbeth/picoflow 2.0.2 → 2.0.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 (152) hide show
  1. package/README.md +10 -0
  2. package/SKILL.md +106 -0
  3. package/package.json +5 -1
  4. package/.gitlab-ci.yml +0 -24
  5. package/.vscode/settings.json +0 -5
  6. package/CHANGELOG.md +0 -94
  7. package/biome.json +0 -47
  8. package/docs/.vitepress/config.mts +0 -145
  9. package/docs/api/functions/array.md +0 -35
  10. package/docs/api/functions/constant.md +0 -33
  11. package/docs/api/functions/constantAsync.md +0 -69
  12. package/docs/api/functions/derivation.md +0 -34
  13. package/docs/api/functions/derivationAsync.md +0 -34
  14. package/docs/api/functions/from.md +0 -129
  15. package/docs/api/functions/isDisposable.md +0 -27
  16. package/docs/api/functions/map.md +0 -36
  17. package/docs/api/functions/signal.md +0 -21
  18. package/docs/api/functions/state.md +0 -67
  19. package/docs/api/functions/stateAsync.md +0 -69
  20. package/docs/api/functions/subscribe.md +0 -40
  21. package/docs/api/functions/writableDerivation.md +0 -33
  22. package/docs/api/functions/writableDerivationAsync.md +0 -34
  23. package/docs/api/index.md +0 -61
  24. package/docs/api/interfaces/FlowArray.md +0 -439
  25. package/docs/api/interfaces/FlowConstant.md +0 -220
  26. package/docs/api/interfaces/FlowConstantAsync.md +0 -221
  27. package/docs/api/interfaces/FlowDerivation.md +0 -241
  28. package/docs/api/interfaces/FlowDerivationAsync.md +0 -242
  29. package/docs/api/interfaces/FlowDisposable.md +0 -59
  30. package/docs/api/interfaces/FlowEffect.md +0 -64
  31. package/docs/api/interfaces/FlowMap.md +0 -374
  32. package/docs/api/interfaces/FlowObservable.md +0 -155
  33. package/docs/api/interfaces/FlowSignal.md +0 -156
  34. package/docs/api/interfaces/FlowState.md +0 -269
  35. package/docs/api/interfaces/FlowStateAsync.md +0 -268
  36. package/docs/api/interfaces/FlowSubscribable.md +0 -55
  37. package/docs/api/interfaces/FlowTracker.md +0 -61
  38. package/docs/api/interfaces/FlowValue.md +0 -222
  39. package/docs/api/interfaces/FlowWritableDerivation.md +0 -292
  40. package/docs/api/interfaces/FlowWritableDerivationAsync.md +0 -293
  41. package/docs/api/type-aliases/DerivationFunction.md +0 -28
  42. package/docs/api/type-aliases/DerivationFunctionAsync.md +0 -28
  43. package/docs/api/type-aliases/FlowArrayAction.md +0 -60
  44. package/docs/api/type-aliases/FlowDataTracker.md +0 -33
  45. package/docs/api/type-aliases/FlowMapAction.md +0 -48
  46. package/docs/api/type-aliases/FlowOnDataListener.md +0 -33
  47. package/docs/api/type-aliases/FlowOnErrorListener.md +0 -27
  48. package/docs/api/type-aliases/FlowOnPendingListener.md +0 -21
  49. package/docs/api/type-aliases/FlowReadonly.md +0 -22
  50. package/docs/api/type-aliases/InitFunction.md +0 -21
  51. package/docs/api/type-aliases/InitFunctionAsync.md +0 -21
  52. package/docs/api/type-aliases/NotPromise.md +0 -21
  53. package/docs/api/type-aliases/UpdateFunction.md +0 -27
  54. package/docs/api/type-aliases/UpdateFunctionAsync.md +0 -27
  55. package/docs/api/typedoc-sidebar.json +0 -65
  56. package/docs/examples/examples.md +0 -2311
  57. package/docs/examples/patterns.md +0 -649
  58. package/docs/guide/advanced/architecture.md +0 -1234
  59. package/docs/guide/advanced/disposal.md +0 -426
  60. package/docs/guide/advanced/migration-v1.md +0 -464
  61. package/docs/guide/advanced/migration-v2.md +0 -204
  62. package/docs/guide/advanced/solidjs.md +0 -135
  63. package/docs/guide/introduction/concepts.md +0 -57
  64. package/docs/guide/introduction/conventions.md +0 -30
  65. package/docs/guide/introduction/getting-started.md +0 -139
  66. package/docs/guide/introduction/lifecycle.md +0 -368
  67. package/docs/guide/primitives/array.md +0 -286
  68. package/docs/guide/primitives/constant.md +0 -207
  69. package/docs/guide/primitives/derivations.md +0 -281
  70. package/docs/guide/primitives/effects.md +0 -372
  71. package/docs/guide/primitives/map.md +0 -265
  72. package/docs/guide/primitives/overview.md +0 -92
  73. package/docs/guide/primitives/signal.md +0 -222
  74. package/docs/guide/primitives/state.md +0 -272
  75. package/docs/index.md +0 -47
  76. package/docs/public/logo.svg +0 -1
  77. package/src/api/base/flowDisposable.ts +0 -44
  78. package/src/api/base/flowObservable.ts +0 -28
  79. package/src/api/base/flowSubscribable.ts +0 -87
  80. package/src/api/base/flowTracker.ts +0 -7
  81. package/src/api/base/index.ts +0 -4
  82. package/src/api/index.ts +0 -2
  83. package/src/api/nodes/async/flowConstantAsync.ts +0 -36
  84. package/src/api/nodes/async/flowDerivationAsync.ts +0 -42
  85. package/src/api/nodes/async/flowStateAsync.ts +0 -47
  86. package/src/api/nodes/async/flowWritableDerivationAsync.ts +0 -33
  87. package/src/api/nodes/async/index.ts +0 -4
  88. package/src/api/nodes/collections/flowArray.ts +0 -155
  89. package/src/api/nodes/collections/flowMap.ts +0 -115
  90. package/src/api/nodes/collections/index.ts +0 -2
  91. package/src/api/nodes/flowEffect.ts +0 -42
  92. package/src/api/nodes/flowSignal.ts +0 -28
  93. package/src/api/nodes/flowValue.ts +0 -37
  94. package/src/api/nodes/index.ts +0 -7
  95. package/src/api/nodes/sync/flowConstant.ts +0 -33
  96. package/src/api/nodes/sync/flowDerivation.ts +0 -41
  97. package/src/api/nodes/sync/flowState.ts +0 -45
  98. package/src/api/nodes/sync/flowWritableDerivation.ts +0 -31
  99. package/src/api/nodes/sync/index.ts +0 -4
  100. package/src/api/nodes/utils.ts +0 -24
  101. package/src/base/disposable.ts +0 -18
  102. package/src/base/executionStack.ts +0 -42
  103. package/src/base/index.ts +0 -5
  104. package/src/base/node.ts +0 -98
  105. package/src/base/observable.ts +0 -92
  106. package/src/base/observer.ts +0 -51
  107. package/src/converters/index.ts +0 -1
  108. package/src/converters/solid.ts +0 -109
  109. package/src/index.ts +0 -2
  110. package/src/nodes/arrayNode.ts +0 -180
  111. package/src/nodes/effectNode.ts +0 -58
  112. package/src/nodes/index.ts +0 -7
  113. package/src/nodes/mapNode.ts +0 -125
  114. package/src/nodes/signalNode.ts +0 -19
  115. package/src/nodes/valueAsyncNode.ts +0 -85
  116. package/src/nodes/valueNode.ts +0 -148
  117. package/src/nodes/valueSyncNode.ts +0 -125
  118. package/src/schedulers/asyncResolver.ts +0 -78
  119. package/src/schedulers/asyncScheduler.ts +0 -66
  120. package/src/schedulers/index.ts +0 -4
  121. package/src/schedulers/pendingError.ts +0 -13
  122. package/src/schedulers/scheduler.ts +0 -9
  123. package/src/schedulers/syncResolver.ts +0 -69
  124. package/src/schedulers/syncScheduler.ts +0 -55
  125. package/test/base/pendingError.test.ts +0 -67
  126. package/test/converters/solid.derivation.browser.test.tsx +0 -69
  127. package/test/converters/solid.node.test.ts +0 -654
  128. package/test/converters/solid.state.browser.test.tsx +0 -1592
  129. package/test/reactivity/flowSignal.test.ts +0 -226
  130. package/test/reactivity/nodes/async/asyncScheduler/asyncResolver.test.ts +0 -593
  131. package/test/reactivity/nodes/async/asyncScheduler/asyncScheduler.test.ts +0 -317
  132. package/test/reactivity/nodes/async/flowConstantAsync.test.ts +0 -652
  133. package/test/reactivity/nodes/async/flowDerivation.test.ts +0 -898
  134. package/test/reactivity/nodes/async/flowDerivationAsync.test.ts +0 -1716
  135. package/test/reactivity/nodes/async/flowStateAsync.test.ts +0 -708
  136. package/test/reactivity/nodes/async/flowWritableDerivationAsync.test.ts +0 -614
  137. package/test/reactivity/nodes/collections/flowArray.asyncStates.test.ts +0 -1289
  138. package/test/reactivity/nodes/collections/flowArray.scalars.test.ts +0 -961
  139. package/test/reactivity/nodes/collections/flowArray.states.test.ts +0 -1035
  140. package/test/reactivity/nodes/collections/flowMap.asyncStates.test.ts +0 -960
  141. package/test/reactivity/nodes/collections/flowMap.scalars.test.ts +0 -775
  142. package/test/reactivity/nodes/collections/flowMap.states.test.ts +0 -958
  143. package/test/reactivity/nodes/sync/flowConstant.test.ts +0 -377
  144. package/test/reactivity/nodes/sync/flowDerivation.test.ts +0 -896
  145. package/test/reactivity/nodes/sync/flowState.test.ts +0 -341
  146. package/test/reactivity/nodes/sync/flowWritableDerivation.test.ts +0 -603
  147. package/test/vitest.d.ts +0 -10
  148. package/tsconfig.json +0 -37
  149. package/typedoc.json +0 -37
  150. package/vite.config.ts +0 -31
  151. package/vitest.browser.config.ts +0 -21
  152. 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
- });