@ersbeth/picoflow 0.2.4 → 1.0.1
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/.cursor/plans/update-js-e795d61b.plan.md +567 -0
- package/.gitlab-ci.yml +24 -0
- package/.vscode/settings.json +3 -3
- package/CHANGELOG.md +51 -0
- package/IMPLEMENTATION_GUIDE.md +1578 -0
- package/README.md +9 -134
- package/biome.json +32 -32
- package/dist/picoflow.js +610 -436
- package/dist/types/advanced/array.d.ts +0 -6
- package/dist/types/advanced/array.d.ts.map +1 -1
- package/dist/types/advanced/index.d.ts +5 -5
- package/dist/types/advanced/index.d.ts.map +1 -1
- package/dist/types/advanced/map.d.ts +114 -23
- package/dist/types/advanced/map.d.ts.map +1 -1
- package/dist/types/advanced/resource.d.ts +51 -12
- package/dist/types/advanced/resource.d.ts.map +1 -1
- package/dist/types/advanced/resourceAsync.d.ts +28 -13
- package/dist/types/advanced/resourceAsync.d.ts.map +1 -1
- package/dist/types/advanced/stream.d.ts +74 -16
- package/dist/types/advanced/stream.d.ts.map +1 -1
- package/dist/types/advanced/streamAsync.d.ts +69 -15
- package/dist/types/advanced/streamAsync.d.ts.map +1 -1
- package/dist/types/basic/constant.d.ts +44 -16
- package/dist/types/basic/constant.d.ts.map +1 -1
- package/dist/types/basic/derivation.d.ts +73 -24
- package/dist/types/basic/derivation.d.ts.map +1 -1
- package/dist/types/basic/disposable.d.ts +65 -6
- package/dist/types/basic/disposable.d.ts.map +1 -1
- package/dist/types/basic/effect.d.ts +27 -16
- package/dist/types/basic/effect.d.ts.map +1 -1
- package/dist/types/basic/index.d.ts +7 -8
- package/dist/types/basic/index.d.ts.map +1 -1
- package/dist/types/basic/observable.d.ts +62 -13
- package/dist/types/basic/observable.d.ts.map +1 -1
- package/dist/types/basic/signal.d.ts +35 -6
- package/dist/types/basic/signal.d.ts.map +1 -1
- package/dist/types/basic/state.d.ts +25 -4
- package/dist/types/basic/state.d.ts.map +1 -1
- package/dist/types/basic/trackingContext.d.ts +33 -0
- package/dist/types/basic/trackingContext.d.ts.map +1 -0
- package/dist/types/creators.d.ts +271 -26
- package/dist/types/creators.d.ts.map +1 -1
- package/dist/types/index.d.ts +60 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/solid/converters.d.ts +5 -5
- package/dist/types/solid/converters.d.ts.map +1 -1
- package/dist/types/solid/index.d.ts +2 -2
- package/dist/types/solid/index.d.ts.map +1 -1
- package/dist/types/solid/primitives.d.ts +96 -4
- package/dist/types/solid/primitives.d.ts.map +1 -1
- package/docs/.vitepress/config.mts +110 -0
- package/docs/api/classes/FlowArray.md +489 -0
- package/docs/api/classes/FlowConstant.md +350 -0
- package/docs/api/classes/FlowDerivation.md +334 -0
- package/docs/api/classes/FlowEffect.md +100 -0
- package/docs/api/classes/FlowMap.md +512 -0
- package/docs/api/classes/FlowObservable.md +306 -0
- package/docs/api/classes/FlowResource.md +380 -0
- package/docs/api/classes/FlowResourceAsync.md +362 -0
- package/docs/api/classes/FlowSignal.md +160 -0
- package/docs/api/classes/FlowState.md +368 -0
- package/docs/api/classes/FlowStream.md +367 -0
- package/docs/api/classes/FlowStreamAsync.md +364 -0
- package/docs/api/classes/SolidDerivation.md +75 -0
- package/docs/api/classes/SolidResource.md +91 -0
- package/docs/api/classes/SolidState.md +71 -0
- package/docs/api/classes/TrackingContext.md +33 -0
- package/docs/api/functions/array.md +58 -0
- package/docs/api/functions/constant.md +45 -0
- package/docs/api/functions/derivation.md +53 -0
- package/docs/api/functions/effect.md +49 -0
- package/docs/api/functions/from.md +220 -0
- package/docs/api/functions/isDisposable.md +49 -0
- package/docs/api/functions/map.md +57 -0
- package/docs/api/functions/resource.md +52 -0
- package/docs/api/functions/resourceAsync.md +50 -0
- package/docs/api/functions/signal.md +36 -0
- package/docs/api/functions/state.md +47 -0
- package/docs/api/functions/stream.md +53 -0
- package/docs/api/functions/streamAsync.md +50 -0
- package/docs/api/index.md +118 -0
- package/docs/api/interfaces/FlowDisposable.md +65 -0
- package/docs/api/interfaces/SolidObservable.md +19 -0
- package/docs/api/type-aliases/FlowArrayAction.md +49 -0
- package/docs/api/type-aliases/FlowStreamDisposer.md +15 -0
- package/docs/api/type-aliases/FlowStreamSetter.md +27 -0
- package/docs/api/type-aliases/FlowStreamUpdater.md +32 -0
- package/docs/api/type-aliases/NotPromise.md +18 -0
- package/docs/api/type-aliases/SolidGetter.md +17 -0
- package/docs/api/typedoc-sidebar.json +1 -0
- package/docs/examples/examples.md +2313 -0
- package/docs/examples/patterns.md +649 -0
- package/docs/guide/advanced/disposal.md +426 -0
- package/docs/guide/advanced/solidjs.md +221 -0
- package/docs/guide/advanced/upgrading.md +464 -0
- package/docs/guide/introduction/concepts.md +56 -0
- package/docs/guide/introduction/conventions.md +61 -0
- package/docs/guide/introduction/getting-started.md +134 -0
- package/docs/guide/introduction/lifecycle.md +371 -0
- package/docs/guide/primitives/array.md +400 -0
- package/docs/guide/primitives/constant.md +380 -0
- package/docs/guide/primitives/derivations.md +348 -0
- package/docs/guide/primitives/effects.md +458 -0
- package/docs/guide/primitives/map.md +387 -0
- package/docs/guide/primitives/overview.md +175 -0
- package/docs/guide/primitives/resources.md +858 -0
- package/docs/guide/primitives/signal.md +259 -0
- package/docs/guide/primitives/state.md +368 -0
- package/docs/guide/primitives/streams.md +931 -0
- package/docs/index.md +47 -0
- package/docs/public/logo.svg +1 -0
- package/package.json +57 -41
- package/src/advanced/array.ts +208 -210
- package/src/advanced/index.ts +7 -7
- package/src/advanced/map.ts +178 -68
- package/src/advanced/resource.ts +87 -43
- package/src/advanced/resourceAsync.ts +62 -42
- package/src/advanced/stream.ts +113 -50
- package/src/advanced/streamAsync.ts +120 -61
- package/src/basic/constant.ts +82 -49
- package/src/basic/derivation.ts +128 -84
- package/src/basic/disposable.ts +74 -15
- package/src/basic/effect.ts +85 -77
- package/src/basic/index.ts +7 -8
- package/src/basic/observable.ts +94 -36
- package/src/basic/signal.ts +133 -105
- package/src/basic/state.ts +46 -25
- package/src/basic/trackingContext.ts +45 -0
- package/src/creators.ts +297 -54
- package/src/index.ts +96 -43
- package/src/solid/converters.ts +186 -67
- package/src/solid/index.ts +8 -2
- package/src/solid/primitives.ts +167 -65
- package/test/array.test.ts +592 -612
- package/test/constant.test.ts +31 -33
- package/test/derivation.test.ts +531 -536
- package/test/effect.test.ts +21 -21
- package/test/map.test.ts +233 -137
- package/test/resource.test.ts +119 -121
- package/test/resourceAsync.test.ts +98 -100
- package/test/signal.test.ts +51 -55
- package/test/state.test.ts +186 -168
- package/test/stream.test.ts +189 -189
- package/test/streamAsync.test.ts +186 -186
- package/tsconfig.json +19 -18
- package/typedoc.json +37 -0
- package/vite.config.ts +23 -23
- package/vitest.config.ts +7 -7
- package/api/doc/index.md +0 -31
- package/api/doc/picoflow.array.md +0 -55
- package/api/doc/picoflow.constant.md +0 -55
- package/api/doc/picoflow.derivation.md +0 -55
- package/api/doc/picoflow.effect.md +0 -55
- package/api/doc/picoflow.flowarray._constructor_.md +0 -49
- package/api/doc/picoflow.flowarray._lastaction.md +0 -13
- package/api/doc/picoflow.flowarray.clear.md +0 -17
- package/api/doc/picoflow.flowarray.dispose.md +0 -55
- package/api/doc/picoflow.flowarray.get.md +0 -19
- package/api/doc/picoflow.flowarray.length.md +0 -13
- package/api/doc/picoflow.flowarray.md +0 -273
- package/api/doc/picoflow.flowarray.pop.md +0 -17
- package/api/doc/picoflow.flowarray.push.md +0 -53
- package/api/doc/picoflow.flowarray.set.md +0 -53
- package/api/doc/picoflow.flowarray.setitem.md +0 -69
- package/api/doc/picoflow.flowarray.shift.md +0 -17
- package/api/doc/picoflow.flowarray.splice.md +0 -85
- package/api/doc/picoflow.flowarray.unshift.md +0 -53
- package/api/doc/picoflow.flowarrayaction.md +0 -37
- package/api/doc/picoflow.flowconstant._constructor_.md +0 -49
- package/api/doc/picoflow.flowconstant.get.md +0 -25
- package/api/doc/picoflow.flowconstant.md +0 -88
- package/api/doc/picoflow.flowderivation._constructor_.md +0 -49
- package/api/doc/picoflow.flowderivation.get.md +0 -23
- package/api/doc/picoflow.flowderivation.md +0 -86
- package/api/doc/picoflow.flowdisposable.dispose.md +0 -55
- package/api/doc/picoflow.flowdisposable.md +0 -43
- package/api/doc/picoflow.floweffect._constructor_.md +0 -54
- package/api/doc/picoflow.floweffect.dispose.md +0 -21
- package/api/doc/picoflow.floweffect.disposed.md +0 -13
- package/api/doc/picoflow.floweffect.md +0 -131
- package/api/doc/picoflow.flowgetter.md +0 -15
- package/api/doc/picoflow.flowmap._lastdeleted.md +0 -21
- package/api/doc/picoflow.flowmap._lastset.md +0 -21
- package/api/doc/picoflow.flowmap.delete.md +0 -61
- package/api/doc/picoflow.flowmap.md +0 -133
- package/api/doc/picoflow.flowmap.setat.md +0 -77
- package/api/doc/picoflow.flowobservable.get.md +0 -19
- package/api/doc/picoflow.flowobservable.md +0 -68
- package/api/doc/picoflow.flowobservable.subscribe.md +0 -55
- package/api/doc/picoflow.flowresource._constructor_.md +0 -49
- package/api/doc/picoflow.flowresource.fetch.md +0 -27
- package/api/doc/picoflow.flowresource.get.md +0 -23
- package/api/doc/picoflow.flowresource.md +0 -100
- package/api/doc/picoflow.flowresourceasync._constructor_.md +0 -49
- package/api/doc/picoflow.flowresourceasync.fetch.md +0 -27
- package/api/doc/picoflow.flowresourceasync.get.md +0 -23
- package/api/doc/picoflow.flowresourceasync.md +0 -100
- package/api/doc/picoflow.flowsignal.dispose.md +0 -59
- package/api/doc/picoflow.flowsignal.disposed.md +0 -18
- package/api/doc/picoflow.flowsignal.md +0 -112
- package/api/doc/picoflow.flowsignal.trigger.md +0 -21
- package/api/doc/picoflow.flowstate.md +0 -52
- package/api/doc/picoflow.flowstate.set.md +0 -61
- package/api/doc/picoflow.flowstream._constructor_.md +0 -49
- package/api/doc/picoflow.flowstream.dispose.md +0 -21
- package/api/doc/picoflow.flowstream.get.md +0 -23
- package/api/doc/picoflow.flowstream.md +0 -100
- package/api/doc/picoflow.flowstreamasync._constructor_.md +0 -54
- package/api/doc/picoflow.flowstreamasync.dispose.md +0 -21
- package/api/doc/picoflow.flowstreamasync.get.md +0 -23
- package/api/doc/picoflow.flowstreamasync.md +0 -100
- package/api/doc/picoflow.flowstreamdisposer.md +0 -13
- package/api/doc/picoflow.flowstreamsetter.md +0 -13
- package/api/doc/picoflow.flowstreamupdater.md +0 -19
- package/api/doc/picoflow.flowwatcher.md +0 -15
- package/api/doc/picoflow.from.md +0 -55
- package/api/doc/picoflow.from_1.md +0 -55
- package/api/doc/picoflow.from_2.md +0 -55
- package/api/doc/picoflow.from_3.md +0 -55
- package/api/doc/picoflow.from_4.md +0 -55
- package/api/doc/picoflow.from_5.md +0 -55
- package/api/doc/picoflow.isdisposable.md +0 -55
- package/api/doc/picoflow.map.md +0 -59
- package/api/doc/picoflow.md +0 -544
- package/api/doc/picoflow.resource.md +0 -55
- package/api/doc/picoflow.resourceasync.md +0 -55
- package/api/doc/picoflow.signal.md +0 -19
- package/api/doc/picoflow.solidderivation._constructor_.md +0 -49
- package/api/doc/picoflow.solidderivation.get.md +0 -13
- package/api/doc/picoflow.solidderivation.md +0 -94
- package/api/doc/picoflow.solidgetter.md +0 -13
- package/api/doc/picoflow.solidobservable.get.md +0 -13
- package/api/doc/picoflow.solidobservable.md +0 -57
- package/api/doc/picoflow.solidresource._constructor_.md +0 -49
- package/api/doc/picoflow.solidresource.get.md +0 -13
- package/api/doc/picoflow.solidresource.latest.md +0 -13
- package/api/doc/picoflow.solidresource.md +0 -157
- package/api/doc/picoflow.solidresource.refetch.md +0 -13
- package/api/doc/picoflow.solidresource.state.md +0 -13
- package/api/doc/picoflow.solidstate._constructor_.md +0 -49
- package/api/doc/picoflow.solidstate.get.md +0 -13
- package/api/doc/picoflow.solidstate.md +0 -115
- package/api/doc/picoflow.solidstate.set.md +0 -13
- package/api/doc/picoflow.state.md +0 -55
- package/api/doc/picoflow.stream.md +0 -55
- package/api/doc/picoflow.streamasync.md +0 -55
- package/api/picoflow.public.api.md +0 -244
- package/api-extractor.json +0 -61
package/test/array.test.ts
CHANGED
|
@@ -1,620 +1,600 @@
|
|
|
1
1
|
import { describe, expect, test, vi } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import { array, effect, type FlowState, state } from "#package";
|
|
3
3
|
|
|
4
4
|
describe("array", () => {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
test("is initialized", () => {
|
|
6
|
+
const $array = array([state(1), state(2), state(3)]);
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const $array = array([state(1), state(2), state(3)]);
|
|
204
|
-
$array.dispose();
|
|
205
|
-
expect(() => $array.shift()).toThrowError(
|
|
206
|
-
"[PicoFlow] Primitive is disposed",
|
|
207
|
-
);
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
test("throws when disposed (splice)", () => {
|
|
211
|
-
const $array = array<FlowState<number>>([
|
|
212
|
-
state(0),
|
|
213
|
-
state(1),
|
|
214
|
-
state(2),
|
|
215
|
-
state(3),
|
|
216
|
-
state(4),
|
|
217
|
-
]);
|
|
218
|
-
$array.dispose();
|
|
219
|
-
expect(() => $array.splice(1, 2)).toThrowError(
|
|
220
|
-
"[PicoFlow] Primitive is disposed",
|
|
221
|
-
);
|
|
222
|
-
});
|
|
8
|
+
expect($array.pick().map((state) => state.pick())).toEqual([1, 2, 3]);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("is updated (set)", () => {
|
|
12
|
+
const $array = array<FlowState<number>>([state(0), state(1), state(2)]);
|
|
13
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0, 1, 2]);
|
|
14
|
+
|
|
15
|
+
$array.set([state(1), state(2), state(3)]);
|
|
16
|
+
expect($array.pick().map((state) => state.pick())).toEqual([1, 2, 3]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("is updated (setItem)", () => {
|
|
20
|
+
const $array = array<FlowState<number>>([state(0), state(1), state(2)]);
|
|
21
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0, 1, 2]);
|
|
22
|
+
|
|
23
|
+
$array.setItem(0, state(1));
|
|
24
|
+
expect($array.pick().map((state) => state.pick())).toEqual([1, 1, 2]);
|
|
25
|
+
|
|
26
|
+
$array.setItem(1, state(2));
|
|
27
|
+
expect($array.pick().map((state) => state.pick())).toEqual([1, 2, 2]);
|
|
28
|
+
|
|
29
|
+
$array.setItem(2, state(3));
|
|
30
|
+
expect($array.pick().map((state) => state.pick())).toEqual([1, 2, 3]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("is updated (push/pop)", () => {
|
|
34
|
+
const $array = array<FlowState<number>>();
|
|
35
|
+
expect($array.pick()).toEqual([]);
|
|
36
|
+
|
|
37
|
+
$array.push(state(0));
|
|
38
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0]);
|
|
39
|
+
|
|
40
|
+
$array.push(state(1));
|
|
41
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0, 1]);
|
|
42
|
+
|
|
43
|
+
$array.push(state(2));
|
|
44
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0, 1, 2]);
|
|
45
|
+
|
|
46
|
+
$array.pop();
|
|
47
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0, 1]);
|
|
48
|
+
|
|
49
|
+
$array.pop();
|
|
50
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0]);
|
|
51
|
+
|
|
52
|
+
$array.pop();
|
|
53
|
+
expect($array.pick().map((state) => state.pick())).toEqual([]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("is updated (unshift/shift)", () => {
|
|
57
|
+
const $array = array<FlowState<number>>();
|
|
58
|
+
expect($array.pick()).toEqual([]);
|
|
59
|
+
|
|
60
|
+
$array.unshift(state(0));
|
|
61
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0]);
|
|
62
|
+
|
|
63
|
+
$array.unshift(state(1));
|
|
64
|
+
expect($array.pick().map((state) => state.pick())).toEqual([1, 0]);
|
|
65
|
+
|
|
66
|
+
$array.unshift(state(2));
|
|
67
|
+
expect($array.pick().map((state) => state.pick())).toEqual([2, 1, 0]);
|
|
68
|
+
|
|
69
|
+
$array.shift();
|
|
70
|
+
expect($array.pick().map((state) => state.pick())).toEqual([1, 0]);
|
|
71
|
+
|
|
72
|
+
$array.shift();
|
|
73
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0]);
|
|
74
|
+
|
|
75
|
+
$array.shift();
|
|
76
|
+
expect($array.pick().map((state) => state.pick())).toEqual([]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("is updated (splice)", () => {
|
|
80
|
+
const $array = array<FlowState<number>>([
|
|
81
|
+
state(0),
|
|
82
|
+
state(1),
|
|
83
|
+
state(2),
|
|
84
|
+
state(3),
|
|
85
|
+
state(4),
|
|
86
|
+
]);
|
|
87
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0, 1, 2, 3, 4]);
|
|
88
|
+
|
|
89
|
+
$array.splice(1, 2);
|
|
90
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0, 3, 4]);
|
|
91
|
+
|
|
92
|
+
$array.splice(1, 0, state(1), state(2));
|
|
93
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0, 1, 2, 3, 4]);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("is updated (clear)", () => {
|
|
97
|
+
const $array = array<FlowState<number>>([
|
|
98
|
+
state(0),
|
|
99
|
+
state(1),
|
|
100
|
+
state(2),
|
|
101
|
+
state(3),
|
|
102
|
+
state(4),
|
|
103
|
+
]);
|
|
104
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0, 1, 2, 3, 4]);
|
|
105
|
+
|
|
106
|
+
$array.clear();
|
|
107
|
+
expect($array.pick().map((state) => state.pick())).toEqual([]);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("is item updated", () => {
|
|
111
|
+
const $array = array<FlowState<number>>([
|
|
112
|
+
state(0),
|
|
113
|
+
state(1),
|
|
114
|
+
state(2),
|
|
115
|
+
state(3),
|
|
116
|
+
state(4),
|
|
117
|
+
]);
|
|
118
|
+
expect($array.pick().map((state) => state.pick())).toEqual([0, 1, 2, 3, 4]);
|
|
119
|
+
|
|
120
|
+
$array.pick()[0].set(1);
|
|
121
|
+
expect($array.pick().map((state) => state.pick())).toEqual([1, 1, 2, 3, 4]);
|
|
122
|
+
|
|
123
|
+
$array.pick()[1].set(2);
|
|
124
|
+
expect($array.pick().map((state) => state.pick())).toEqual([1, 2, 2, 3, 4]);
|
|
125
|
+
|
|
126
|
+
$array.pick()[2].set(3);
|
|
127
|
+
expect($array.pick().map((state) => state.pick())).toEqual([1, 2, 3, 3, 4]);
|
|
128
|
+
|
|
129
|
+
$array.pick()[3].set(4);
|
|
130
|
+
expect($array.pick().map((state) => state.pick())).toEqual([1, 2, 3, 4, 4]);
|
|
131
|
+
|
|
132
|
+
$array.pick()[4].set(5);
|
|
133
|
+
expect($array.pick().map((state) => state.pick())).toEqual([1, 2, 3, 4, 5]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("throws when disposed (get)", () => {
|
|
137
|
+
const $array = array([state(1), state(2), state(3)]);
|
|
138
|
+
$array.dispose();
|
|
139
|
+
expect(() => $array.pick()).toThrowError(
|
|
140
|
+
"[PicoFlow] Primitive is disposed",
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("throws when disposed (set)", () => {
|
|
145
|
+
const $array = array([state(1), state(2), state(3)]);
|
|
146
|
+
$array.dispose();
|
|
147
|
+
expect(() => $array.set([state(1)])).toThrowError(
|
|
148
|
+
"[PicoFlow] Primitive is disposed",
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("throws when disposed (setItem)", () => {
|
|
153
|
+
const $array = array([state(1), state(2), state(3)]);
|
|
154
|
+
$array.dispose();
|
|
155
|
+
expect(() => $array.setItem(0, state(3))).toThrowError(
|
|
156
|
+
"[PicoFlow] Primitive is disposed",
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("throws when disposed (push)", () => {
|
|
161
|
+
const $array = array([state(1), state(2), state(3)]);
|
|
162
|
+
$array.dispose();
|
|
163
|
+
expect(() => $array.push(state(3))).toThrowError(
|
|
164
|
+
"[PicoFlow] Primitive is disposed",
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("throws when disposed (pop)", () => {
|
|
169
|
+
const $array = array([state(1), state(2), state(3)]);
|
|
170
|
+
$array.dispose();
|
|
171
|
+
expect(() => $array.pop()).toThrowError("[PicoFlow] Primitive is disposed");
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("throws when disposed (unshift)", () => {
|
|
175
|
+
const $array = array([state(1), state(2), state(3)]);
|
|
176
|
+
$array.dispose();
|
|
177
|
+
expect(() => $array.unshift(state(3))).toThrowError(
|
|
178
|
+
"[PicoFlow] Primitive is disposed",
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("throws when disposed (shift)", () => {
|
|
183
|
+
const $array = array([state(1), state(2), state(3)]);
|
|
184
|
+
$array.dispose();
|
|
185
|
+
expect(() => $array.shift()).toThrowError(
|
|
186
|
+
"[PicoFlow] Primitive is disposed",
|
|
187
|
+
);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("throws when disposed (splice)", () => {
|
|
191
|
+
const $array = array<FlowState<number>>([
|
|
192
|
+
state(0),
|
|
193
|
+
state(1),
|
|
194
|
+
state(2),
|
|
195
|
+
state(3),
|
|
196
|
+
state(4),
|
|
197
|
+
]);
|
|
198
|
+
$array.dispose();
|
|
199
|
+
expect(() => $array.splice(1, 2)).toThrowError(
|
|
200
|
+
"[PicoFlow] Primitive is disposed",
|
|
201
|
+
);
|
|
202
|
+
});
|
|
223
203
|
});
|
|
224
204
|
|
|
225
205
|
describe("effect", () => {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
206
|
+
test("called when initialized", () => {
|
|
207
|
+
const $array = array([state(1), state(2), state(3)]);
|
|
208
|
+
const effectFn = vi.fn();
|
|
209
|
+
effect((t) => effectFn($array.get(t).map((state) => state.get(t))));
|
|
210
|
+
|
|
211
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
212
|
+
expect(effectFn).toHaveBeenLastCalledWith([1, 2, 3]);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("called when updated (set)", () => {
|
|
216
|
+
const $array = array<FlowState<number>>([state(0), state(1), state(2)]);
|
|
217
|
+
const effectFn = vi.fn();
|
|
218
|
+
effect((t) => effectFn($array.get(t).map((state) => state.get(t))));
|
|
219
|
+
|
|
220
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
221
|
+
expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2]);
|
|
222
|
+
|
|
223
|
+
$array.set([state(1), state(2), state(3)]);
|
|
224
|
+
expect(effectFn).toHaveBeenLastCalledWith([1, 2, 3]);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("called when updated (push/pop)", () => {
|
|
228
|
+
const $array = array<FlowState<number>>();
|
|
229
|
+
const effectFn = vi.fn();
|
|
230
|
+
effect((t) => effectFn($array.get(t).map((state) => state.get(t))));
|
|
231
|
+
|
|
232
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
233
|
+
expect(effectFn).toHaveBeenLastCalledWith([]);
|
|
234
|
+
|
|
235
|
+
$array.push(state(0));
|
|
236
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
237
|
+
expect(effectFn).toHaveBeenLastCalledWith([0]);
|
|
238
|
+
|
|
239
|
+
$array.push(state(1));
|
|
240
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
241
|
+
expect(effectFn).toHaveBeenLastCalledWith([0, 1]);
|
|
242
|
+
|
|
243
|
+
$array.push(state(2));
|
|
244
|
+
expect(effectFn).toHaveBeenCalledTimes(4);
|
|
245
|
+
expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2]);
|
|
246
|
+
|
|
247
|
+
$array.pop();
|
|
248
|
+
expect(effectFn).toHaveBeenCalledTimes(5);
|
|
249
|
+
expect(effectFn).toHaveBeenLastCalledWith([0, 1]);
|
|
250
|
+
|
|
251
|
+
$array.pop();
|
|
252
|
+
expect(effectFn).toHaveBeenCalledTimes(6);
|
|
253
|
+
expect(effectFn).toHaveBeenLastCalledWith([0]);
|
|
254
|
+
|
|
255
|
+
$array.pop();
|
|
256
|
+
expect(effectFn).toHaveBeenCalledTimes(7);
|
|
257
|
+
expect(effectFn).toHaveBeenLastCalledWith([]);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test("called when updated (unshift/shift)", () => {
|
|
261
|
+
const $array = array<FlowState<number>>();
|
|
262
|
+
const effectFn = vi.fn();
|
|
263
|
+
effect((t) => effectFn($array.get(t).map((state) => state.get(t))));
|
|
264
|
+
|
|
265
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
266
|
+
expect(effectFn).toHaveBeenLastCalledWith([]);
|
|
267
|
+
|
|
268
|
+
$array.unshift(state(0));
|
|
269
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
270
|
+
expect(effectFn).toHaveBeenLastCalledWith([0]);
|
|
271
|
+
|
|
272
|
+
$array.unshift(state(1));
|
|
273
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
274
|
+
expect(effectFn).toHaveBeenLastCalledWith([1, 0]);
|
|
275
|
+
|
|
276
|
+
$array.unshift(state(2));
|
|
277
|
+
expect(effectFn).toHaveBeenCalledTimes(4);
|
|
278
|
+
expect(effectFn).toHaveBeenLastCalledWith([2, 1, 0]);
|
|
279
|
+
|
|
280
|
+
$array.shift();
|
|
281
|
+
expect(effectFn).toHaveBeenCalledTimes(5);
|
|
282
|
+
expect(effectFn).toHaveBeenLastCalledWith([1, 0]);
|
|
283
|
+
|
|
284
|
+
$array.shift();
|
|
285
|
+
expect(effectFn).toHaveBeenCalledTimes(6);
|
|
286
|
+
expect(effectFn).toHaveBeenLastCalledWith([0]);
|
|
287
|
+
|
|
288
|
+
$array.shift();
|
|
289
|
+
expect(effectFn).toHaveBeenCalledTimes(7);
|
|
290
|
+
expect(effectFn).toHaveBeenLastCalledWith([]);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test("called when updated (splice)", () => {
|
|
294
|
+
const $array = array<FlowState<number>>([
|
|
295
|
+
state(0),
|
|
296
|
+
state(1),
|
|
297
|
+
state(2),
|
|
298
|
+
state(3),
|
|
299
|
+
state(4),
|
|
300
|
+
]);
|
|
301
|
+
const effectFn = vi.fn();
|
|
302
|
+
effect((t) => effectFn($array.get(t).map((state) => state.get(t))));
|
|
303
|
+
|
|
304
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
305
|
+
expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2, 3, 4]);
|
|
306
|
+
|
|
307
|
+
$array.splice(1, 2);
|
|
308
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
309
|
+
expect(effectFn).toHaveBeenLastCalledWith([0, 3, 4]);
|
|
310
|
+
|
|
311
|
+
$array.splice(1, 0, state(1), state(2));
|
|
312
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
313
|
+
expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2, 3, 4]);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test("called when updated (clear)", () => {
|
|
317
|
+
const $array = array<FlowState<number>>([
|
|
318
|
+
state(0),
|
|
319
|
+
state(1),
|
|
320
|
+
state(2),
|
|
321
|
+
state(3),
|
|
322
|
+
state(4),
|
|
323
|
+
]);
|
|
324
|
+
const effectFn = vi.fn();
|
|
325
|
+
effect((t) => effectFn($array.get(t).map((state) => state.get(t))));
|
|
326
|
+
|
|
327
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
328
|
+
expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2, 3, 4]);
|
|
329
|
+
|
|
330
|
+
$array.clear();
|
|
331
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
332
|
+
expect(effectFn).toHaveBeenLastCalledWith([]);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
test("called when item updated", () => {
|
|
336
|
+
const $array = array<FlowState<number>>([state(0), state(1), state(2)]);
|
|
337
|
+
const effectFn = vi.fn();
|
|
338
|
+
const effect0Fn = vi.fn();
|
|
339
|
+
const effect1Fn = vi.fn();
|
|
340
|
+
const effect2Fn = vi.fn();
|
|
341
|
+
|
|
342
|
+
effect((t) => effectFn($array.get(t).map((state) => state.get(t))));
|
|
343
|
+
effect((t) => effect0Fn($array.get(t)[0].get(t)));
|
|
344
|
+
effect((t) => effect1Fn($array.get(t)[1].get(t)));
|
|
345
|
+
effect((t) => effect2Fn($array.get(t)[2].get(t)));
|
|
346
|
+
|
|
347
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
348
|
+
expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2]);
|
|
349
|
+
expect(effect0Fn).toHaveBeenCalledTimes(1);
|
|
350
|
+
expect(effect0Fn).toHaveBeenLastCalledWith(0);
|
|
351
|
+
expect(effect1Fn).toHaveBeenCalledTimes(1);
|
|
352
|
+
expect(effect1Fn).toHaveBeenLastCalledWith(1);
|
|
353
|
+
expect(effect2Fn).toHaveBeenCalledTimes(1);
|
|
354
|
+
expect(effect2Fn).toHaveBeenLastCalledWith(2);
|
|
355
|
+
|
|
356
|
+
$array.pick()[0].set(1);
|
|
357
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
358
|
+
expect(effectFn).toHaveBeenLastCalledWith([1, 1, 2]);
|
|
359
|
+
expect(effect0Fn).toHaveBeenCalledTimes(2);
|
|
360
|
+
expect(effect0Fn).toHaveBeenLastCalledWith(1);
|
|
361
|
+
expect(effect1Fn).toHaveBeenCalledTimes(1);
|
|
362
|
+
expect(effect1Fn).toHaveBeenLastCalledWith(1);
|
|
363
|
+
expect(effect2Fn).toHaveBeenCalledTimes(1);
|
|
364
|
+
expect(effect2Fn).toHaveBeenLastCalledWith(2);
|
|
365
|
+
|
|
366
|
+
$array.pick()[1].set(2);
|
|
367
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
368
|
+
expect(effectFn).toHaveBeenLastCalledWith([1, 2, 2]);
|
|
369
|
+
expect(effect0Fn).toHaveBeenCalledTimes(2);
|
|
370
|
+
expect(effect0Fn).toHaveBeenLastCalledWith(1);
|
|
371
|
+
expect(effect1Fn).toHaveBeenCalledTimes(2);
|
|
372
|
+
expect(effect1Fn).toHaveBeenLastCalledWith(2);
|
|
373
|
+
expect(effect2Fn).toHaveBeenCalledTimes(1);
|
|
374
|
+
expect(effect2Fn).toHaveBeenLastCalledWith(2);
|
|
375
|
+
|
|
376
|
+
$array.pick()[2].set(3);
|
|
377
|
+
expect(effectFn).toHaveBeenCalledTimes(4);
|
|
378
|
+
expect(effectFn).toHaveBeenLastCalledWith([1, 2, 3]);
|
|
379
|
+
expect(effect0Fn).toHaveBeenCalledTimes(2);
|
|
380
|
+
expect(effect0Fn).toHaveBeenLastCalledWith(1);
|
|
381
|
+
expect(effect1Fn).toHaveBeenCalledTimes(2);
|
|
382
|
+
expect(effect1Fn).toHaveBeenLastCalledWith(2);
|
|
383
|
+
expect(effect2Fn).toHaveBeenCalledTimes(2);
|
|
384
|
+
expect(effect2Fn).toHaveBeenLastCalledWith(3);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
test("called when item replaced", () => {
|
|
388
|
+
const $array = array<FlowState<number>>([state(0), state(1), state(2)]);
|
|
389
|
+
const effectFn = vi.fn();
|
|
390
|
+
const effect0Fn = vi.fn();
|
|
391
|
+
|
|
392
|
+
effect((t) => effectFn($array.get(t).map((state) => state.get(t))));
|
|
393
|
+
effect((t) => effect0Fn($array.get(t)[0].get(t)));
|
|
394
|
+
|
|
395
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
396
|
+
expect(effectFn).toHaveBeenLastCalledWith([0, 1, 2]);
|
|
397
|
+
expect(effect0Fn).toHaveBeenCalledTimes(1);
|
|
398
|
+
expect(effect0Fn).toHaveBeenLastCalledWith(0);
|
|
399
|
+
|
|
400
|
+
$array.setItem(0, state(3));
|
|
401
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
402
|
+
expect(effectFn).toHaveBeenLastCalledWith([3, 1, 2]);
|
|
403
|
+
expect(effect0Fn).toHaveBeenCalledTimes(2);
|
|
404
|
+
expect(effect0Fn).toHaveBeenLastCalledWith(3);
|
|
405
|
+
|
|
406
|
+
$array.shift();
|
|
407
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
408
|
+
expect(effectFn).toHaveBeenLastCalledWith([1, 2]);
|
|
409
|
+
expect(effect0Fn).toHaveBeenCalledTimes(3);
|
|
410
|
+
expect(effect0Fn).toHaveBeenLastCalledWith(1);
|
|
411
|
+
|
|
412
|
+
$array.unshift(state(4));
|
|
413
|
+
expect(effectFn).toHaveBeenCalledTimes(4);
|
|
414
|
+
expect(effectFn).toHaveBeenLastCalledWith([4, 1, 2]);
|
|
415
|
+
expect(effect0Fn).toHaveBeenCalledTimes(4);
|
|
416
|
+
expect(effect0Fn).toHaveBeenLastCalledWith(4);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
describe("lastAction", () => {
|
|
420
|
+
test("called when initialized", () => {
|
|
421
|
+
const $array = array([1, 2, 3]);
|
|
422
|
+
const effectFn = vi.fn();
|
|
423
|
+
effect((t) => effectFn($array.$lastAction.get(t)));
|
|
424
|
+
|
|
425
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
426
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
427
|
+
type: "set",
|
|
428
|
+
items: [1, 2, 3],
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test("called when updated (set)", () => {
|
|
433
|
+
const $array = array([0, 1, 2]);
|
|
434
|
+
const effectFn = vi.fn();
|
|
435
|
+
effect((t) => effectFn($array.$lastAction.get(t)));
|
|
436
|
+
|
|
437
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
438
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
439
|
+
type: "set",
|
|
440
|
+
items: [0, 1, 2],
|
|
441
|
+
});
|
|
442
|
+
$array.set([1, 2, 3]);
|
|
443
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
444
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
445
|
+
type: "set",
|
|
446
|
+
items: [1, 2, 3],
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
test("called when updated (push/pop)", () => {
|
|
451
|
+
const $array = array<number>();
|
|
452
|
+
const effectFn = vi.fn();
|
|
453
|
+
effect((t) => effectFn($array.$lastAction.get(t)));
|
|
454
|
+
|
|
455
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
456
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
457
|
+
type: "set",
|
|
458
|
+
items: [],
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
$array.push(0);
|
|
462
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
463
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
464
|
+
type: "push",
|
|
465
|
+
item: 0,
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
$array.push(1);
|
|
469
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
470
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
471
|
+
type: "push",
|
|
472
|
+
item: 1,
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
$array.push(2);
|
|
476
|
+
expect(effectFn).toHaveBeenCalledTimes(4);
|
|
477
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
478
|
+
type: "push",
|
|
479
|
+
item: 2,
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
$array.pop();
|
|
483
|
+
expect(effectFn).toHaveBeenCalledTimes(5);
|
|
484
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
485
|
+
type: "pop",
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
$array.pop();
|
|
489
|
+
expect(effectFn).toHaveBeenCalledTimes(6);
|
|
490
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
491
|
+
type: "pop",
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
$array.pop();
|
|
495
|
+
expect(effectFn).toHaveBeenCalledTimes(7);
|
|
496
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
497
|
+
type: "pop",
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
test("called when updated (unshift/shift)", () => {
|
|
502
|
+
const $array = array<number>();
|
|
503
|
+
const effectFn = vi.fn();
|
|
504
|
+
effect((t) => effectFn($array.$lastAction.get(t)));
|
|
505
|
+
|
|
506
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
507
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
508
|
+
type: "set",
|
|
509
|
+
items: [],
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
$array.unshift(0);
|
|
513
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
514
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
515
|
+
type: "unshift",
|
|
516
|
+
item: 0,
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
$array.unshift(1);
|
|
520
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
521
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
522
|
+
type: "unshift",
|
|
523
|
+
item: 1,
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
$array.unshift(2);
|
|
527
|
+
expect(effectFn).toHaveBeenCalledTimes(4);
|
|
528
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
529
|
+
type: "unshift",
|
|
530
|
+
item: 2,
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
$array.shift();
|
|
534
|
+
expect(effectFn).toHaveBeenCalledTimes(5);
|
|
535
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
536
|
+
type: "shift",
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
$array.shift();
|
|
540
|
+
expect(effectFn).toHaveBeenCalledTimes(6);
|
|
541
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
542
|
+
type: "shift",
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
$array.shift();
|
|
546
|
+
expect(effectFn).toHaveBeenCalledTimes(7);
|
|
547
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
548
|
+
type: "shift",
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
test("called when updated (splice)", () => {
|
|
553
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
554
|
+
const effectFn = vi.fn();
|
|
555
|
+
effect((t) => effectFn($array.$lastAction.get(t)));
|
|
556
|
+
|
|
557
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
558
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
559
|
+
type: "set",
|
|
560
|
+
items: [0, 1, 2, 3, 4],
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
$array.splice(1, 2);
|
|
564
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
565
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
566
|
+
type: "splice",
|
|
567
|
+
start: 1,
|
|
568
|
+
deleteCount: 2,
|
|
569
|
+
items: [],
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
$array.splice(1, 0, 1, 2);
|
|
573
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
574
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
575
|
+
type: "splice",
|
|
576
|
+
start: 1,
|
|
577
|
+
deleteCount: 0,
|
|
578
|
+
items: [1, 2],
|
|
579
|
+
});
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
test("called when updated (clear)", () => {
|
|
583
|
+
const $array = array<number>([0, 1, 2, 3, 4]);
|
|
584
|
+
const effectFn = vi.fn();
|
|
585
|
+
effect((t) => effectFn($array.$lastAction.get(t)));
|
|
586
|
+
|
|
587
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
588
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
589
|
+
type: "set",
|
|
590
|
+
items: [0, 1, 2, 3, 4],
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
$array.clear();
|
|
594
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
595
|
+
expect(effectFn).toHaveBeenLastCalledWith({
|
|
596
|
+
type: "clear",
|
|
597
|
+
});
|
|
598
|
+
});
|
|
599
|
+
});
|
|
620
600
|
});
|