@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/docs/index.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: home
|
|
3
|
+
|
|
4
|
+
hero:
|
|
5
|
+
name: PicoFlow
|
|
6
|
+
text: Lightweight Reactive Dataflow
|
|
7
|
+
tagline: Fine-grained reactive primitives for TypeScript with explicit dependency tracking
|
|
8
|
+
image:
|
|
9
|
+
src: /logo.svg
|
|
10
|
+
alt: PicoFlow
|
|
11
|
+
actions:
|
|
12
|
+
- theme: brand
|
|
13
|
+
text: Get Started
|
|
14
|
+
link: /guide/introduction/getting-started
|
|
15
|
+
- theme: alt
|
|
16
|
+
text: API Reference
|
|
17
|
+
link: /api/
|
|
18
|
+
- theme: alt
|
|
19
|
+
text: View on GitLab
|
|
20
|
+
link: https://gitlab.com/ersbeth-web/picoflow
|
|
21
|
+
|
|
22
|
+
features:
|
|
23
|
+
- icon: 🎯
|
|
24
|
+
title: Explicit Tracking
|
|
25
|
+
details: Full control over reactive dependencies with TrackingContext. Choose between reactive reads with get(t) and non-reactive reads with pick().
|
|
26
|
+
|
|
27
|
+
- icon: ⚡
|
|
28
|
+
title: Lazy Evaluation
|
|
29
|
+
details: Derivations compute only when accessed, not on construction. Smart caching ensures computations run only when dependencies change.
|
|
30
|
+
|
|
31
|
+
- icon: 🔧
|
|
32
|
+
title: Fine-grained Reactivity
|
|
33
|
+
details: Track specific operations on collections with reactive arrays and maps. Subscribe to additions, deletions, or entire collection changes.
|
|
34
|
+
|
|
35
|
+
- icon: 🧹
|
|
36
|
+
title: Resource Management
|
|
37
|
+
details: Automatic cleanup with dispose patterns. Manage async resources, streams, and effects with confidence.
|
|
38
|
+
|
|
39
|
+
- icon: 📦
|
|
40
|
+
title: Lightweight
|
|
41
|
+
details: Minimal bundle size with zero dependencies. Tree-shakeable exports ensure you only ship what you use.
|
|
42
|
+
|
|
43
|
+
- icon: 🔄
|
|
44
|
+
title: SolidJS Integration
|
|
45
|
+
details: Seamless integration with SolidJS through built-in converters. Use PicoFlow primitives directly in Solid components.
|
|
46
|
+
---
|
|
47
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Free v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M176 120C189.3 120 200 130.7 200 144C200 157.3 189.3 168 176 168C162.7 168 152 157.3 152 144C152 130.7 162.7 120 176 120zM208.4 217.2C236.4 204.8 256 176.7 256 144C256 99.8 220.2 64 176 64C131.8 64 96 99.8 96 144C96 176.8 115.7 205 144 217.3L144 422.6C115.7 435 96 463.2 96 496C96 540.2 131.8 576 176 576C220.2 576 256 540.2 256 496C256 463.2 236.3 435 208 422.7L208 336.1C234.7 356.2 268 368.1 304 368.1L390.7 368.1C403 396.4 431.2 416.1 464 416.1C508.2 416.1 544 380.3 544 336.1C544 291.9 508.2 256.1 464 256.1C431.2 256.1 403 275.8 390.7 304.1L304 304C254.1 304 213 265.9 208.4 217.2zM176 472C189.3 472 200 482.7 200 496C200 509.3 189.3 520 176 520C162.7 520 152 509.3 152 496C152 482.7 162.7 472 176 472zM440 336C440 322.7 450.7 312 464 312C477.3 312 488 322.7 488 336C488 349.3 477.3 360 464 360C450.7 360 440 349.3 440 336z" fill="#5672cd"/></svg>
|
package/package.json
CHANGED
|
@@ -1,43 +1,59 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
2
|
+
"name": "@ersbeth/picoflow",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Minimal Dataflow librairy for TypeScript",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
8
|
+
"default": "./dist/picoflow.js"
|
|
9
|
+
},
|
|
10
|
+
"imports": {
|
|
11
|
+
"#package": "./src/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"check": "pnpm exec tsc --noEmit",
|
|
15
|
+
"lint": "pnpm exec biome check --fix",
|
|
16
|
+
"build": "pnpm exec vite build --config vite.config.ts",
|
|
17
|
+
"test": "pnpm exec vitest",
|
|
18
|
+
"docs:dev": "vitepress dev docs",
|
|
19
|
+
"docs:build": "pnpm docs:generate && vitepress build docs",
|
|
20
|
+
"docs:preview": "vitepress preview docs",
|
|
21
|
+
"docs:generate": "typedoc",
|
|
22
|
+
"api:extract": "pnpm exec api-extractor run --local",
|
|
23
|
+
"api:generate": "pnpm exec api-documenter markdown -i ./api/temp -o ./api/doc",
|
|
24
|
+
"api:clean": "rm ./api/temp/*",
|
|
25
|
+
"api": "pnpm api:extract && pnpm api:generate && pnpm api:clean"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"solid-js": "^1.9.7"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@biomejs/biome": "2.3.8",
|
|
32
|
+
"@braintree/sanitize-url": "^7.1.1",
|
|
33
|
+
"@vitest/coverage-v8": "^3.0.9",
|
|
34
|
+
"cytoscape": "^3.33.1",
|
|
35
|
+
"cytoscape-cose-bilkent": "^4.1.0",
|
|
36
|
+
"dayjs": "^1.11.19",
|
|
37
|
+
"dompurify": "^3.3.0",
|
|
38
|
+
"mermaid": "^11.12.1",
|
|
39
|
+
"typedoc": "^0.28.15",
|
|
40
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
41
|
+
"typedoc-vitepress-theme": "^1.1.2",
|
|
42
|
+
"typescript": "^5.9.3",
|
|
43
|
+
"vite": "^6.2.3",
|
|
44
|
+
"vite-plugin-dts": "^4.5.3",
|
|
45
|
+
"vitepress": "^1.6.4",
|
|
46
|
+
"vitepress-plugin-mermaid": "^2.0.17",
|
|
47
|
+
"vitest": "^3.0.9"
|
|
48
|
+
},
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+ssh://git@gitlab.com/ersbeth-web/picoflow.git"
|
|
52
|
+
},
|
|
53
|
+
"author": "Elisabeth Rousset",
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://gitlab.com/ersbeth-web/picoflow/issues"
|
|
57
|
+
},
|
|
58
|
+
"homepage": "https://gitlab.com/ersbeth-web/picoflow#readme"
|
|
43
59
|
}
|
package/src/advanced/array.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { FlowObservable, type FlowState } from "../basic";
|
|
2
|
-
import { isDisposable } from "../basic";
|
|
1
|
+
import { FlowObservable, type FlowState, isDisposable } from "../basic";
|
|
3
2
|
import { state } from "../creators";
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -7,218 +6,217 @@ import { state } from "../creators";
|
|
|
7
6
|
* @public
|
|
8
7
|
*/
|
|
9
8
|
export type FlowArrayAction<T> =
|
|
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
|
-
|
|
9
|
+
| {
|
|
10
|
+
type: "set";
|
|
11
|
+
items: T[];
|
|
12
|
+
}
|
|
13
|
+
| {
|
|
14
|
+
type: "setItem";
|
|
15
|
+
index: number;
|
|
16
|
+
item: T;
|
|
17
|
+
}
|
|
18
|
+
| {
|
|
19
|
+
type: "push";
|
|
20
|
+
item: T;
|
|
21
|
+
}
|
|
22
|
+
| {
|
|
23
|
+
type: "pop";
|
|
24
|
+
}
|
|
25
|
+
| {
|
|
26
|
+
type: "unshift";
|
|
27
|
+
item: T;
|
|
28
|
+
}
|
|
29
|
+
| {
|
|
30
|
+
type: "shift";
|
|
31
|
+
}
|
|
32
|
+
| {
|
|
33
|
+
type: "splice";
|
|
34
|
+
start: number;
|
|
35
|
+
deleteCount: number;
|
|
36
|
+
items: T[];
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
type: "clear";
|
|
40
|
+
};
|
|
42
41
|
|
|
43
42
|
/**
|
|
44
43
|
* Represents a reactive array.
|
|
45
44
|
* @public
|
|
46
45
|
*/
|
|
47
46
|
export class FlowArray<T> extends FlowObservable<T[]> {
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
/*@internal*/ protected override _value: T[] = [];
|
|
47
|
+
/**
|
|
48
|
+
* Last action performed on the FlowArray.
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
$lastAction: FlowState<FlowArrayAction<T>>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Creates an instance of FlowArray.
|
|
55
|
+
* @param value - Initial array value.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
constructor(value: T[] = []) {
|
|
59
|
+
super();
|
|
60
|
+
this._value = value;
|
|
61
|
+
this.$lastAction = state<FlowArrayAction<T>>({
|
|
62
|
+
type: "set",
|
|
63
|
+
items: value,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Gets the current length of the array.
|
|
69
|
+
* @returns The length of the array.
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
get length(): number {
|
|
73
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
74
|
+
return this._value.length;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Internal method to get the raw value.
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
protected _getRaw(): T[] {
|
|
82
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
83
|
+
return [...this._value]; // Ensure nobody can modify the original array
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Replaces the entire array with new items.
|
|
88
|
+
* @param items - The new array of items.
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
set(items: T[]): void {
|
|
92
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
93
|
+
this._value.forEach((item) => {
|
|
94
|
+
if (isDisposable(item)) item.dispose({ self: true });
|
|
95
|
+
});
|
|
96
|
+
this._value = items;
|
|
97
|
+
this._notify();
|
|
98
|
+
this.$lastAction.set({ type: "set", items: items });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Replaces an item at a specific index.
|
|
103
|
+
* @param index - The index of the item to replace.
|
|
104
|
+
* @param item - The new item.
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
107
|
+
setItem(index: number, item: T): void {
|
|
108
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
109
|
+
if (index < 0 || index >= this._value.length) {
|
|
110
|
+
throw new Error("[PicoFlow] Index out of bounds");
|
|
111
|
+
}
|
|
112
|
+
this._value[index] = item;
|
|
113
|
+
this._notify();
|
|
114
|
+
this.$lastAction.set({ type: "setItem", index: index, item: item });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Appends an item to the end of the array.
|
|
119
|
+
* @param item - The item to append.
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
push(item: T): void {
|
|
123
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
124
|
+
this._value.push(item);
|
|
125
|
+
this._notify();
|
|
126
|
+
this.$lastAction.set({ type: "push", item: item });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Removes the last item from the array.
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
pop(): void {
|
|
134
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
135
|
+
const item = this._value.pop();
|
|
136
|
+
if (isDisposable(item)) {
|
|
137
|
+
item.dispose({ self: true });
|
|
138
|
+
}
|
|
139
|
+
this._notify();
|
|
140
|
+
this.$lastAction.set({ type: "pop" });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Inserts an item at the beginning of the array.
|
|
145
|
+
* @param item - The item to insert.
|
|
146
|
+
* @public
|
|
147
|
+
*/
|
|
148
|
+
unshift(item: T): void {
|
|
149
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
150
|
+
this._value.unshift(item);
|
|
151
|
+
this._notify();
|
|
152
|
+
this.$lastAction.set({ type: "unshift", item: item });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Removes the first item from the array.
|
|
157
|
+
* @public
|
|
158
|
+
*/
|
|
159
|
+
shift(): void {
|
|
160
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
161
|
+
const item = this._value.shift();
|
|
162
|
+
if (isDisposable(item)) {
|
|
163
|
+
item.dispose({ self: true });
|
|
164
|
+
}
|
|
165
|
+
this._notify();
|
|
166
|
+
this.$lastAction.set({ type: "shift" });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Changes the content of the array.
|
|
171
|
+
* @param start - The starting index.
|
|
172
|
+
* @param deleteCount - Number of items to remove.
|
|
173
|
+
* @param newItems - New items to add.
|
|
174
|
+
* @public
|
|
175
|
+
*/
|
|
176
|
+
splice(start: number, deleteCount: number, ...newItems: T[]): void {
|
|
177
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
178
|
+
const items = this._value.splice(start, deleteCount, ...newItems);
|
|
179
|
+
items.forEach((item) => {
|
|
180
|
+
if (isDisposable(item)) item.dispose({ self: true });
|
|
181
|
+
});
|
|
182
|
+
this._notify();
|
|
183
|
+
this.$lastAction.set({
|
|
184
|
+
type: "splice",
|
|
185
|
+
start: start,
|
|
186
|
+
deleteCount: deleteCount,
|
|
187
|
+
items: newItems,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Clears all items from the array.
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
clear(): void {
|
|
196
|
+
if (this._disposed) throw new Error("[PicoFlow] Primitive is disposed");
|
|
197
|
+
const items = [...this._value];
|
|
198
|
+
items.forEach((item) => {
|
|
199
|
+
if (isDisposable(item)) item.dispose({ self: true });
|
|
200
|
+
});
|
|
201
|
+
this._value = [];
|
|
202
|
+
this._notify();
|
|
203
|
+
this.$lastAction.set({ type: "clear" });
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Disposes the FlowArray and its items.
|
|
208
|
+
* @param options - Disposal options.
|
|
209
|
+
* @public
|
|
210
|
+
*/
|
|
211
|
+
override dispose(options?: { self: boolean }): void {
|
|
212
|
+
super.dispose(options);
|
|
213
|
+
this._value.forEach((item) => {
|
|
214
|
+
if (isDisposable(item)) item.dispose(options);
|
|
215
|
+
});
|
|
216
|
+
this._value = [];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/* INTERNAL */
|
|
220
|
+
|
|
221
|
+
/** @internal */ protected override _value: T[] = [];
|
|
224
222
|
}
|
package/src/advanced/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
export type { FlowArrayAction } from "./array";
|
|
2
|
+
export { FlowArray } from "./array";
|
|
1
3
|
export { FlowMap } from "./map";
|
|
2
|
-
export { FlowStream } from "./stream";
|
|
3
|
-
export { FlowStreamAsync } from "./streamAsync";
|
|
4
4
|
export { FlowResource } from "./resource";
|
|
5
5
|
export { FlowResourceAsync } from "./resourceAsync";
|
|
6
6
|
export type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
FlowStreamDisposer,
|
|
8
|
+
FlowStreamSetter,
|
|
9
|
+
FlowStreamUpdater,
|
|
10
10
|
} from "./stream";
|
|
11
|
-
export {
|
|
12
|
-
export
|
|
11
|
+
export { FlowStream } from "./stream";
|
|
12
|
+
export { FlowStreamAsync } from "./streamAsync";
|