@ersbeth/picoflow 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/doc/index.md +1 -1
- package/api/doc/picoflow.array.md +55 -0
- package/api/doc/picoflow.constant.md +55 -0
- package/api/doc/picoflow.derivation.md +1 -1
- package/api/doc/picoflow.effect.md +1 -1
- package/api/doc/picoflow.flowarray._constructor_.md +49 -0
- package/api/doc/picoflow.flowarray._lastaction.md +13 -0
- package/api/doc/picoflow.flowarray.clear.md +17 -0
- package/api/doc/picoflow.flowarray.dispose.md +55 -0
- package/api/doc/picoflow.flowarray.get.md +19 -0
- package/api/doc/picoflow.flowarray.length.md +13 -0
- package/api/doc/picoflow.flowarray.md +273 -0
- package/api/doc/picoflow.flowarray.pop.md +17 -0
- package/api/doc/picoflow.flowarray.push.md +53 -0
- package/api/doc/picoflow.flowarray.set.md +53 -0
- package/api/doc/picoflow.flowarray.setitem.md +69 -0
- package/api/doc/picoflow.flowarray.shift.md +17 -0
- package/api/doc/picoflow.flowarray.splice.md +85 -0
- package/api/doc/picoflow.flowarray.unshift.md +53 -0
- package/api/doc/picoflow.flowarrayaction.md +37 -0
- package/api/doc/picoflow.flowconstant._constructor_.md +49 -0
- package/api/doc/picoflow.flowconstant.get.md +25 -0
- package/api/doc/picoflow.flowconstant.md +88 -0
- package/api/doc/picoflow.flowderivation._constructor_.md +2 -2
- package/api/doc/picoflow.flowderivation.get.md +2 -2
- package/api/doc/picoflow.flowderivation.md +2 -2
- package/api/doc/picoflow.flowdisposable.dispose.md +55 -0
- package/api/doc/picoflow.flowdisposable.md +43 -0
- package/api/doc/picoflow.floweffect._constructor_.md +7 -2
- package/api/doc/picoflow.floweffect.dispose.md +3 -3
- package/api/doc/picoflow.floweffect.disposed.md +1 -1
- package/api/doc/picoflow.floweffect.md +4 -4
- package/api/doc/picoflow.flowgetter.md +2 -2
- package/api/doc/picoflow.flowmap._lastdeleted.md +1 -1
- package/api/doc/picoflow.flowmap._lastset.md +1 -1
- package/api/doc/picoflow.flowmap.delete.md +6 -2
- package/api/doc/picoflow.flowmap.md +5 -7
- package/api/doc/picoflow.flowmap.setat.md +6 -2
- package/api/doc/picoflow.flowobservable.get.md +3 -3
- package/api/doc/picoflow.flowobservable.md +18 -4
- package/api/doc/picoflow.flowobservable.subscribe.md +55 -0
- package/api/doc/picoflow.flowresource._constructor_.md +2 -18
- package/api/doc/picoflow.flowresource.fetch.md +1 -1
- package/api/doc/picoflow.flowresource.get.md +4 -4
- package/api/doc/picoflow.flowresource.md +4 -4
- package/api/doc/picoflow.flowresourceasync._constructor_.md +49 -0
- package/api/doc/picoflow.flowresourceasync.fetch.md +27 -0
- package/api/doc/picoflow.flowresourceasync.get.md +23 -0
- package/api/doc/picoflow.flowresourceasync.md +100 -0
- package/api/doc/picoflow.flowsignal.dispose.md +42 -8
- package/api/doc/picoflow.flowsignal.disposed.md +2 -2
- package/api/doc/picoflow.flowsignal.md +8 -7
- package/api/doc/picoflow.flowsignal.trigger.md +3 -7
- package/api/doc/picoflow.flowstate.md +4 -52
- package/api/doc/picoflow.flowstate.set.md +5 -5
- package/api/doc/picoflow.flowstream._constructor_.md +3 -19
- package/api/doc/picoflow.flowstream.dispose.md +1 -1
- package/api/doc/picoflow.flowstream.get.md +4 -4
- package/api/doc/picoflow.flowstream.md +5 -5
- package/api/doc/picoflow.flowstreamasync._constructor_.md +54 -0
- package/api/doc/picoflow.flowstreamasync.dispose.md +21 -0
- package/api/doc/picoflow.flowstreamasync.get.md +23 -0
- package/api/doc/picoflow.flowstreamasync.md +100 -0
- package/api/doc/picoflow.flowstreamdisposer.md +13 -0
- package/api/doc/picoflow.flowstreamsetter.md +13 -0
- package/api/doc/picoflow.flowstreamupdater.md +19 -0
- package/api/doc/picoflow.flowwatcher.md +1 -1
- package/api/doc/picoflow.isdisposable.md +55 -0
- package/api/doc/picoflow.map.md +1 -1
- package/api/doc/picoflow.md +149 -13
- package/api/doc/picoflow.resource.md +2 -18
- package/api/doc/picoflow.resourceasync.md +55 -0
- package/api/doc/picoflow.signal.md +1 -1
- package/api/doc/picoflow.state.md +3 -3
- package/api/doc/picoflow.stream.md +2 -18
- package/api/doc/picoflow.streamasync.md +55 -0
- package/api/picoflow.public.api.md +192 -0
- package/api-extractor.json +2 -1
- package/dist/picoflow.js +513 -305
- package/dist/types/advanced/array.d.ts +116 -0
- package/dist/types/advanced/array.d.ts.map +1 -0
- package/dist/types/advanced/index.d.ts +9 -0
- package/dist/types/advanced/index.d.ts.map +1 -0
- package/dist/types/{map.d.ts → advanced/map.d.ts} +12 -12
- package/dist/types/advanced/map.d.ts.map +1 -0
- package/dist/types/advanced/resource.d.ts +39 -0
- package/dist/types/advanced/resource.d.ts.map +1 -0
- package/dist/types/{resource.d.ts → advanced/resourceAsync.d.ts} +6 -11
- package/dist/types/advanced/resourceAsync.d.ts.map +1 -0
- package/dist/types/advanced/stream.d.ts +59 -0
- package/dist/types/advanced/stream.d.ts.map +1 -0
- package/dist/types/advanced/streamAsync.d.ts +43 -0
- package/dist/types/advanced/streamAsync.d.ts.map +1 -0
- package/dist/types/basic/constant.d.ts +32 -0
- package/dist/types/basic/constant.d.ts.map +1 -0
- package/dist/types/basic/derivation.d.ts +40 -0
- package/dist/types/basic/derivation.d.ts.map +1 -0
- package/dist/types/basic/disposable.d.ts +23 -0
- package/dist/types/basic/disposable.d.ts.map +1 -0
- package/dist/types/basic/effect.d.ts +56 -0
- package/dist/types/basic/effect.d.ts.map +1 -0
- package/dist/types/basic/index.d.ts +11 -0
- package/dist/types/basic/index.d.ts.map +1 -0
- package/dist/types/basic/observable.d.ts +34 -0
- package/dist/types/basic/observable.d.ts.map +1 -0
- package/dist/types/basic/signal.d.ts +40 -0
- package/dist/types/basic/signal.d.ts.map +1 -0
- package/dist/types/basic/state.d.ts +26 -0
- package/dist/types/basic/state.d.ts.map +1 -0
- package/dist/types/creators.d.ts +38 -13
- package/dist/types/creators.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -9
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/advanced/array.ts +224 -0
- package/src/advanced/index.ts +12 -0
- package/src/{map.ts → advanced/map.ts} +14 -14
- package/src/advanced/resource.ts +56 -0
- package/src/{resource.ts → advanced/resourceAsync.ts} +9 -16
- package/src/advanced/stream.ts +87 -0
- package/src/advanced/streamAsync.ts +82 -0
- package/src/basic/constant.ts +64 -0
- package/src/basic/derivation.ts +86 -0
- package/src/basic/disposable.ts +27 -0
- package/src/basic/effect.ts +96 -0
- package/src/basic/index.ts +10 -0
- package/src/basic/observable.ts +51 -0
- package/src/basic/signal.ts +117 -0
- package/src/basic/state.ts +39 -0
- package/src/creators.ts +66 -15
- package/src/index.ts +26 -11
- package/test/array.test.ts +620 -0
- package/test/constant.test.ts +46 -0
- package/test/derivation.test.ts +30 -6
- package/test/effect.test.ts +29 -0
- package/test/map.test.ts +38 -0
- package/test/resource.test.ts +18 -16
- package/test/resourceAsync.test.ts +108 -0
- package/test/signal.test.ts +18 -1
- package/test/state.test.ts +107 -2
- package/test/stream.test.ts +38 -13
- package/test/streamAsync.test.ts +194 -0
- package/tsconfig.json +3 -1
- package/api/doc/picoflow.flowdisposer.md +0 -13
- package/api/doc/picoflow.flowsetter.md +0 -13
- package/api/doc/picoflow.flowstate._constructor_.md +0 -49
- package/api/doc/picoflow.flowstate.get.md +0 -23
- package/api/doc/picoflow.flowupdater.md +0 -19
- package/api/picoflow.api.md +0 -145
- package/dist/types/derivation.d.ts +0 -58
- package/dist/types/derivation.d.ts.map +0 -1
- package/dist/types/effect.d.ts +0 -108
- package/dist/types/effect.d.ts.map +0 -1
- package/dist/types/map.d.ts.map +0 -1
- package/dist/types/observable.d.ts +0 -40
- package/dist/types/observable.d.ts.map +0 -1
- package/dist/types/resource.d.ts.map +0 -1
- package/dist/types/signal.d.ts +0 -111
- package/dist/types/signal.d.ts.map +0 -1
- package/dist/types/state.d.ts +0 -39
- package/dist/types/state.d.ts.map +0 -1
- package/dist/types/stream.d.ts +0 -71
- package/dist/types/stream.d.ts.map +0 -1
- package/src/derivation.ts +0 -96
- package/src/effect.ts +0 -152
- package/src/observable.ts +0 -50
- package/src/signal.ts +0 -166
- package/src/state.ts +0 -52
- package/src/stream.ts +0 -99
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from "vitest";
|
|
2
|
+
import { effect, streamAsync } from "#package";
|
|
3
|
+
|
|
4
|
+
describe("streamAsync", () => {
|
|
5
|
+
test("is updated (callback)", async () => {
|
|
6
|
+
const counter = {
|
|
7
|
+
count: 0,
|
|
8
|
+
callback: undefined as ((value: number) => void) | undefined,
|
|
9
|
+
increment() {
|
|
10
|
+
this.count++;
|
|
11
|
+
if (this.callback) {
|
|
12
|
+
this.callback(this.count);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const $stream = streamAsync((set) => {
|
|
18
|
+
counter.callback = set;
|
|
19
|
+
return () => {
|
|
20
|
+
counter.callback = undefined;
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const promise = $stream.get();
|
|
25
|
+
|
|
26
|
+
counter.increment();
|
|
27
|
+
expect(await promise).toBe(1);
|
|
28
|
+
expect(await $stream.get()).toBe(1);
|
|
29
|
+
|
|
30
|
+
counter.increment();
|
|
31
|
+
expect(await $stream.get()).toBe(2);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("stream is updated (interval)", async () => {
|
|
35
|
+
vi.useFakeTimers();
|
|
36
|
+
|
|
37
|
+
const $stream = streamAsync<number>((set) => {
|
|
38
|
+
let counter = 0;
|
|
39
|
+
const interval = setInterval(() => {
|
|
40
|
+
counter++;
|
|
41
|
+
set(counter);
|
|
42
|
+
}, 1000);
|
|
43
|
+
return () => clearInterval(interval);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const promise = $stream.get();
|
|
47
|
+
|
|
48
|
+
vi.advanceTimersToNextTimer();
|
|
49
|
+
expect(await promise).toBe(1);
|
|
50
|
+
expect(await $stream.get()).toBe(1);
|
|
51
|
+
|
|
52
|
+
vi.advanceTimersToNextTimer();
|
|
53
|
+
expect(await $stream.get()).toBe(2);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("get throws when stream is disposed", async () => {
|
|
57
|
+
vi.useFakeTimers();
|
|
58
|
+
|
|
59
|
+
const $stream = streamAsync((set) => {
|
|
60
|
+
let counter = 0;
|
|
61
|
+
const interval = setInterval(() => {
|
|
62
|
+
counter++;
|
|
63
|
+
set(counter);
|
|
64
|
+
}, 1000);
|
|
65
|
+
return () => clearInterval(interval);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
vi.advanceTimersToNextTimer();
|
|
69
|
+
expect(await $stream.get()).toBe(1);
|
|
70
|
+
|
|
71
|
+
vi.advanceTimersToNextTimer();
|
|
72
|
+
expect(await $stream.get()).toBe(2);
|
|
73
|
+
|
|
74
|
+
$stream.dispose();
|
|
75
|
+
vi.advanceTimersToNextTimer();
|
|
76
|
+
expect(() => $stream.get()).toThrow("[PicoFlow] Primitive is disposed");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("effect", () => {
|
|
81
|
+
test("called when stream is updated", async () => {
|
|
82
|
+
vi.useFakeTimers();
|
|
83
|
+
|
|
84
|
+
const $stream = streamAsync((set) => {
|
|
85
|
+
let counter = 0;
|
|
86
|
+
const interval = setInterval(() => {
|
|
87
|
+
counter++;
|
|
88
|
+
set(counter);
|
|
89
|
+
}, 1000);
|
|
90
|
+
return () => clearInterval(interval);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const effectFn = vi.fn();
|
|
94
|
+
effect((get) => effectFn(get($stream)));
|
|
95
|
+
|
|
96
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
97
|
+
expect(effectFn).toHaveBeenLastCalledWith(new Promise(() => {}));
|
|
98
|
+
|
|
99
|
+
vi.advanceTimersToNextTimer();
|
|
100
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
101
|
+
expect(await effectFn.mock.calls[1][0]).toEqual(1);
|
|
102
|
+
|
|
103
|
+
vi.advanceTimersToNextTimer();
|
|
104
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
105
|
+
expect(await effectFn.mock.calls[2][0]).toEqual(2);
|
|
106
|
+
|
|
107
|
+
vi.advanceTimersToNextTimer();
|
|
108
|
+
expect(effectFn).toHaveBeenCalledTimes(4);
|
|
109
|
+
expect(await effectFn.mock.calls[3][0]).toEqual(3);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("NOT called when stream is updated with same value", async () => {
|
|
113
|
+
vi.useFakeTimers();
|
|
114
|
+
|
|
115
|
+
const $stream = streamAsync((set) => {
|
|
116
|
+
const interval = setInterval(() => {
|
|
117
|
+
set(5);
|
|
118
|
+
}, 1000);
|
|
119
|
+
return () => clearInterval(interval);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const effectFn = vi.fn();
|
|
123
|
+
effect((get) => effectFn(get($stream)));
|
|
124
|
+
|
|
125
|
+
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
126
|
+
expect(effectFn).toHaveBeenLastCalledWith(new Promise(() => {}));
|
|
127
|
+
|
|
128
|
+
vi.advanceTimersToNextTimer();
|
|
129
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
130
|
+
expect(await effectFn.mock.calls[1][0]).toEqual(5);
|
|
131
|
+
|
|
132
|
+
vi.advanceTimersToNextTimer();
|
|
133
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
134
|
+
expect(await effectFn.mock.calls[1][0]).toEqual(5);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("NOT called when disposed", async () => {
|
|
138
|
+
vi.useFakeTimers();
|
|
139
|
+
|
|
140
|
+
const $stream = streamAsync((set) => {
|
|
141
|
+
let counter = 0;
|
|
142
|
+
const interval = setInterval(() => {
|
|
143
|
+
counter++;
|
|
144
|
+
set(counter);
|
|
145
|
+
}, 1000);
|
|
146
|
+
return () => clearInterval(interval);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const effectFn = vi.fn();
|
|
150
|
+
const $effect = effect((get) => effectFn(get($stream)));
|
|
151
|
+
|
|
152
|
+
vi.advanceTimersToNextTimer();
|
|
153
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
154
|
+
expect(await effectFn.mock.calls[1][0]).toEqual(1);
|
|
155
|
+
|
|
156
|
+
vi.advanceTimersToNextTimer();
|
|
157
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
158
|
+
expect(await effectFn.mock.calls[2][0]).toEqual(2);
|
|
159
|
+
|
|
160
|
+
$effect.dispose();
|
|
161
|
+
vi.advanceTimersToNextTimer();
|
|
162
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
163
|
+
expect(await effectFn.mock.calls[2][0]).toEqual(2);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("NOT called when stream is disposed", async () => {
|
|
167
|
+
vi.useFakeTimers();
|
|
168
|
+
|
|
169
|
+
const $stream = streamAsync((set) => {
|
|
170
|
+
let counter = 0;
|
|
171
|
+
const interval = setInterval(() => {
|
|
172
|
+
counter++;
|
|
173
|
+
set(counter);
|
|
174
|
+
}, 1000);
|
|
175
|
+
return () => clearInterval(interval);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const effectFn = vi.fn();
|
|
179
|
+
effect((get) => effectFn(get($stream)));
|
|
180
|
+
|
|
181
|
+
vi.advanceTimersToNextTimer();
|
|
182
|
+
expect(effectFn).toHaveBeenCalledTimes(2);
|
|
183
|
+
expect(await effectFn.mock.calls[1][0]).toEqual(1);
|
|
184
|
+
|
|
185
|
+
vi.advanceTimersToNextTimer();
|
|
186
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
187
|
+
expect(await effectFn.mock.calls[2][0]).toEqual(2);
|
|
188
|
+
|
|
189
|
+
$stream.dispose();
|
|
190
|
+
vi.advanceTimersToNextTimer();
|
|
191
|
+
expect(effectFn).toHaveBeenCalledTimes(3);
|
|
192
|
+
expect(await effectFn.mock.calls[2][0]).toEqual(2);
|
|
193
|
+
});
|
|
194
|
+
});
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
-
|
|
3
|
-
[Home](./index.md) > [picoflow](./picoflow.md) > [FlowDisposer](./picoflow.flowdisposer.md)
|
|
4
|
-
|
|
5
|
-
## FlowDisposer type
|
|
6
|
-
|
|
7
|
-
A function that disposes of a resource.
|
|
8
|
-
|
|
9
|
-
**Signature:**
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
export type FlowDisposer = () => void;
|
|
13
|
-
```
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
-
|
|
3
|
-
[Home](./index.md) > [picoflow](./picoflow.md) > [FlowSetter](./picoflow.flowsetter.md)
|
|
4
|
-
|
|
5
|
-
## FlowSetter type
|
|
6
|
-
|
|
7
|
-
A function that sets a new value.
|
|
8
|
-
|
|
9
|
-
**Signature:**
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
export type FlowSetter<T> = (value: T) => void;
|
|
13
|
-
```
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
-
|
|
3
|
-
[Home](./index.md) > [picoflow](./picoflow.md) > [FlowState](./picoflow.flowstate.md) > [(constructor)](./picoflow.flowstate._constructor_.md)
|
|
4
|
-
|
|
5
|
-
## FlowState.(constructor)
|
|
6
|
-
|
|
7
|
-
Creates a new FlowState with the given initial value.
|
|
8
|
-
|
|
9
|
-
**Signature:**
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
constructor(value: T);
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Parameters
|
|
16
|
-
|
|
17
|
-
<table><thead><tr><th>
|
|
18
|
-
|
|
19
|
-
Parameter
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
</th><th>
|
|
23
|
-
|
|
24
|
-
Type
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
</th><th>
|
|
28
|
-
|
|
29
|
-
Description
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
</th></tr></thead>
|
|
33
|
-
<tbody><tr><td>
|
|
34
|
-
|
|
35
|
-
value
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
</td><td>
|
|
39
|
-
|
|
40
|
-
T
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
</td><td>
|
|
44
|
-
|
|
45
|
-
The initial value for the state.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
</td></tr>
|
|
49
|
-
</tbody></table>
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
-
|
|
3
|
-
[Home](./index.md) > [picoflow](./picoflow.md) > [FlowState](./picoflow.flowstate.md) > [get](./picoflow.flowstate.get.md)
|
|
4
|
-
|
|
5
|
-
## FlowState.get() method
|
|
6
|
-
|
|
7
|
-
Retrieves the current state value.
|
|
8
|
-
|
|
9
|
-
**Signature:**
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
get(): T;
|
|
13
|
-
```
|
|
14
|
-
**Returns:**
|
|
15
|
-
|
|
16
|
-
T
|
|
17
|
-
|
|
18
|
-
The current value of the state.
|
|
19
|
-
|
|
20
|
-
## Exceptions
|
|
21
|
-
|
|
22
|
-
Error if the state has been disposed.
|
|
23
|
-
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
-
|
|
3
|
-
[Home](./index.md) > [picoflow](./picoflow.md) > [FlowUpdater](./picoflow.flowupdater.md)
|
|
4
|
-
|
|
5
|
-
## FlowUpdater type
|
|
6
|
-
|
|
7
|
-
A function that performs updates on a stream.
|
|
8
|
-
|
|
9
|
-
**Signature:**
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
export type FlowUpdater<T> = (set: FlowSetter<T>) => FlowDisposer;
|
|
13
|
-
```
|
|
14
|
-
**References:** [FlowSetter](./picoflow.flowsetter.md)<!-- -->, [FlowDisposer](./picoflow.flowdisposer.md)
|
|
15
|
-
|
|
16
|
-
## Remarks
|
|
17
|
-
|
|
18
|
-
The updater receives a setter function that can be used to update the stream's value. It should return a disposer function to clean up any resources or subscriptions.
|
|
19
|
-
|
package/api/picoflow.api.md
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
## API Report File for "picoflow"
|
|
2
|
-
|
|
3
|
-
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
|
|
7
|
-
// @public
|
|
8
|
-
export function derivation<T>(fn: (get: FlowGetter, watch: FlowWatcher) => T): FlowDerivation<T>;
|
|
9
|
-
|
|
10
|
-
// @public
|
|
11
|
-
export function effect(fn: (get: FlowGetter, watch: FlowWatcher) => void): FlowEffect;
|
|
12
|
-
|
|
13
|
-
// @public
|
|
14
|
-
export class FlowDerivation<T> extends FlowObservable<T> {
|
|
15
|
-
constructor(compute: (get: FlowGetter, watch: FlowWatcher) => T);
|
|
16
|
-
// @internal
|
|
17
|
-
_exec(): void;
|
|
18
|
-
get(): T;
|
|
19
|
-
// @internal
|
|
20
|
-
_notify(): void;
|
|
21
|
-
// @internal
|
|
22
|
-
_watch(): void;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// @public
|
|
26
|
-
export type FlowDisposer = () => void;
|
|
27
|
-
|
|
28
|
-
// @public
|
|
29
|
-
export class FlowEffect {
|
|
30
|
-
constructor(apply: (get: FlowGetter, watch: FlowWatcher) => void);
|
|
31
|
-
dispose(): void;
|
|
32
|
-
get disposed(): boolean;
|
|
33
|
-
// @internal
|
|
34
|
-
_exec(): void;
|
|
35
|
-
// @internal
|
|
36
|
-
_registerDependency(dependency: FlowSignal): void;
|
|
37
|
-
// @internal
|
|
38
|
-
_unregisterDependency(dependency: FlowSignal): void;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// @public
|
|
42
|
-
export type FlowGetter = <T>(observable: FlowObservable<T>) => T;
|
|
43
|
-
|
|
44
|
-
// @public
|
|
45
|
-
export class FlowMap<K, V> extends FlowState<Map<K, V>> {
|
|
46
|
-
$lastDeleted: FlowState<{
|
|
47
|
-
key?: K;
|
|
48
|
-
value?: V;
|
|
49
|
-
}>;
|
|
50
|
-
$lastSet: FlowState<{
|
|
51
|
-
key?: K;
|
|
52
|
-
value?: V;
|
|
53
|
-
}>;
|
|
54
|
-
delete(key: K): void;
|
|
55
|
-
setAt(key: K, value: V): void;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// @public
|
|
59
|
-
export abstract class FlowObservable<T> extends FlowSignal {
|
|
60
|
-
abstract get(): T;
|
|
61
|
-
// @internal
|
|
62
|
-
_getFrom(listener: FlowObservable<unknown> | FlowEffect): T;
|
|
63
|
-
// @internal
|
|
64
|
-
protected _value: T;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// @public
|
|
68
|
-
export class FlowResource<T> extends FlowObservable<T> {
|
|
69
|
-
constructor(fetch: () => Promise<T>, initial: T);
|
|
70
|
-
fetch(): Promise<void>;
|
|
71
|
-
get(): T;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// @public
|
|
75
|
-
export type FlowSetter<T> = (value: T) => void;
|
|
76
|
-
|
|
77
|
-
// @public
|
|
78
|
-
export class FlowSignal {
|
|
79
|
-
// @internal (undocumented)
|
|
80
|
-
protected _dependencies: Set<FlowSignal>;
|
|
81
|
-
dispose(): void;
|
|
82
|
-
get disposed(): boolean;
|
|
83
|
-
// @internal (undocumented)
|
|
84
|
-
protected _disposed: boolean;
|
|
85
|
-
// @internal (undocumented)
|
|
86
|
-
protected _effects: Set<FlowEffect>;
|
|
87
|
-
// @internal (undocumented)
|
|
88
|
-
protected _listeners: Set<FlowSignal>;
|
|
89
|
-
// @internal
|
|
90
|
-
_notify(): void;
|
|
91
|
-
// @internal
|
|
92
|
-
_registerDependency(dependency: FlowSignal): void;
|
|
93
|
-
// @internal
|
|
94
|
-
_registerEffect(effect: FlowEffect): void;
|
|
95
|
-
// @internal
|
|
96
|
-
_registerListener(signal: FlowSignal): void;
|
|
97
|
-
trigger(): void;
|
|
98
|
-
// @internal
|
|
99
|
-
_unregisterDependency(dependency: FlowSignal): void;
|
|
100
|
-
// @internal
|
|
101
|
-
_unregisterEffect(effect: FlowEffect): void;
|
|
102
|
-
// @internal
|
|
103
|
-
_unregisterListener(signal: FlowSignal): void;
|
|
104
|
-
// @internal
|
|
105
|
-
_watch(): void;
|
|
106
|
-
// @internal
|
|
107
|
-
_watchFrom(listener: FlowSignal | FlowEffect): void;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// @public
|
|
111
|
-
export class FlowState<T> extends FlowObservable<T> {
|
|
112
|
-
constructor(value: T);
|
|
113
|
-
get(): T;
|
|
114
|
-
set(value: T): void;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// @public
|
|
118
|
-
export class FlowStream<T> extends FlowObservable<T> {
|
|
119
|
-
constructor(updater: FlowUpdater<T>, initial: T);
|
|
120
|
-
dispose(): void;
|
|
121
|
-
get(): T;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// @public
|
|
125
|
-
export type FlowUpdater<T> = (set: FlowSetter<T>) => FlowDisposer;
|
|
126
|
-
|
|
127
|
-
// @public
|
|
128
|
-
export type FlowWatcher = (signal: FlowSignal) => void;
|
|
129
|
-
|
|
130
|
-
// @public
|
|
131
|
-
export function map<K extends string | number | symbol, V>(initial?: Record<K, V>): FlowMap<K, V>;
|
|
132
|
-
|
|
133
|
-
// @public
|
|
134
|
-
export function resource<T>(fn: () => Promise<T>, initial: T): FlowResource<T>;
|
|
135
|
-
|
|
136
|
-
// @public
|
|
137
|
-
export function signal(): FlowSignal;
|
|
138
|
-
|
|
139
|
-
// @public
|
|
140
|
-
export function state<T>(value: T): FlowState<T>;
|
|
141
|
-
|
|
142
|
-
// @public
|
|
143
|
-
export function stream<T>(updater: (set: (value: T) => void) => () => void, initial: T): FlowStream<T>;
|
|
144
|
-
|
|
145
|
-
```
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { FlowGetter, FlowObservable } from './observable';
|
|
2
|
-
import { FlowWatcher } from './signal';
|
|
3
|
-
/**
|
|
4
|
-
* Represents a reactive derivation whose value is computed based on other reactive signals.
|
|
5
|
-
* @remarks
|
|
6
|
-
* A FlowDerivation automatically tracks its dependencies and recomputes its value when needed.
|
|
7
|
-
* @typeparam T - The type of the computed value.
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
export declare class FlowDerivation<T> extends FlowObservable<T> {
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new FlowDerivation.
|
|
13
|
-
* @param compute - A function that computes the derived value. It is provided with a getter
|
|
14
|
-
* and a watcher function to access observables and signals dependencies.
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
constructor(compute: (get: FlowGetter, watch: FlowWatcher) => T);
|
|
18
|
-
/**
|
|
19
|
-
* Gets the current derived value.
|
|
20
|
-
* @returns The current computed value.
|
|
21
|
-
* @remarks
|
|
22
|
-
* This method ensures that the derivation is up-to-date before returning the value.
|
|
23
|
-
* @public
|
|
24
|
-
*/
|
|
25
|
-
get(): T;
|
|
26
|
-
/** @internal */
|
|
27
|
-
private _initialized;
|
|
28
|
-
/** @internal */
|
|
29
|
-
private _dirty;
|
|
30
|
-
/** @internal */
|
|
31
|
-
private _trackedGet;
|
|
32
|
-
/** @internal */
|
|
33
|
-
private _trackedWatch;
|
|
34
|
-
/** @internal */
|
|
35
|
-
private _untrackedGet;
|
|
36
|
-
/** @internal */
|
|
37
|
-
private _untrackedWatch;
|
|
38
|
-
/** @internal */
|
|
39
|
-
private _trackedExec;
|
|
40
|
-
/** @internal */
|
|
41
|
-
private _untrackedExec;
|
|
42
|
-
/**
|
|
43
|
-
* @internal
|
|
44
|
-
* Executes the compute function if necessary to update the derived value.
|
|
45
|
-
*/
|
|
46
|
-
_exec(): void;
|
|
47
|
-
/**
|
|
48
|
-
* @internal
|
|
49
|
-
* Marks the derivation as dirty and notifies downstream dependencies.
|
|
50
|
-
*/
|
|
51
|
-
_notify(): void;
|
|
52
|
-
/**
|
|
53
|
-
* @internal
|
|
54
|
-
* Ensures that the derivation is up-to-date when it is watched.
|
|
55
|
-
*/
|
|
56
|
-
_watch(): void;
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=derivation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"derivation.d.ts","sourceRoot":"","sources":["../../src/derivation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;GAMG;AACH,qBAAa,cAAc,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IAEpD;;;;;OAKG;gBACS,OAAO,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,KAAK,CAAC;IAM/D;;;;;;OAMG;IACI,GAAG,IAAI,CAAC;IAOf,gBAAgB;IAChB,OAAO,CAAC,YAAY,CAAS;IAE7B,gBAAgB;IAChB,OAAO,CAAC,MAAM,CAAQ;IAEtB,gBAAgB;IAChB,OAAO,CAAC,WAAW,CAAyD;IAE5E,gBAAgB;IAChB,OAAO,CAAC,aAAa,CAAoD;IAEzE,gBAAgB;IAChB,OAAO,CAAC,aAAa,CAAgD;IAErE,gBAAgB;IAChB,OAAO,CAAC,eAAe,CAA4C;IAEnE,gBAAgB;IAChB,OAAO,CAAC,YAAY,CAAU;IAE9B,gBAAgB;IAChB,OAAO,CAAC,cAAc,CAAU;IAEhC;;;OAGG;IACH,KAAK,IAAI,IAAI;IAab;;;OAGG;IACM,OAAO,IAAI,IAAI;IAKxB;;;OAGG;IACM,MAAM,IAAI,IAAI;CAG1B"}
|
package/dist/types/effect.d.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { FlowGetter } from './observable';
|
|
2
|
-
import { FlowSignal, FlowWatcher } from './signal';
|
|
3
|
-
/**
|
|
4
|
-
* Represents a reactive effect that executes a side‐effect function
|
|
5
|
-
* based on its tracked dependencies.
|
|
6
|
-
*
|
|
7
|
-
* @remarks
|
|
8
|
-
* A FlowEffect runs an apply function to perform side effects. The apply function
|
|
9
|
-
* is executed in two modes:
|
|
10
|
-
* Initially, in a tracked mode to register dependencies.
|
|
11
|
-
* Subsequently, in an untracked mode to only re-execute the effect .
|
|
12
|
-
*
|
|
13
|
-
* @public
|
|
14
|
-
*/
|
|
15
|
-
export declare class FlowEffect {
|
|
16
|
-
/**
|
|
17
|
-
* Creates a new FlowEffect.
|
|
18
|
-
*
|
|
19
|
-
* @param apply - A function that performs the side effect. It receives a getter and a watcher
|
|
20
|
-
* function to access and register dependencies on reactive observables and signals.
|
|
21
|
-
*
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
constructor(apply: (get: FlowGetter, watch: FlowWatcher) => void);
|
|
25
|
-
/**
|
|
26
|
-
* Disposes the effect, unregistering all its dependencies.
|
|
27
|
-
*
|
|
28
|
-
* @remarks
|
|
29
|
-
* After disposal, the effect should no longer be used. Calling this method on an already
|
|
30
|
-
* disposed effect will throw an error.
|
|
31
|
-
*
|
|
32
|
-
* @public
|
|
33
|
-
*/
|
|
34
|
-
dispose(): void;
|
|
35
|
-
/**
|
|
36
|
-
* Indicates whether this effect has been disposed.
|
|
37
|
-
*
|
|
38
|
-
* @returns A boolean value indicating if the effect is disposed.
|
|
39
|
-
*
|
|
40
|
-
* @public
|
|
41
|
-
*/
|
|
42
|
-
get disposed(): boolean;
|
|
43
|
-
/**
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
private _disposed;
|
|
47
|
-
/**
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
private _initialized;
|
|
51
|
-
/**
|
|
52
|
-
* @internal
|
|
53
|
-
*/
|
|
54
|
-
private _dependencies;
|
|
55
|
-
/**
|
|
56
|
-
* @internal
|
|
57
|
-
* A tracked getter that registers a dependency when accessing an observable.
|
|
58
|
-
*/
|
|
59
|
-
private _trackedGet;
|
|
60
|
-
/**
|
|
61
|
-
* @internal
|
|
62
|
-
* A tracked watcher that registers a dependency when watching a signal.
|
|
63
|
-
*/
|
|
64
|
-
private _trackedWatch;
|
|
65
|
-
/**
|
|
66
|
-
* @internal
|
|
67
|
-
* An untracked getter that simply retrieves the current value from an observable.
|
|
68
|
-
*/
|
|
69
|
-
private _untrackedGet;
|
|
70
|
-
/**
|
|
71
|
-
* @internal
|
|
72
|
-
* An untracked watcher that calls the default watch on a signal.
|
|
73
|
-
*/
|
|
74
|
-
private _untrackedWatch;
|
|
75
|
-
/**
|
|
76
|
-
* @internal
|
|
77
|
-
* Execution function used during initialization (tracked mode).
|
|
78
|
-
*/
|
|
79
|
-
private _trackedExec;
|
|
80
|
-
/**
|
|
81
|
-
* @internal
|
|
82
|
-
* Execution function used after initialization (untracked mode).
|
|
83
|
-
*/
|
|
84
|
-
private _untrackedExec;
|
|
85
|
-
/**
|
|
86
|
-
* @internal
|
|
87
|
-
* Executes the effect. If the effect has not been initialized, it runs in tracked mode;
|
|
88
|
-
* otherwise, it runs in untracked mode.
|
|
89
|
-
*
|
|
90
|
-
* @throws Error if the effect has been disposed.
|
|
91
|
-
*/
|
|
92
|
-
_exec(): void;
|
|
93
|
-
/**
|
|
94
|
-
* @internal
|
|
95
|
-
* Registers a dependency on the given signal.
|
|
96
|
-
*
|
|
97
|
-
* @param dependency - The FlowSignal to register as a dependency.
|
|
98
|
-
*/
|
|
99
|
-
_registerDependency(dependency: FlowSignal): void;
|
|
100
|
-
/**
|
|
101
|
-
* @internal
|
|
102
|
-
* Unregisters the given dependency.
|
|
103
|
-
*
|
|
104
|
-
* @param dependency - The FlowSignal to unregister.
|
|
105
|
-
*/
|
|
106
|
-
_unregisterDependency(dependency: FlowSignal): void;
|
|
107
|
-
}
|
|
108
|
-
//# sourceMappingURL=effect.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../src/effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,qBAAa,UAAU;IAGnB;;;;;;;OAOG;gBACS,KAAK,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI;IAMhE;;;;;;;;OAQG;IACI,OAAO,IAAI,IAAI;IAQtB;;;;;;OAMG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAID;;OAEG;IACH,OAAO,CAAC,SAAS,CAAS;IAE1B;;OAEG;IACH,OAAO,CAAC,YAAY,CAAS;IAE7B;;OAEG;IACH,OAAO,CAAC,aAAa,CAAyB;IAE9C;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAyD;IAE5E;;;OAGG;IACH,OAAO,CAAC,aAAa,CAAoD;IAEzE;;;OAGG;IACH,OAAO,CAAC,aAAa,CAAgD;IAErE;;;OAGG;IACH,OAAO,CAAC,eAAe,CAA4C;IAEnE;;;OAGG;IACH,OAAO,CAAC,YAAY,CAAa;IAEjC;;;OAGG;IACH,OAAO,CAAC,cAAc,CAAa;IAEnC;;;;;;OAMG;IACH,KAAK,IAAI,IAAI;IASb;;;;;OAKG;IACH,mBAAmB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAKjD;;;;;OAKG;IACH,qBAAqB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;CAItD"}
|
package/dist/types/map.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,OAAO,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEnD;;;;;;;;OAQG;IACI,QAAQ,EAAE,SAAS,CAAC;QAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,CAAC,CAAA;KAAE,CAAC,CAAqB;IAEvE;;;;;;;;OAQG;IACI,YAAY,EAAE,SAAS,CAAC;QAAE,GAAG,CAAC,EAAE,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,CAAC,CAAA;KAAE,CAAC,CAAqB;IAE3E;;;;;;;;;;;OAWG;IACI,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAOpC;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI;CAO9B"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { FlowEffect } from './effect';
|
|
2
|
-
import { FlowSignal } from './signal';
|
|
3
|
-
/**
|
|
4
|
-
* A function for retrieving the current value from a FlowObservable.
|
|
5
|
-
* @typeparam T - The type of the value held by the observable.
|
|
6
|
-
* @param atom - The FlowObservable from which to get the value.
|
|
7
|
-
* @returns The current value of the observable.
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
export type FlowGetter = <T>(observable: FlowObservable<T>) => T;
|
|
11
|
-
/**
|
|
12
|
-
* Represents a reactive observable that carries a value.
|
|
13
|
-
* @typeparam T - The type of the value held by the observable.
|
|
14
|
-
* @remarks
|
|
15
|
-
* A FlowObservable extends the basic FlowSignal to store a value. Subclasses must
|
|
16
|
-
* implement the abstract {@link FlowObservable.get} method to return the current value.
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
export declare abstract class FlowObservable<T> extends FlowSignal {
|
|
20
|
-
/**
|
|
21
|
-
* Retrieves the current value of the observable.
|
|
22
|
-
* @returns The current value.
|
|
23
|
-
* @public
|
|
24
|
-
*/
|
|
25
|
-
abstract get(): T;
|
|
26
|
-
/**
|
|
27
|
-
* @internal
|
|
28
|
-
* Internal storage for the observable's value.
|
|
29
|
-
*/
|
|
30
|
-
protected _value: T;
|
|
31
|
-
/**
|
|
32
|
-
* @internal
|
|
33
|
-
* Retrieves the current value from the observable and registers a dependency
|
|
34
|
-
* from the provided listener.
|
|
35
|
-
* @param listener - The FlowObservable or FlowEffect that is accessing this observable.
|
|
36
|
-
* @returns The current value, as returned by {@link FlowObservable.get}.
|
|
37
|
-
*/
|
|
38
|
-
_getFrom(listener: FlowObservable<unknown> | FlowEffect): T;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=observable.d.ts.map
|