@thi.ng/rstream 8.5.0 → 8.5.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/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/atom.d.ts +7 -5
- package/bisect.d.ts +15 -6
- package/debounce.d.ts +4 -3
- package/event.d.ts +0 -2
- package/merge.d.ts +8 -5
- package/metastream.d.ts +31 -21
- package/nodejs.d.ts +2 -3
- package/object.d.ts +13 -10
- package/package.json +14 -14
- package/post-worker.d.ts +4 -4
- package/promises.d.ts +2 -16
- package/resolve.d.ts +3 -3
- package/sidechain-partition.d.ts +9 -7
- package/sidechain-toggle.d.ts +11 -5
- package/sidechain-trigger.d.ts +1 -2
- package/stream.d.ts +3 -3
- package/subscription.d.ts +6 -3
- package/sync-raf.d.ts +1 -2
- package/sync.d.ts +14 -4
- package/toggle.d.ts +1 -1
- package/transduce.d.ts +1 -1
- package/tween.d.ts +8 -5
- package/view.d.ts +10 -5
- package/worker.d.ts +0 -5
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 193 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
package/atom.d.ts
CHANGED
|
@@ -32,14 +32,16 @@ export interface FromAtomOpts<T> extends CommonOpts {
|
|
|
32
32
|
* Also see {@link fromView}, {@link fromViewUnsafe}
|
|
33
33
|
*
|
|
34
34
|
* @example
|
|
35
|
-
* ```ts
|
|
35
|
+
* ```ts tangle:../export/from-atom.ts
|
|
36
36
|
* import { defAtom, defCursor } from "@thi.ng/atom";
|
|
37
|
-
* import {
|
|
37
|
+
* import { fromAtom, trace } from "@thi.ng/rstream";
|
|
38
38
|
*
|
|
39
|
-
*
|
|
40
|
-
* cursor = defCursor(db, "a")
|
|
39
|
+
* type DB = { a: number; b?: number };
|
|
41
40
|
*
|
|
42
|
-
*
|
|
41
|
+
* const db = defAtom<DB>({ a: 23, b: 88 });
|
|
42
|
+
* const cursor = defCursor(db, ["a"])
|
|
43
|
+
*
|
|
44
|
+
* fromAtom(cursor).subscribe(trace("cursor val:"))
|
|
43
45
|
* // cursor val: 23
|
|
44
46
|
*
|
|
45
47
|
* cursor.reset(42);
|
package/bisect.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { PubSub } from "./pubsub.js";
|
|
|
12
12
|
* kept prior to calling `bisect()`.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
* ```ts
|
|
15
|
+
* ```ts tangle:../export/bisect.ts
|
|
16
16
|
* import { bisect, fromIterable, trace } from "@thi.ng/rstream";
|
|
17
17
|
*
|
|
18
18
|
* fromIterable([1, 2, 3, 4]).subscribe(
|
|
@@ -31,19 +31,28 @@ import { PubSub } from "./pubsub.js";
|
|
|
31
31
|
* ```
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* import { bisect, subscription, trace } from "@thi.ng/rstream";
|
|
34
|
+
* ```ts tangle:../export/bisect-2.ts
|
|
35
|
+
* import { bisect, fromIterable, subscription, trace } from "@thi.ng/rstream";
|
|
36
36
|
* import { map } from "@thi.ng/transducers";
|
|
37
37
|
*
|
|
38
|
-
* const odd = subscription();
|
|
39
|
-
* const even = subscription();
|
|
38
|
+
* const odd = subscription<number, number>();
|
|
39
|
+
* const even = subscription<number, number>();
|
|
40
40
|
* odd.subscribe(trace("odd"));
|
|
41
|
-
* odd.subscribe(trace("odd x10"), { xform: map((x) => x * 10) });
|
|
41
|
+
* odd.subscribe(trace("odd x10"), { xform: map((x: number) => x * 10) });
|
|
42
42
|
* even.subscribe(trace("even"));
|
|
43
43
|
*
|
|
44
44
|
* fromIterable([1, 2, 3, 4]).subscribe(
|
|
45
45
|
* bisect((x) => !!(x & 1), odd, even)
|
|
46
46
|
* );
|
|
47
|
+
* // odd x10 10
|
|
48
|
+
* // odd 1
|
|
49
|
+
* // even 2
|
|
50
|
+
* // odd x10 30
|
|
51
|
+
* // odd 3
|
|
52
|
+
* // even 4
|
|
53
|
+
* // odd x10 done
|
|
54
|
+
* // odd done
|
|
55
|
+
* // even done
|
|
47
56
|
* ```
|
|
48
57
|
*
|
|
49
58
|
* @param pred - predicate function
|
package/debounce.d.ts
CHANGED
|
@@ -5,12 +5,13 @@ import { type MetaStreamOpts } from "./metastream.js";
|
|
|
5
5
|
* milliseconds.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* import { debounce, fromIterable } from "@thi.ng/rstream";
|
|
8
|
+
* ```ts tangle:../export/debounce.ts
|
|
9
|
+
* import { debounce, fromIterable, trace } from "@thi.ng/rstream";
|
|
10
10
|
*
|
|
11
11
|
* const src = fromIterable([1, 2, 3], { delay: 10 })
|
|
12
|
-
* src.subscribe(debounce(20)).subscribe(
|
|
12
|
+
* src.subscribe(debounce(20)).subscribe(trace());
|
|
13
13
|
* // 3
|
|
14
|
+
* // done
|
|
14
15
|
* ```
|
|
15
16
|
*
|
|
16
17
|
* @param delay -
|
package/event.d.ts
CHANGED
package/merge.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface StreamMergeOpts<A, B> extends TransformableOpts<A, B> {
|
|
|
17
17
|
* {@link StreamMergeOpts | options}.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
|
-
* ```ts
|
|
20
|
+
* ```ts tangle:../export/merge.ts
|
|
21
21
|
* import { fromIterable, merge, trace } from "@thi.ng/rstream";
|
|
22
22
|
*
|
|
23
23
|
* merge({
|
|
@@ -37,6 +37,7 @@ export interface StreamMergeOpts<A, B> extends TransformableOpts<A, B> {
|
|
|
37
37
|
* // 3
|
|
38
38
|
* // 20
|
|
39
39
|
* // 30
|
|
40
|
+
* // done
|
|
40
41
|
* ```
|
|
41
42
|
*
|
|
42
43
|
* @example
|
|
@@ -46,13 +47,14 @@ export interface StreamMergeOpts<A, B> extends TransformableOpts<A, B> {
|
|
|
46
47
|
* track their provenance:
|
|
47
48
|
*
|
|
48
49
|
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* import { fromIterable, merge } from "@thi.ng/rstream";
|
|
50
|
+
* ```ts tangle:../export/merge-2.ts
|
|
51
|
+
* import { fromIterable, merge, trace } from "@thi.ng/rstream";
|
|
52
|
+
* import { labeled } from "@thi.ng/transducers";
|
|
51
53
|
*
|
|
52
54
|
* merge({
|
|
53
55
|
* src: [
|
|
54
|
-
* fromIterable([1, 2, 3]).transform(
|
|
55
|
-
* fromIterable([10, 20, 30]).transform(
|
|
56
|
+
* fromIterable([1, 2, 3]).transform(labeled("a")),
|
|
57
|
+
* fromIterable([10, 20, 30]).transform(labeled("b")),
|
|
56
58
|
* ]
|
|
57
59
|
* }).subscribe(trace());
|
|
58
60
|
* // ["a", 1]
|
|
@@ -61,6 +63,7 @@ export interface StreamMergeOpts<A, B> extends TransformableOpts<A, B> {
|
|
|
61
63
|
* // ["b", 20]
|
|
62
64
|
* // ["a", 3]
|
|
63
65
|
* // ["b", 30]
|
|
66
|
+
* // done
|
|
64
67
|
* ```
|
|
65
68
|
*
|
|
66
69
|
* @param opts -
|
package/metastream.d.ts
CHANGED
|
@@ -36,14 +36,14 @@ export interface MetaStreamOpts extends CommonOpts {
|
|
|
36
36
|
* dynamic switching between them.
|
|
37
37
|
*
|
|
38
38
|
* @example
|
|
39
|
-
* ```ts
|
|
39
|
+
* ```ts tangle:../export/metastream.ts
|
|
40
40
|
* import { fromIterable, metaStream, trace } from "@thi.ng/rstream";
|
|
41
41
|
* import { repeat } from "@thi.ng/transducers";
|
|
42
42
|
*
|
|
43
43
|
* // transform each received odd number into a stream
|
|
44
44
|
* // producing 3 copies of that number in the metastream
|
|
45
45
|
* // even numbers are ignored
|
|
46
|
-
* a = metaStream(
|
|
46
|
+
* const a = metaStream<number, number>(
|
|
47
47
|
* (x) => (x & 1)
|
|
48
48
|
* ? fromIterable(repeat(x, 3), { delay: 100 })
|
|
49
49
|
* : null
|
|
@@ -56,41 +56,51 @@ export interface MetaStreamOpts extends CommonOpts {
|
|
|
56
56
|
* // 23
|
|
57
57
|
* // 23
|
|
58
58
|
*
|
|
59
|
-
* a.next(42) // ignored by
|
|
59
|
+
* setTimeout(() => a.next(42), 500); // value 42 ignored by metastream
|
|
60
60
|
*
|
|
61
|
-
* a.next(43)
|
|
61
|
+
* setTimeout(() => a.next(43), 1000);
|
|
62
62
|
* // 43
|
|
63
63
|
* // 43
|
|
64
64
|
* // 43
|
|
65
65
|
* ```
|
|
66
66
|
*
|
|
67
67
|
* @example
|
|
68
|
-
* ```ts
|
|
69
|
-
* import { fromIterable, metaStream, trace
|
|
70
|
-
* import { repeat } from "@thi.ng/transducers";
|
|
68
|
+
* ```ts tangle:../export/metastream-2.ts
|
|
69
|
+
* import { CloseMode, fromIterable, metaStream, trace } from "@thi.ng/rstream";
|
|
70
|
+
* import { cycle, repeat } from "@thi.ng/transducers";
|
|
71
71
|
*
|
|
72
|
-
* // infinite inputs
|
|
73
|
-
* a = fromIterable(
|
|
72
|
+
* // infinite inputs (important: closeOut mode = never!)
|
|
73
|
+
* const a = fromIterable(
|
|
74
74
|
* repeat("a"),
|
|
75
|
-
* { delay:
|
|
75
|
+
* { delay: 100, closeOut: CloseMode.NEVER }
|
|
76
76
|
* );
|
|
77
|
-
* b = fromIterable(
|
|
77
|
+
* const b = fromIterable(
|
|
78
78
|
* repeat("b"),
|
|
79
|
-
* { delay:
|
|
79
|
+
* { delay: 100, closeOut: CloseMode.NEVER }
|
|
80
80
|
* );
|
|
81
81
|
*
|
|
82
82
|
* // stream selector / switch
|
|
83
|
-
* m = metaStream((x) => x ? a : b);
|
|
83
|
+
* const m = metaStream<boolean, string>((x) => (x ? a : b));
|
|
84
84
|
* m.subscribe(trace("meta from: "));
|
|
85
85
|
*
|
|
86
|
-
*
|
|
87
|
-
* //
|
|
88
|
-
*
|
|
89
|
-
* m.next(
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* //
|
|
86
|
+
* // create infinite stream of true/false and pipe into
|
|
87
|
+
* // the metastream and switch which source to use
|
|
88
|
+
* fromIterable(cycle([true, false]), { delay: 500 })
|
|
89
|
+
* .subscribe({ next(x) { m.next(x); } });
|
|
90
|
+
*
|
|
91
|
+
* // a
|
|
92
|
+
* // a
|
|
93
|
+
* // a
|
|
94
|
+
* // a
|
|
95
|
+
* // a
|
|
96
|
+
* // b
|
|
97
|
+
* // b
|
|
98
|
+
* // b
|
|
99
|
+
* // b
|
|
100
|
+
* // b
|
|
101
|
+
* // a
|
|
102
|
+
* // a
|
|
103
|
+
* // ...
|
|
94
104
|
* ```
|
|
95
105
|
*
|
|
96
106
|
* @param factory -
|
package/nodejs.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { Readable } from "node:stream";
|
|
3
2
|
import { type Stream } from "./stream.js";
|
|
4
3
|
import type { Subscription } from "./subscription.js";
|
|
@@ -23,9 +22,9 @@ export declare const fromNodeJS: <T>(stdout: Readable, stderr?: Readable, close?
|
|
|
23
22
|
* to rechunk input.
|
|
24
23
|
*
|
|
25
24
|
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* import { spawn } from "node:child_process"
|
|
25
|
+
* ```ts tangle:../export/lines-from-nodejs.ts
|
|
28
26
|
* import { linesFromNodeJS, trace } from "@thi.ng/rstream";
|
|
27
|
+
* import { spawn } from "node:child_process"
|
|
29
28
|
*
|
|
30
29
|
* const cmd = spawn("ls", ["-la"]);
|
|
31
30
|
*
|
package/object.d.ts
CHANGED
|
@@ -90,28 +90,31 @@ export interface StreamObjOpts<T, K extends Keys<T>> extends CommonOpts {
|
|
|
90
90
|
* `fromObject` and specify shared options for *all* created streams.
|
|
91
91
|
*
|
|
92
92
|
* @example
|
|
93
|
-
* ```ts
|
|
94
|
-
* import { fromObject } from "@thi.ng/rstream";
|
|
93
|
+
* ```ts tangle:../export/from-object.ts
|
|
94
|
+
* import { fromObject, trace } from "@thi.ng/rstream";
|
|
95
95
|
*
|
|
96
96
|
* type Foo = { a?: number; b: string; };
|
|
97
97
|
*
|
|
98
|
-
* const obj = fromObject(<Foo>{ a: 1, b: "foo" })
|
|
98
|
+
* const obj = fromObject(<Foo>{ a: 1, b: "foo" });
|
|
99
99
|
*
|
|
100
|
-
* obj.streams.a.subscribe(trace("a"))
|
|
100
|
+
* obj.streams.a.subscribe(trace("a"));
|
|
101
101
|
* // a 1
|
|
102
|
-
*
|
|
102
|
+
*
|
|
103
|
+
* obj.streams.b.subscribe(trace("b"));
|
|
103
104
|
* // b foo
|
|
104
105
|
*
|
|
105
|
-
* obj.next({ b: "bar" })
|
|
106
|
+
* obj.next({ b: "bar" });
|
|
106
107
|
* // a undefined
|
|
107
108
|
* // b bar
|
|
108
109
|
* ```
|
|
109
110
|
*
|
|
110
111
|
* @example
|
|
111
|
-
* ```ts
|
|
112
|
-
* import { fromObject, trace } from "@thi.ng/rstream";
|
|
112
|
+
* ```ts tangle:../export/from-object-2.ts
|
|
113
|
+
* import { fromObject, subscription, trace } from "@thi.ng/rstream";
|
|
114
|
+
*
|
|
115
|
+
* type Foo = { a?: number; b: string; };
|
|
113
116
|
*
|
|
114
|
-
* const obj = fromObject(<Foo>{}, ["a", "b"],
|
|
117
|
+
* const obj = fromObject(<Foo>{}, { keys: ["a", "b"], initial: false });
|
|
115
118
|
* obj.streams.a.subscribe(trace("a"));
|
|
116
119
|
* obj.streams.b.subscribe(trace("b"));
|
|
117
120
|
*
|
|
@@ -127,5 +130,5 @@ export interface StreamObjOpts<T, K extends Keys<T>> extends CommonOpts {
|
|
|
127
130
|
* @param src -
|
|
128
131
|
* @param opts -
|
|
129
132
|
*/
|
|
130
|
-
export declare const fromObject: <T extends object, K extends
|
|
133
|
+
export declare const fromObject: <T extends object, K extends Keys<T>>(src: T, opts?: Partial<StreamObjOpts<T, K>>) => StreamObj<T, K>;
|
|
131
134
|
//# sourceMappingURL=object.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/rstream",
|
|
3
|
-
"version": "8.5.
|
|
3
|
+
"version": "8.5.1",
|
|
4
4
|
"description": "Reactive streams & subscription primitives for constructing dataflow graphs / pipelines",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/rstream",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -40,20 +40,20 @@
|
|
|
40
40
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@thi.ng/api": "^8.11.
|
|
44
|
-
"@thi.ng/arrays": "^2.9.
|
|
45
|
-
"@thi.ng/associative": "^6.3.
|
|
46
|
-
"@thi.ng/atom": "^5.3.
|
|
47
|
-
"@thi.ng/checks": "^3.6.
|
|
48
|
-
"@thi.ng/errors": "^2.5.
|
|
49
|
-
"@thi.ng/logger": "^3.0.
|
|
50
|
-
"@thi.ng/transducers": "^9.0.
|
|
43
|
+
"@thi.ng/api": "^8.11.3",
|
|
44
|
+
"@thi.ng/arrays": "^2.9.7",
|
|
45
|
+
"@thi.ng/associative": "^6.3.61",
|
|
46
|
+
"@thi.ng/atom": "^5.3.1",
|
|
47
|
+
"@thi.ng/checks": "^3.6.5",
|
|
48
|
+
"@thi.ng/errors": "^2.5.8",
|
|
49
|
+
"@thi.ng/logger": "^3.0.13",
|
|
50
|
+
"@thi.ng/transducers": "^9.0.6"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@microsoft/api-extractor": "^7.
|
|
54
|
-
"esbuild": "^0.21.
|
|
53
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
54
|
+
"esbuild": "^0.21.5",
|
|
55
55
|
"typedoc": "^0.25.13",
|
|
56
|
-
"typescript": "^5.
|
|
56
|
+
"typescript": "^5.5.2"
|
|
57
57
|
},
|
|
58
58
|
"keywords": [
|
|
59
59
|
"async",
|
|
@@ -218,5 +218,5 @@
|
|
|
218
218
|
],
|
|
219
219
|
"year": 2017
|
|
220
220
|
},
|
|
221
|
-
"gitHead": "
|
|
221
|
+
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
|
|
222
222
|
}
|
package/post-worker.d.ts
CHANGED
|
@@ -16,15 +16,15 @@ import type { ISubscriber } from "./api.js";
|
|
|
16
16
|
* since the parent subscription is {@link ISubscriber.done}.
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
|
-
* ```ts
|
|
19
|
+
* ```ts tangle:../export/post-worker.ts
|
|
20
20
|
* import { postWorker, stream } from "@thi.ng/rstream";
|
|
21
21
|
*
|
|
22
22
|
* // worker source code
|
|
23
|
-
* src = `self.onmessage = (e) => console.log("worker", e.data);`;
|
|
23
|
+
* const src = `self.onmessage = (e) => console.log("worker", e.data);`;
|
|
24
24
|
*
|
|
25
|
-
* a = stream();
|
|
25
|
+
* const a = stream<any>();
|
|
26
26
|
* a.subscribe(
|
|
27
|
-
* postWorker(src, { type: "application/javascript" }))
|
|
27
|
+
* postWorker(new Blob([src], { type: "application/javascript" }))
|
|
28
28
|
* );
|
|
29
29
|
*
|
|
30
30
|
* a.next(42)
|
package/promises.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ import type { ISubscription, WithErrorHandlerOpts } from "./api.js";
|
|
|
10
10
|
* Also see {@link fromPromise}, {@link resolve}.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { fromPromises } from "@thi.ng/rstream";
|
|
13
|
+
* ```ts tangle:../export/from-promises.ts
|
|
14
|
+
* import { fromPromises, trace } from "@thi.ng/rstream";
|
|
15
15
|
*
|
|
16
16
|
* fromPromises([
|
|
17
17
|
* Promise.resolve(1),
|
|
@@ -24,20 +24,6 @@ import type { ISubscription, WithErrorHandlerOpts } from "./api.js";
|
|
|
24
24
|
* // done
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
|
-
* @example
|
|
28
|
-
* If individual error handling is required, an alternative is below
|
|
29
|
-
* (however this approach provides no ordering guarantees):
|
|
30
|
-
*
|
|
31
|
-
* ```ts
|
|
32
|
-
* import { fromIterable, resolve, trace } from "@thi.ng/rstream";
|
|
33
|
-
*
|
|
34
|
-
* fromIterable([
|
|
35
|
-
* Promise.resolve(1),
|
|
36
|
-
* new Promise(() => setTimeout(() => { throw new Error("eeek"); }, 10)),
|
|
37
|
-
* Promise.resolve(3)
|
|
38
|
-
* ]).subscribe(resolve()).subscribe(trace())
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
27
|
* @param promises -
|
|
42
28
|
* @param opts -
|
|
43
29
|
*/
|
package/resolve.d.ts
CHANGED
|
@@ -17,14 +17,14 @@ export interface ResolverOpts extends IID<string> {
|
|
|
17
17
|
* from receiving further values.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
|
-
* ```ts
|
|
20
|
+
* ```ts tangle:../export/resolve.ts
|
|
21
21
|
* import { fromIterable, resolve, trace } from "@thi.ng/rstream";
|
|
22
22
|
* import { delayed } from "@thi.ng/transducers";
|
|
23
23
|
*
|
|
24
|
-
* fromIterable([1, 2, 3],
|
|
24
|
+
* fromIterable([1, 2, 3], 500)
|
|
25
25
|
* .transform(delayed(1000))
|
|
26
26
|
* .subscribe(resolve())
|
|
27
|
-
* .subscribe(trace("result"))
|
|
27
|
+
* .subscribe(trace("result"));
|
|
28
28
|
* // result 1
|
|
29
29
|
* // result 2
|
|
30
30
|
* // result 3
|
package/sidechain-partition.d.ts
CHANGED
|
@@ -17,15 +17,17 @@ export interface SidechainPartitionOpts<T> extends CommonOpts {
|
|
|
17
17
|
* Also see: {@link sidechainToggle}, {@link sidechainTrigger}, {@link syncRAF}.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
|
-
* ```ts
|
|
20
|
+
* ```ts tangle:../export/sidechain-partition.ts
|
|
21
21
|
* import { fromEvent, fromRAF, merge, sidechainPartition, trace } from "@thi.ng/rstream";
|
|
22
22
|
*
|
|
23
23
|
* // merge various event streams
|
|
24
|
-
* events = merge(
|
|
24
|
+
* const events = merge({
|
|
25
|
+
* src: [
|
|
25
26
|
* fromEvent(document,"mousemove"),
|
|
26
27
|
* fromEvent(document,"mousedown"),
|
|
27
28
|
* fromEvent(document,"mouseup")
|
|
28
|
-
*
|
|
29
|
+
* ]
|
|
30
|
+
* });
|
|
29
31
|
*
|
|
30
32
|
* // queue event processing to only execute during the
|
|
31
33
|
* // requestAnimationFrame cycle (RAF)
|
|
@@ -51,15 +53,15 @@ export declare const sidechainPartition: <T, S>(src: ISubscribable<T>, side: ISu
|
|
|
51
53
|
* and {@link syncRAF}.
|
|
52
54
|
*
|
|
53
55
|
* @example
|
|
54
|
-
* ```ts
|
|
56
|
+
* ```ts tangle:../export/sidechain-partition-raf.ts
|
|
55
57
|
* import { defAtom } from "@thi.ng/atom";
|
|
56
|
-
* import {
|
|
58
|
+
* import { fromAtom, sidechainPartitionRAF } from "@thi.ng/rstream";
|
|
57
59
|
*
|
|
58
60
|
* const atom = defAtom("alice");
|
|
59
61
|
*
|
|
60
62
|
* // any change to the atom will only be applied during next RAF update
|
|
61
|
-
*
|
|
62
|
-
* next(
|
|
63
|
+
* sidechainPartitionRAF(fromAtom(atom)).subscribe({
|
|
64
|
+
* next(name) { document.body.innerText = name; }
|
|
63
65
|
* });
|
|
64
66
|
*
|
|
65
67
|
* // trigger update
|
package/sidechain-toggle.d.ts
CHANGED
|
@@ -17,17 +17,23 @@ export interface SidechainToggleOpts<T> extends CommonOpts {
|
|
|
17
17
|
* forwarded downstream.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
|
-
* ```ts
|
|
20
|
+
* ```ts tangle:../export/sidechain-toggle.ts
|
|
21
21
|
* import { fromInterval, sidechainToggle, trace } from "@thi.ng/rstream";
|
|
22
22
|
*
|
|
23
|
+
* const src = fromInterval(500);
|
|
24
|
+
*
|
|
25
|
+
* // close stream after 5 secs
|
|
26
|
+
* setTimeout(() => src.done(), 5000);
|
|
27
|
+
*
|
|
23
28
|
* // use slower interval stream to toggle faster main stream on/off
|
|
24
|
-
* sidechainToggle(
|
|
29
|
+
* sidechainToggle(src, fromInterval(1000)).subscribe(trace());
|
|
25
30
|
* // 0
|
|
26
|
-
* //
|
|
31
|
+
* // 1
|
|
27
32
|
* // 4
|
|
28
|
-
* //
|
|
33
|
+
* // 5
|
|
29
34
|
* // 8
|
|
30
|
-
*
|
|
35
|
+
* // 9
|
|
36
|
+
* // done
|
|
31
37
|
* ```
|
|
32
38
|
*
|
|
33
39
|
* @param src -
|
package/sidechain-trigger.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface SidechainTriggerOpts<T> extends CommonOpts {
|
|
|
18
18
|
* downstream.
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
|
-
* ```ts
|
|
21
|
+
* ```ts tangle:../export/sidechain-trigger.ts
|
|
22
22
|
* import { reactive, stream, sidechainTrigger, trace } from "@thi.ng/rstream";
|
|
23
23
|
*
|
|
24
24
|
* const src = reactive("payload");
|
|
@@ -40,7 +40,6 @@ export interface SidechainTriggerOpts<T> extends CommonOpts {
|
|
|
40
40
|
* // ...until side chain triggers again
|
|
41
41
|
* side.next(1);
|
|
42
42
|
* // data: update #2
|
|
43
|
-
* ...
|
|
44
43
|
* ```
|
|
45
44
|
*
|
|
46
45
|
* @param src
|
package/stream.d.ts
CHANGED
|
@@ -27,10 +27,10 @@ import { Subscription } from "./subscription.js";
|
|
|
27
27
|
* disabled or if the stream is done, it will deref to `undefined`.
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
|
-
* ```ts
|
|
30
|
+
* ```ts tangle:../export/stream.ts
|
|
31
31
|
* import { stream, subscription, trace } from "@thi.ng/rstream";
|
|
32
32
|
*
|
|
33
|
-
* a = stream((s) => {
|
|
33
|
+
* const a = stream((s) => {
|
|
34
34
|
* s.next(1);
|
|
35
35
|
* s.next(2);
|
|
36
36
|
* s.done()
|
|
@@ -41,7 +41,7 @@ import { Subscription } from "./subscription.js";
|
|
|
41
41
|
* // a done
|
|
42
42
|
*
|
|
43
43
|
* // as reactive value mechanism
|
|
44
|
-
* b = stream();
|
|
44
|
+
* const b = stream();
|
|
45
45
|
* // or alternatively
|
|
46
46
|
* // b = subscription();
|
|
47
47
|
*
|
package/subscription.d.ts
CHANGED
|
@@ -32,14 +32,17 @@ import { CloseMode, State, type CommonOpts, type ISubscriber, type ISubscription
|
|
|
32
32
|
* arg. See {@link CommonOpts} and {@link SubscriptionOpts} for further details.
|
|
33
33
|
*
|
|
34
34
|
* @example
|
|
35
|
-
* ```ts
|
|
35
|
+
* ```ts tangle:../export/subscription.ts
|
|
36
36
|
* import { subscription, trace } from "@thi.ng/rstream";
|
|
37
37
|
* import { filter } from "@thi.ng/transducers";
|
|
38
38
|
*
|
|
39
39
|
* // as reactive value mechanism (same as with stream() above)
|
|
40
|
-
* s = subscription();
|
|
40
|
+
* const s = subscription<number, number>();
|
|
41
|
+
*
|
|
42
|
+
* // attach child subscriptions
|
|
41
43
|
* s.subscribe(trace("s1"));
|
|
42
|
-
*
|
|
44
|
+
* // this child sub will receive filtered values only
|
|
45
|
+
* s.subscribe(trace("s2"), { xform: filter((x: number) => x > 25) });
|
|
43
46
|
*
|
|
44
47
|
* // external trigger
|
|
45
48
|
* s.next(23);
|
package/sync-raf.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { type CommonOpts, type ISubscribable } from "./api.js";
|
|
3
2
|
import { Subscription } from "./subscription.js";
|
|
4
3
|
/**
|
|
@@ -13,7 +12,7 @@ import { Subscription } from "./subscription.js";
|
|
|
13
12
|
* See {@link sidechainTrigger} from a similar & more general construct.
|
|
14
13
|
*
|
|
15
14
|
* @example
|
|
16
|
-
* ```ts
|
|
15
|
+
* ```ts tangle:../export/sync-raf.ts
|
|
17
16
|
* import { defAtom } from "@thi.ng/atom";
|
|
18
17
|
* import { fromAtom, syncRAF } from "@thi.ng/rstream";
|
|
19
18
|
*
|
package/sync.d.ts
CHANGED
|
@@ -92,15 +92,25 @@ export interface StreamSyncOpts<A extends IObjectOf<ISubscribable<any>>, B = Syn
|
|
|
92
92
|
* package. See this function's docs for further details.
|
|
93
93
|
*
|
|
94
94
|
* @example
|
|
95
|
-
* ```ts
|
|
95
|
+
* ```ts tangle:../export/sync.ts
|
|
96
96
|
* import { stream, sync, trace } from "@thi.ng/rstream";
|
|
97
97
|
*
|
|
98
|
-
* const a = stream();
|
|
99
|
-
* const b = stream();
|
|
100
|
-
*
|
|
98
|
+
* const a = stream<number>();
|
|
99
|
+
* const b = stream<number>();
|
|
100
|
+
*
|
|
101
|
+
* const main = sync({ src: { a, b } }).subscribe(trace("result: "));
|
|
102
|
+
*
|
|
101
103
|
* a.next(1);
|
|
104
|
+
* // main received value, but does not yet emit...
|
|
105
|
+
*
|
|
102
106
|
* b.next(2);
|
|
107
|
+
* // now that `b` has delivered a value, `main` will produce its 1st result tuple
|
|
103
108
|
* // result: { a: 1, b: 2 }
|
|
109
|
+
*
|
|
110
|
+
* // any further input changes will trigger new results
|
|
111
|
+
* // (with cached values from other inputs)
|
|
112
|
+
* b.next(3);
|
|
113
|
+
* // result: { a: 1, b: 3 }
|
|
104
114
|
* ```
|
|
105
115
|
*
|
|
106
116
|
* Also see: {@link StreamSyncOpts}
|
package/toggle.d.ts
CHANGED
package/transduce.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { Subscription } from "./subscription.js";
|
|
|
9
9
|
* the final reduced result (or fail with error).
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
* ```ts
|
|
12
|
+
* ```ts tangle:../export/transduce.ts
|
|
13
13
|
* import { fromIterable, transduce } from "@thi.ng/rstream";
|
|
14
14
|
* import { add, map, range } from "@thi.ng/transducers";
|
|
15
15
|
*
|
package/tween.d.ts
CHANGED
|
@@ -21,10 +21,10 @@ import { type ISubscribable } from "./api.js";
|
|
|
21
21
|
* `clock` are exhausted.
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* import { stream, tween } from "@thi.ng/rstream";
|
|
24
|
+
* ```ts tangle:../export/tween.ts
|
|
25
|
+
* import { stream, tween, trace } from "@thi.ng/rstream";
|
|
26
26
|
*
|
|
27
|
-
* val = stream();
|
|
27
|
+
* const val = stream<number>();
|
|
28
28
|
*
|
|
29
29
|
* tween(
|
|
30
30
|
* // consume from `val` stream
|
|
@@ -37,17 +37,20 @@ import { type ISubscribable } from "./api.js";
|
|
|
37
37
|
* (a, b) => Math.abs(a - b) < 0.01
|
|
38
38
|
* ).subscribe(trace("tweened"))
|
|
39
39
|
*
|
|
40
|
-
*
|
|
40
|
+
* val.next(10)
|
|
41
41
|
* // 5
|
|
42
42
|
* // 7.5
|
|
43
43
|
* // ...
|
|
44
44
|
* // 9.98046875
|
|
45
45
|
*
|
|
46
|
-
*
|
|
46
|
+
* val.next(100)
|
|
47
47
|
* // 55
|
|
48
48
|
* // 77.5
|
|
49
49
|
* // ...
|
|
50
50
|
* // 99.989013671875
|
|
51
|
+
*
|
|
52
|
+
* // terminate after 1sec
|
|
53
|
+
* setTimeout(() => val.done(), 1000);
|
|
51
54
|
* ```
|
|
52
55
|
*
|
|
53
56
|
* @param src -
|
package/view.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type FromViewUnsafeOpts<T> = FromViewOpts<Path, any, T>;
|
|
|
13
13
|
* or tuple.
|
|
14
14
|
|
|
15
15
|
* @example
|
|
16
|
-
* ```ts
|
|
16
|
+
* ```ts tangle:../export/from-view-unsafe.ts
|
|
17
17
|
* import { defAtom } from "@thi.ng/atom";
|
|
18
18
|
* import { fromViewUnsafe, trace } from "@thi.ng/rstream";
|
|
19
19
|
*
|
|
@@ -69,22 +69,27 @@ export declare const fromViewUnsafe: <T>(atom: ReadonlyAtom<any>, opts: FromView
|
|
|
69
69
|
* [`defViewUnsafe()`](https://docs.thi.ng/umbrella/atom/functions/defViewUnsafe.html)
|
|
70
70
|
*
|
|
71
71
|
* @example
|
|
72
|
-
* ```ts
|
|
72
|
+
* ```ts tangle:../export/from-view.ts
|
|
73
73
|
* import { defAtom } from "@thi.ng/atom";
|
|
74
74
|
* import { fromView, trace } from "@thi.ng/rstream";
|
|
75
75
|
*
|
|
76
|
-
*
|
|
76
|
+
* interface DB {
|
|
77
|
+
* a: number;
|
|
78
|
+
* b?: { c: number; }
|
|
79
|
+
* }
|
|
80
|
+
*
|
|
81
|
+
* const db = defAtom<DB>({ a: 1, b: { c: 2 }});
|
|
77
82
|
*
|
|
78
83
|
* fromView(
|
|
79
84
|
* db,
|
|
80
85
|
* {
|
|
81
|
-
* path: ["b,"c"],
|
|
86
|
+
* path: ["b", "c"],
|
|
82
87
|
* tx: (x) => x != null ? String(x) : "n/a"
|
|
83
88
|
* }
|
|
84
89
|
* ).subscribe(trace("view:"))
|
|
85
90
|
* // view: 2
|
|
86
91
|
*
|
|
87
|
-
* db.swapIn(["b","c"], (x) => x + 1);
|
|
92
|
+
* db.swapIn(["b","c"], (x) => x! + 1);
|
|
88
93
|
* // view: 3
|
|
89
94
|
*
|
|
90
95
|
* db.reset({ a: 10 });
|
package/worker.d.ts
CHANGED
|
@@ -23,11 +23,6 @@ export interface FromWorkerOpts extends WithErrorHandlerOpts {
|
|
|
23
23
|
* instance, a JS source code `Blob` or an URL string. In the latter two
|
|
24
24
|
* cases, a worker is created automatically.
|
|
25
25
|
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
*
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
26
|
* @param worker -
|
|
32
27
|
* @param opts -
|
|
33
28
|
*/
|