@thi.ng/rstream 8.5.0 → 8.5.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-05-08T18:24:31Z
3
+ - **Last updated**: 2024-06-29T09:28:36Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 189 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 { fromCursor } from "@thi.ng/rstream";
37
+ * import { fromAtom, trace } from "@thi.ng/rstream";
38
38
  *
39
- * db = defAtom({ a: 23, b: 88 });
40
- * cursor = defCursor(db, "a")
39
+ * type DB = { a: number; b?: number };
41
40
  *
42
- * rs.fromAtom(cursor).subscribe(rs.trace("cursor val:"))
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({ next: console.log });
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
@@ -32,8 +32,6 @@ export declare const fromEvent: (src: EventTarget, name: string, listenerOpts?:
32
32
  * fromEvent(document.body, "mousemove"); // Stream<Event>
33
33
  * ```
34
34
  *
35
- * Also see: {@link fromEvent}
36
- *
37
35
  * @param src -
38
36
  * @param name -
39
37
  * @param listenerOpts -
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(tx.labeled("a")),
55
- * fromIterable([10, 20, 30]).transform(tx.labeled("b")),
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 factory fn
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, CloseMode } from "@thi.ng/rstream";
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: 1000, closeOut: CloseMode.NEVER }
75
+ * { delay: 100, closeOut: CloseMode.NEVER }
76
76
  * );
77
- * b = fromIterable(
77
+ * const b = fromIterable(
78
78
  * repeat("b"),
79
- * { delay: 1000, closeOut: CloseMode.NEVER }
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
- * m.next(true);
87
- * // meta from: a
88
- *
89
- * m.next(false);
90
- * // meta from: b
91
- *
92
- * m.next(true);
93
- * // meta from: a
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
- * obj.streams.b.subscribe(trace("b"))
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"], { initial: false });
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 keyof T>(src: T, opts?: Partial<StreamObjOpts<T, K>>) => StreamObj<T, K>;
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.0",
3
+ "version": "8.5.2",
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://github.com/thi-ng/umbrella/tree/develop/packages/rstream#readme",
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.2",
44
- "@thi.ng/arrays": "^2.9.6",
45
- "@thi.ng/associative": "^6.3.60",
46
- "@thi.ng/atom": "^5.3.0",
47
- "@thi.ng/checks": "^3.6.4",
48
- "@thi.ng/errors": "^2.5.7",
49
- "@thi.ng/logger": "^3.0.12",
50
- "@thi.ng/transducers": "^9.0.5"
43
+ "@thi.ng/api": "^8.11.4",
44
+ "@thi.ng/arrays": "^2.9.8",
45
+ "@thi.ng/associative": "^6.3.62",
46
+ "@thi.ng/atom": "^5.3.2",
47
+ "@thi.ng/checks": "^3.6.6",
48
+ "@thi.ng/errors": "^2.5.9",
49
+ "@thi.ng/logger": "^3.0.14",
50
+ "@thi.ng/transducers": "^9.0.7"
51
51
  },
52
52
  "devDependencies": {
53
- "@microsoft/api-extractor": "^7.43.2",
54
- "esbuild": "^0.21.1",
53
+ "@microsoft/api-extractor": "^7.47.0",
54
+ "esbuild": "^0.21.5",
55
55
  "typedoc": "^0.25.13",
56
- "typescript": "^5.4.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": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
221
+ "gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\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], 100)
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
@@ -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 { sideChainPartitionRAF } from "@thi.ng/rstream";
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
- * sideChainPartitionRAF(fromAtom(atom)).subscribe({
62
- * next({ name }) { document.body.innerText = name; }
63
+ * sidechainPartitionRAF(fromAtom(atom)).subscribe({
64
+ * next(name) { document.body.innerText = name; }
63
65
  * });
64
66
  *
65
67
  * // trigger update
@@ -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(fromInterval(500), fromInterval(1000)).subscribe(trace());
29
+ * sidechainToggle(src, fromInterval(1000)).subscribe(trace());
25
30
  * // 0
26
- * // 3
31
+ * // 1
27
32
  * // 4
28
- * // 7
33
+ * // 5
29
34
  * // 8
30
- * ...
35
+ * // 9
36
+ * // done
31
37
  * ```
32
38
  *
33
39
  * @param src -
@@ -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
- * s.subscribe(trace("s2"), { xform: filter((x) => x > 25) });
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
- * s = sync({ src: { a, b } }).subscribe(trace("result: "));
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
@@ -6,7 +6,7 @@ import { Subscription } from "./subscription.js";
6
6
  * `initial` value.
7
7
  *
8
8
  * @examples
9
- * ```ts
9
+ * ```ts tangle:../export/toggle.ts
10
10
  * import { toggle, trace } from "@thi.ng/rstream";
11
11
  *
12
12
  * const mute = toggle(false);
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
- * a.next(10)
40
+ * val.next(10)
41
41
  * // 5
42
42
  * // 7.5
43
43
  * // ...
44
44
  * // 9.98046875
45
45
  *
46
- * a.next(100)
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
- * const db = defAtom<any>({ a: 1, b: { c: 2 }});
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
  */