@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.
- package/README.md +10 -0
- package/SKILL.md +106 -0
- package/package.json +5 -1
- package/.gitlab-ci.yml +0 -24
- package/.vscode/settings.json +0 -5
- package/CHANGELOG.md +0 -94
- package/biome.json +0 -47
- package/docs/.vitepress/config.mts +0 -145
- package/docs/api/functions/array.md +0 -35
- package/docs/api/functions/constant.md +0 -33
- package/docs/api/functions/constantAsync.md +0 -69
- package/docs/api/functions/derivation.md +0 -34
- package/docs/api/functions/derivationAsync.md +0 -34
- package/docs/api/functions/from.md +0 -129
- package/docs/api/functions/isDisposable.md +0 -27
- package/docs/api/functions/map.md +0 -36
- package/docs/api/functions/signal.md +0 -21
- package/docs/api/functions/state.md +0 -67
- package/docs/api/functions/stateAsync.md +0 -69
- package/docs/api/functions/subscribe.md +0 -40
- package/docs/api/functions/writableDerivation.md +0 -33
- package/docs/api/functions/writableDerivationAsync.md +0 -34
- package/docs/api/index.md +0 -61
- package/docs/api/interfaces/FlowArray.md +0 -439
- package/docs/api/interfaces/FlowConstant.md +0 -220
- package/docs/api/interfaces/FlowConstantAsync.md +0 -221
- package/docs/api/interfaces/FlowDerivation.md +0 -241
- package/docs/api/interfaces/FlowDerivationAsync.md +0 -242
- package/docs/api/interfaces/FlowDisposable.md +0 -59
- package/docs/api/interfaces/FlowEffect.md +0 -64
- package/docs/api/interfaces/FlowMap.md +0 -374
- package/docs/api/interfaces/FlowObservable.md +0 -155
- package/docs/api/interfaces/FlowSignal.md +0 -156
- package/docs/api/interfaces/FlowState.md +0 -269
- package/docs/api/interfaces/FlowStateAsync.md +0 -268
- package/docs/api/interfaces/FlowSubscribable.md +0 -55
- package/docs/api/interfaces/FlowTracker.md +0 -61
- package/docs/api/interfaces/FlowValue.md +0 -222
- package/docs/api/interfaces/FlowWritableDerivation.md +0 -292
- package/docs/api/interfaces/FlowWritableDerivationAsync.md +0 -293
- package/docs/api/type-aliases/DerivationFunction.md +0 -28
- package/docs/api/type-aliases/DerivationFunctionAsync.md +0 -28
- package/docs/api/type-aliases/FlowArrayAction.md +0 -60
- package/docs/api/type-aliases/FlowDataTracker.md +0 -33
- package/docs/api/type-aliases/FlowMapAction.md +0 -48
- package/docs/api/type-aliases/FlowOnDataListener.md +0 -33
- package/docs/api/type-aliases/FlowOnErrorListener.md +0 -27
- package/docs/api/type-aliases/FlowOnPendingListener.md +0 -21
- package/docs/api/type-aliases/FlowReadonly.md +0 -22
- package/docs/api/type-aliases/InitFunction.md +0 -21
- package/docs/api/type-aliases/InitFunctionAsync.md +0 -21
- package/docs/api/type-aliases/NotPromise.md +0 -21
- package/docs/api/type-aliases/UpdateFunction.md +0 -27
- package/docs/api/type-aliases/UpdateFunctionAsync.md +0 -27
- package/docs/api/typedoc-sidebar.json +0 -65
- package/docs/examples/examples.md +0 -2311
- package/docs/examples/patterns.md +0 -649
- package/docs/guide/advanced/architecture.md +0 -1234
- package/docs/guide/advanced/disposal.md +0 -426
- package/docs/guide/advanced/migration-v1.md +0 -464
- package/docs/guide/advanced/migration-v2.md +0 -204
- package/docs/guide/advanced/solidjs.md +0 -135
- package/docs/guide/introduction/concepts.md +0 -57
- package/docs/guide/introduction/conventions.md +0 -30
- package/docs/guide/introduction/getting-started.md +0 -139
- package/docs/guide/introduction/lifecycle.md +0 -368
- package/docs/guide/primitives/array.md +0 -286
- package/docs/guide/primitives/constant.md +0 -207
- package/docs/guide/primitives/derivations.md +0 -281
- package/docs/guide/primitives/effects.md +0 -372
- package/docs/guide/primitives/map.md +0 -265
- package/docs/guide/primitives/overview.md +0 -92
- package/docs/guide/primitives/signal.md +0 -222
- package/docs/guide/primitives/state.md +0 -272
- package/docs/index.md +0 -47
- package/docs/public/logo.svg +0 -1
- package/src/api/base/flowDisposable.ts +0 -44
- package/src/api/base/flowObservable.ts +0 -28
- package/src/api/base/flowSubscribable.ts +0 -87
- package/src/api/base/flowTracker.ts +0 -7
- package/src/api/base/index.ts +0 -4
- package/src/api/index.ts +0 -2
- package/src/api/nodes/async/flowConstantAsync.ts +0 -36
- package/src/api/nodes/async/flowDerivationAsync.ts +0 -42
- package/src/api/nodes/async/flowStateAsync.ts +0 -47
- package/src/api/nodes/async/flowWritableDerivationAsync.ts +0 -33
- package/src/api/nodes/async/index.ts +0 -4
- package/src/api/nodes/collections/flowArray.ts +0 -155
- package/src/api/nodes/collections/flowMap.ts +0 -115
- package/src/api/nodes/collections/index.ts +0 -2
- package/src/api/nodes/flowEffect.ts +0 -42
- package/src/api/nodes/flowSignal.ts +0 -28
- package/src/api/nodes/flowValue.ts +0 -37
- package/src/api/nodes/index.ts +0 -7
- package/src/api/nodes/sync/flowConstant.ts +0 -33
- package/src/api/nodes/sync/flowDerivation.ts +0 -41
- package/src/api/nodes/sync/flowState.ts +0 -45
- package/src/api/nodes/sync/flowWritableDerivation.ts +0 -31
- package/src/api/nodes/sync/index.ts +0 -4
- package/src/api/nodes/utils.ts +0 -24
- package/src/base/disposable.ts +0 -18
- package/src/base/executionStack.ts +0 -42
- package/src/base/index.ts +0 -5
- package/src/base/node.ts +0 -98
- package/src/base/observable.ts +0 -92
- package/src/base/observer.ts +0 -51
- package/src/converters/index.ts +0 -1
- package/src/converters/solid.ts +0 -109
- package/src/index.ts +0 -2
- package/src/nodes/arrayNode.ts +0 -180
- package/src/nodes/effectNode.ts +0 -58
- package/src/nodes/index.ts +0 -7
- package/src/nodes/mapNode.ts +0 -125
- package/src/nodes/signalNode.ts +0 -19
- package/src/nodes/valueAsyncNode.ts +0 -85
- package/src/nodes/valueNode.ts +0 -148
- package/src/nodes/valueSyncNode.ts +0 -125
- package/src/schedulers/asyncResolver.ts +0 -78
- package/src/schedulers/asyncScheduler.ts +0 -66
- package/src/schedulers/index.ts +0 -4
- package/src/schedulers/pendingError.ts +0 -13
- package/src/schedulers/scheduler.ts +0 -9
- package/src/schedulers/syncResolver.ts +0 -69
- package/src/schedulers/syncScheduler.ts +0 -55
- package/test/base/pendingError.test.ts +0 -67
- package/test/converters/solid.derivation.browser.test.tsx +0 -69
- package/test/converters/solid.node.test.ts +0 -654
- package/test/converters/solid.state.browser.test.tsx +0 -1592
- package/test/reactivity/flowSignal.test.ts +0 -226
- package/test/reactivity/nodes/async/asyncScheduler/asyncResolver.test.ts +0 -593
- package/test/reactivity/nodes/async/asyncScheduler/asyncScheduler.test.ts +0 -317
- package/test/reactivity/nodes/async/flowConstantAsync.test.ts +0 -652
- package/test/reactivity/nodes/async/flowDerivation.test.ts +0 -898
- package/test/reactivity/nodes/async/flowDerivationAsync.test.ts +0 -1716
- package/test/reactivity/nodes/async/flowStateAsync.test.ts +0 -708
- package/test/reactivity/nodes/async/flowWritableDerivationAsync.test.ts +0 -614
- package/test/reactivity/nodes/collections/flowArray.asyncStates.test.ts +0 -1289
- package/test/reactivity/nodes/collections/flowArray.scalars.test.ts +0 -961
- package/test/reactivity/nodes/collections/flowArray.states.test.ts +0 -1035
- package/test/reactivity/nodes/collections/flowMap.asyncStates.test.ts +0 -960
- package/test/reactivity/nodes/collections/flowMap.scalars.test.ts +0 -775
- package/test/reactivity/nodes/collections/flowMap.states.test.ts +0 -958
- package/test/reactivity/nodes/sync/flowConstant.test.ts +0 -377
- package/test/reactivity/nodes/sync/flowDerivation.test.ts +0 -896
- package/test/reactivity/nodes/sync/flowState.test.ts +0 -341
- package/test/reactivity/nodes/sync/flowWritableDerivation.test.ts +0 -603
- package/test/vitest.d.ts +0 -10
- package/tsconfig.json +0 -37
- package/typedoc.json +0 -37
- package/vite.config.ts +0 -31
- package/vitest.browser.config.ts +0 -21
- package/vitest.config.ts +0 -17
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { constant, subscribe } from "~";
|
|
3
|
-
import { EffectNode } from "~/nodes";
|
|
4
|
-
|
|
5
|
-
describe("flowConstant", () => {
|
|
6
|
-
describe("unit", () => {
|
|
7
|
-
describe("initialization / pick", () => {
|
|
8
|
-
it("should initialize with initializer function", async () => {
|
|
9
|
-
const $constant = constant(() => 1);
|
|
10
|
-
expect(await $constant.pick()).toBe(1);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("should compute initial value lazily on first access", async () => {
|
|
14
|
-
const computeFn = vi.fn(() => 42);
|
|
15
|
-
const $constant = constant(computeFn);
|
|
16
|
-
|
|
17
|
-
// Function should not be called yet
|
|
18
|
-
expect(computeFn).not.toHaveBeenCalled();
|
|
19
|
-
|
|
20
|
-
// First access triggers computation
|
|
21
|
-
const value = await $constant.pick();
|
|
22
|
-
expect(value).toBe(42);
|
|
23
|
-
expect(computeFn).toHaveBeenCalledTimes(1);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should call initializer function only once", async () => {
|
|
27
|
-
const computeFn = vi.fn(() => 100);
|
|
28
|
-
const $constant = constant(computeFn);
|
|
29
|
-
|
|
30
|
-
// Multiple accesses should only call compute once
|
|
31
|
-
await $constant.pick();
|
|
32
|
-
await $constant.pick();
|
|
33
|
-
await $constant.pick();
|
|
34
|
-
|
|
35
|
-
expect(computeFn).toHaveBeenCalledTimes(1);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should cache i value after initialization", async () => {
|
|
39
|
-
const computeFn = vi.fn(() => "cached");
|
|
40
|
-
const $constant = constant(computeFn);
|
|
41
|
-
|
|
42
|
-
const value1 = await $constant.pick();
|
|
43
|
-
const value2 = await $constant.pick();
|
|
44
|
-
const value3 = await $constant.pick();
|
|
45
|
-
|
|
46
|
-
expect(value1).toBe("cached");
|
|
47
|
-
expect(value2).toBe("cached");
|
|
48
|
-
expect(value3).toBe("cached");
|
|
49
|
-
expect(computeFn).toHaveBeenCalledTimes(1);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("should handle initializer function using closure to capture values", async () => {
|
|
53
|
-
let externalValue = 10;
|
|
54
|
-
const $constant = constant(() => {
|
|
55
|
-
// Closure captures external value at computation time
|
|
56
|
-
return externalValue * 2;
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Constant computes once with captured value
|
|
60
|
-
expect(await $constant.pick()).toBe(20);
|
|
61
|
-
|
|
62
|
-
// Changing external value should not affect constant (it's cached)
|
|
63
|
-
externalValue = 20;
|
|
64
|
-
expect(await $constant.pick()).toBe(20); // Still cached value
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("should handle number values", async () => {
|
|
68
|
-
const $constant = constant(() => 42);
|
|
69
|
-
expect(await $constant.pick()).toBe(42);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should handle string values", async () => {
|
|
73
|
-
const $constant = constant(() => "hello");
|
|
74
|
-
expect(await $constant.pick()).toBe("hello");
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("should handle object values", async () => {
|
|
78
|
-
const obj = { a: 1, b: 2 };
|
|
79
|
-
const $constant = constant(() => obj);
|
|
80
|
-
const value = await $constant.pick();
|
|
81
|
-
expect(value).toBe(obj);
|
|
82
|
-
expect(value).toEqual({ a: 1, b: 2 });
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("should handle array values", async () => {
|
|
86
|
-
const arr = [1, 2, 3];
|
|
87
|
-
const $constant = constant(() => arr);
|
|
88
|
-
const value = await $constant.pick();
|
|
89
|
-
expect(value).toBe(arr);
|
|
90
|
-
expect(value).toEqual([1, 2, 3]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("should handle undefined values", async () => {
|
|
94
|
-
const $constant = constant(() => undefined);
|
|
95
|
-
const value = await $constant.pick();
|
|
96
|
-
expect(value).toBeUndefined();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("should handle null values", async () => {
|
|
100
|
-
const $constant = constant(() => null);
|
|
101
|
-
const value = await $constant.pick();
|
|
102
|
-
expect(value).toBeNull();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe("error handling", () => {
|
|
106
|
-
it("pick should throw error when pick is called after disposal", async () => {
|
|
107
|
-
const $constant = constant(() => 1);
|
|
108
|
-
|
|
109
|
-
expect(await $constant.pick()).toBe(1);
|
|
110
|
-
|
|
111
|
-
$constant.dispose();
|
|
112
|
-
|
|
113
|
-
await expect($constant.pick()).rejects.toThrow("[PicoFlow] Primitive is disposed");
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("should throw error when subscribe is called after disposal", () => {
|
|
117
|
-
const $constant = constant(() => 1);
|
|
118
|
-
const onData = vi.fn();
|
|
119
|
-
|
|
120
|
-
$constant.dispose();
|
|
121
|
-
|
|
122
|
-
expect(() => $constant.subscribe(onData)).toThrow("[PicoFlow] Primitive is disposed");
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("should propagate error when pick is called on throwing initializer function", async () => {
|
|
126
|
-
const error = new Error("Compute error");
|
|
127
|
-
const $constant = constant(() => {
|
|
128
|
-
throw error;
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
await expect($constant.pick()).rejects.toThrow("Compute error");
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe("disposal", () => {
|
|
137
|
-
it("should have disposed property set to false initially", () => {
|
|
138
|
-
const $constant = constant(() => 1);
|
|
139
|
-
expect($constant.disposed).toBe(false);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("should have disposed property set to true after disposal", () => {
|
|
143
|
-
const $constant = constant(() => 1);
|
|
144
|
-
$constant.dispose();
|
|
145
|
-
expect($constant.disposed).toBe(true);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe("error handling", () => {
|
|
149
|
-
it("should throw error when disposed twice", () => {
|
|
150
|
-
const $constant = constant(() => 1);
|
|
151
|
-
$constant.dispose();
|
|
152
|
-
expect(() => $constant.dispose()).toThrow("[PicoFlow] Primitive is disposed");
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
describe("subscribe", () => {
|
|
158
|
-
it("should return an effect", () => {
|
|
159
|
-
const $constant = constant(() => 50);
|
|
160
|
-
const onData = vi.fn();
|
|
161
|
-
const effect = $constant.subscribe(onData);
|
|
162
|
-
|
|
163
|
-
expect(effect).toBeInstanceOf(EffectNode);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("should call onData immediately with lazy init value", async () => {
|
|
167
|
-
const $constant = constant(() => 55);
|
|
168
|
-
const onData = vi.fn();
|
|
169
|
-
|
|
170
|
-
$constant.subscribe(onData);
|
|
171
|
-
|
|
172
|
-
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
173
|
-
expect(onData).toHaveBeenLastCalledWith(55);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("should not call onData after disposal of constant", async () => {
|
|
177
|
-
const $constant = constant(() => 60);
|
|
178
|
-
const onData = vi.fn();
|
|
179
|
-
|
|
180
|
-
$constant.subscribe(onData);
|
|
181
|
-
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
182
|
-
|
|
183
|
-
$constant.dispose();
|
|
184
|
-
|
|
185
|
-
// Wait to ensure onData is not called again
|
|
186
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
187
|
-
expect(onData).toHaveBeenCalledTimes(1);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("should not call onData after disposer is called", async () => {
|
|
191
|
-
const $constant = constant(() => 65);
|
|
192
|
-
const onData = vi.fn();
|
|
193
|
-
|
|
194
|
-
const effect = $constant.subscribe(onData);
|
|
195
|
-
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
196
|
-
|
|
197
|
-
effect.dispose();
|
|
198
|
-
|
|
199
|
-
// Wait to ensure onData is not called again
|
|
200
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
201
|
-
expect(onData).toHaveBeenCalledTimes(1);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it("should support multiple subscriptions", async () => {
|
|
205
|
-
const $constant = constant(() => 70);
|
|
206
|
-
const onData1 = vi.fn();
|
|
207
|
-
const onData2 = vi.fn();
|
|
208
|
-
const onData3 = vi.fn();
|
|
209
|
-
|
|
210
|
-
$constant.subscribe(onData1);
|
|
211
|
-
$constant.subscribe(onData2);
|
|
212
|
-
$constant.subscribe(onData3);
|
|
213
|
-
|
|
214
|
-
await vi.waitFor(() => {
|
|
215
|
-
expect(onData1).toHaveBeenCalledTimes(1);
|
|
216
|
-
expect(onData2).toHaveBeenCalledTimes(1);
|
|
217
|
-
expect(onData3).toHaveBeenCalledTimes(1);
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
expect(onData1).toHaveBeenLastCalledWith(70);
|
|
221
|
-
expect(onData2).toHaveBeenLastCalledWith(70);
|
|
222
|
-
expect(onData3).toHaveBeenLastCalledWith(70);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
describe("error handling", () => {
|
|
226
|
-
it("should throw error when subscribe is called after disposal", () => {
|
|
227
|
-
const $constant = constant(() => 1);
|
|
228
|
-
const onData = vi.fn();
|
|
229
|
-
|
|
230
|
-
$constant.dispose();
|
|
231
|
-
|
|
232
|
-
expect(() => $constant.subscribe(onData)).toThrow("[PicoFlow] Primitive is disposed");
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
describe("with effect", () => {
|
|
239
|
-
describe("get", () => {
|
|
240
|
-
it("should call effect with lazy init value", async () => {
|
|
241
|
-
const $constant = constant(() => 100);
|
|
242
|
-
const onData = vi.fn();
|
|
243
|
-
|
|
244
|
-
subscribe((t) => $constant.get(t), onData);
|
|
245
|
-
|
|
246
|
-
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
247
|
-
expect(onData).toHaveBeenLastCalledWith(100);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it("should not re-execute effect when closure is mutated", async () => {
|
|
251
|
-
let capturedValue = 5;
|
|
252
|
-
const $constant = constant(() => capturedValue * 3);
|
|
253
|
-
|
|
254
|
-
const onData = vi.fn();
|
|
255
|
-
subscribe((t) => $constant.get(t), onData);
|
|
256
|
-
|
|
257
|
-
// Initial execution with computed value (5 * 3 = 15)
|
|
258
|
-
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
259
|
-
expect(onData).toHaveBeenLastCalledWith(15);
|
|
260
|
-
|
|
261
|
-
// Change captured value - constant is cached, so effect should not re-run
|
|
262
|
-
capturedValue = 10;
|
|
263
|
-
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
264
|
-
expect(onData).toHaveBeenLastCalledWith(15);
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it("should support multiple effects depending on same constant", async () => {
|
|
268
|
-
const $constant = constant(() => 300);
|
|
269
|
-
const onData1 = vi.fn();
|
|
270
|
-
const onData2 = vi.fn();
|
|
271
|
-
const onData3 = vi.fn();
|
|
272
|
-
|
|
273
|
-
subscribe((t) => $constant.get(t), onData1);
|
|
274
|
-
subscribe((t) => $constant.get(t), onData2);
|
|
275
|
-
subscribe((t) => $constant.get(t), onData3);
|
|
276
|
-
|
|
277
|
-
await vi.waitFor(() => {
|
|
278
|
-
expect(onData1).toHaveBeenCalledTimes(1);
|
|
279
|
-
expect(onData2).toHaveBeenCalledTimes(1);
|
|
280
|
-
expect(onData3).toHaveBeenCalledTimes(1);
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
expect(onData1).toHaveBeenLastCalledWith(300);
|
|
284
|
-
expect(onData2).toHaveBeenLastCalledWith(300);
|
|
285
|
-
expect(onData3).toHaveBeenLastCalledWith(300);
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
describe("watch", () => {
|
|
290
|
-
it("should register dependency when watch is used in effect", async () => {
|
|
291
|
-
const $constant = constant(() => 400);
|
|
292
|
-
const onData = vi.fn();
|
|
293
|
-
|
|
294
|
-
subscribe((t) => $constant.watch(t), onData);
|
|
295
|
-
|
|
296
|
-
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
describe("disposal", () => {
|
|
301
|
-
it("should not dispose effects when constant is disposed", async () => {
|
|
302
|
-
const $constant = constant(() => 1000);
|
|
303
|
-
const onData = vi.fn();
|
|
304
|
-
const $effect = subscribe((t) => $constant.get(t), onData);
|
|
305
|
-
|
|
306
|
-
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
307
|
-
expect($effect.disposed).toBe(false);
|
|
308
|
-
|
|
309
|
-
$constant.dispose();
|
|
310
|
-
|
|
311
|
-
expect($effect.disposed).toBe(false);
|
|
312
|
-
expect($constant.disposed).toBe(true);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it("should unregister effects when constant is disposed", async () => {
|
|
316
|
-
const $constant = constant(() => 1100);
|
|
317
|
-
const onData = vi.fn();
|
|
318
|
-
const $effect = subscribe((t) => $constant.get(t), onData);
|
|
319
|
-
|
|
320
|
-
await vi.waitFor(() => expect(onData).toHaveBeenCalledTimes(1));
|
|
321
|
-
|
|
322
|
-
$constant.dispose();
|
|
323
|
-
|
|
324
|
-
// Effect should still be active but not notified
|
|
325
|
-
expect($effect.disposed).toBe(false);
|
|
326
|
-
|
|
327
|
-
// But constant is disposed so operations should fail
|
|
328
|
-
await expect($constant.pick()).rejects.toThrow("[PicoFlow] Primitive is disposed");
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
describe("error handling", () => {
|
|
333
|
-
describe("compute function errors", () => {
|
|
334
|
-
it("should propagate error when used inside an effect", async () => {
|
|
335
|
-
const error = new Error("Effect compute error");
|
|
336
|
-
const $constant = constant(() => {
|
|
337
|
-
throw error;
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
const onData = vi.fn();
|
|
341
|
-
const onError = vi.fn();
|
|
342
|
-
subscribe((t) => $constant.get(t), onData, onError);
|
|
343
|
-
|
|
344
|
-
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(1));
|
|
345
|
-
expect(onError).toHaveBeenLastCalledWith(error);
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
describe("disposed constant", () => {
|
|
350
|
-
it("should throw error when watching a disposed constant", async () => {
|
|
351
|
-
const $constant = constant(() => 1);
|
|
352
|
-
const onData = vi.fn();
|
|
353
|
-
const onError = vi.fn();
|
|
354
|
-
|
|
355
|
-
$constant.dispose();
|
|
356
|
-
|
|
357
|
-
subscribe((t) => $constant.watch(t), onData, onError);
|
|
358
|
-
|
|
359
|
-
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(1));
|
|
360
|
-
expect(onError).toHaveBeenLastCalledWith(expect.any(Error));
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
it("should throw error when getting a disposed constant", async () => {
|
|
364
|
-
const $constant = constant(() => 1);
|
|
365
|
-
const onData = vi.fn();
|
|
366
|
-
const onError = vi.fn();
|
|
367
|
-
$constant.dispose();
|
|
368
|
-
|
|
369
|
-
subscribe((t) => $constant.get(t), onData, onError);
|
|
370
|
-
|
|
371
|
-
await vi.waitFor(() => expect(onError).toHaveBeenCalledTimes(1));
|
|
372
|
-
expect(onError).toHaveBeenLastCalledWith(expect.any(Error));
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
});
|