@thi.ng/rstream 8.3.8 → 8.3.10
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 +67 -20
- package/object.d.ts +1 -1
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
<!-- This file is generated - DO NOT EDIT! -->
|
|
2
2
|
<!-- Please see: https://github.com/thi-ng/umbrella/blob/develop/CONTRIBUTING.md#changes-to-readme-files -->
|
|
3
|
-
> [!IMPORTANT]
|
|
4
|
-
> ‼️ Announcing the thi.ng user survey 2024 📋
|
|
5
|
-
>
|
|
6
|
-
> [Please participate in the survey here!](https://forms.gle/XacbSDEmQMPZg8197)\
|
|
7
|
-
> (open until end of February)
|
|
8
|
-
>
|
|
9
|
-
> **To achieve a better sample size, I'd highly appreciate if you could
|
|
10
|
-
> circulate the link to this survey in your own networks.**
|
|
11
|
-
>
|
|
12
|
-
> [Discussion](https://github.com/thi-ng/umbrella/discussions/447)
|
|
13
|
-
|
|
14
3
|
# 
|
|
15
4
|
|
|
16
5
|
[](https://www.npmjs.com/package/@thi.ng/rstream)
|
|
@@ -22,7 +11,7 @@
|
|
|
22
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
23
12
|
> and anti-framework.
|
|
24
13
|
>
|
|
25
|
-
> 🚀
|
|
14
|
+
> 🚀 Please help me to work full-time on these projects by [sponsoring me on
|
|
26
15
|
> GitHub](https://github.com/sponsors/postspectacular). Thank you! ❤️
|
|
27
16
|
|
|
28
17
|
- [About](#about)
|
|
@@ -146,6 +135,9 @@ src.transform({ xform: map(...), error: handleError });
|
|
|
146
135
|
(transducer) must now be given as part of the options object:
|
|
147
136
|
|
|
148
137
|
```ts
|
|
138
|
+
import { reactive, trace } from "@thi.ng/rstream";
|
|
139
|
+
import { filter } from "@thi.ng/transducers";
|
|
140
|
+
|
|
149
141
|
const src = reactive(1);
|
|
150
142
|
|
|
151
143
|
// old
|
|
@@ -160,6 +152,9 @@ src.subscribe(trace("foo"), { xform: filter((x) => x < 10), id: "child-sub" });
|
|
|
160
152
|
similarity to above.
|
|
161
153
|
|
|
162
154
|
```ts
|
|
155
|
+
import { pubsub } from "@thi.ng/rstream";
|
|
156
|
+
import { map } from "@thi.ng/transducers";
|
|
157
|
+
|
|
163
158
|
type Event = { id: string; value: any; };
|
|
164
159
|
|
|
165
160
|
const src = pubsub<Event>({ topic: (e) => e.id });
|
|
@@ -352,6 +347,8 @@ triggered manually (from outside the stream), in which case the user
|
|
|
352
347
|
should call `stream.next()` to cause value propagation.
|
|
353
348
|
|
|
354
349
|
```ts
|
|
350
|
+
import { stream, trace } from "@thi.ng/rstream";
|
|
351
|
+
|
|
355
352
|
a = stream<number>((s) => {
|
|
356
353
|
s.next(1);
|
|
357
354
|
s.next(2);
|
|
@@ -411,14 +408,19 @@ too). Subscriptions can be:
|
|
|
411
408
|
- implement the @thi.ng/api `IDeref` interface
|
|
412
409
|
|
|
413
410
|
```ts
|
|
411
|
+
import { subscription, trace } from "@thi.ng/rstream";
|
|
412
|
+
import { filter } from "@thi.ng/transducers";
|
|
413
|
+
|
|
414
414
|
// as reactive value mechanism (same as with stream() above)
|
|
415
415
|
s = subscription<any, any>();
|
|
416
416
|
s.subscribe(trace("s1"));
|
|
417
|
-
s.subscribe(trace("s2"),
|
|
417
|
+
s.subscribe(trace("s2"), filter((x) => x > 25));
|
|
418
418
|
|
|
419
419
|
// external trigger
|
|
420
420
|
s.next(23);
|
|
421
421
|
// s1 23
|
|
422
|
+
// (s2 doesn't receive value here due to its filter)
|
|
423
|
+
|
|
422
424
|
s.next(42);
|
|
423
425
|
// s2 42
|
|
424
426
|
// s1 42
|
|
@@ -468,12 +470,15 @@ function returns `null` / `undefined`, no further action will be taken
|
|
|
468
470
|
ignored).
|
|
469
471
|
|
|
470
472
|
```ts
|
|
473
|
+
import { metastream, fromIterable, trace } from "@thi.ng/rstream";
|
|
474
|
+
import { repeat } from "@thi.ng/transducers";
|
|
475
|
+
|
|
471
476
|
// transform each received odd number into a stream
|
|
472
477
|
// producing 3 copies of that number in the metastream
|
|
473
478
|
// even numbers are ignored
|
|
474
479
|
a = metastream<number, string>(
|
|
475
480
|
(x) => (x & 1)
|
|
476
|
-
? fromIterable(
|
|
481
|
+
? fromIterable(repeat("odd: " + x, 3), { delay: 100 })
|
|
477
482
|
: null
|
|
478
483
|
);
|
|
479
484
|
|
|
@@ -502,14 +507,17 @@ inputs. This keeps them alive and allows for dynamic switching between
|
|
|
502
507
|
them.
|
|
503
508
|
|
|
504
509
|
```ts
|
|
510
|
+
import { metastream, fromIterable, trace, CloseMode } from "@thi.ng/rstream";
|
|
511
|
+
import { repeat } from "@thi.ng/transducers";
|
|
512
|
+
|
|
505
513
|
// infinite inputs
|
|
506
514
|
a = fromIterable(
|
|
507
|
-
|
|
515
|
+
repeat("a"),
|
|
508
516
|
{ delay: 1000, closeOut: CloseMode.NEVER }
|
|
509
517
|
);
|
|
510
518
|
|
|
511
519
|
b = fromIterable(
|
|
512
|
-
|
|
520
|
+
repeat("b"),
|
|
513
521
|
{ delay: 1000, closeOut: CloseMode.NEVER }
|
|
514
522
|
);
|
|
515
523
|
|
|
@@ -543,6 +551,8 @@ done, but this behavior can be overridden via the `close` option, using
|
|
|
543
551
|
`CloseMode` enums.
|
|
544
552
|
|
|
545
553
|
```ts
|
|
554
|
+
import { merge, fromIterable, trace } from "@thi.ng/rstream";
|
|
555
|
+
|
|
546
556
|
merge({
|
|
547
557
|
// input streams w/ different frequencies
|
|
548
558
|
src: [
|
|
@@ -567,10 +577,13 @@ transducer](https://docs.thi.ng/umbrella/transducers/functions/labeled.html) for
|
|
|
567
577
|
each input to create a stream of labeled values and track their provenance:
|
|
568
578
|
|
|
569
579
|
```ts
|
|
580
|
+
import { merge, fromIterable, trace } from "@thi.ng/rstream";
|
|
581
|
+
import { labeled } from "@thi.ng/transducers";
|
|
582
|
+
|
|
570
583
|
merge({
|
|
571
584
|
src: [
|
|
572
|
-
fromIterable([1, 2, 3]).transform(
|
|
573
|
-
fromIterable([10, 20, 30]).transform(
|
|
585
|
+
fromIterable([1, 2, 3]).transform(labeled("a")),
|
|
586
|
+
fromIterable([10, 20, 30]).transform(labeled("b")),
|
|
574
587
|
]
|
|
575
588
|
}).subscribe(trace());
|
|
576
589
|
// ["a", 1]
|
|
@@ -593,12 +606,13 @@ as new input to the merge and then automatically remove once that stream
|
|
|
593
606
|
is exhausted.
|
|
594
607
|
|
|
595
608
|
```ts
|
|
609
|
+
import { merge, stream, fromIterable, trace } from "@thi.ng/rstream";
|
|
596
610
|
import { repeat } from "@thi.ng/transducers";
|
|
597
611
|
|
|
598
612
|
// stream source w/ transducer mapping values to new streams
|
|
599
613
|
a = stream().map((x) => fromIterable(repeat(x, 3)));
|
|
600
614
|
// simple 1Hz counter
|
|
601
|
-
b = fromInterval(1000);
|
|
615
|
+
b = fromInterval(1000).map((x) => "b" + x);
|
|
602
616
|
|
|
603
617
|
merge({ src: [a, b] }).subscribe(trace());
|
|
604
618
|
// 0
|
|
@@ -641,6 +655,8 @@ calls `done()` when the last active input is done, but this behavior can
|
|
|
641
655
|
be overridden via the `close` constructor option, using `CloseMode` enums.
|
|
642
656
|
|
|
643
657
|
```ts
|
|
658
|
+
import { sync, stream, trace } from "@thi.ng/rstream";
|
|
659
|
+
|
|
644
660
|
const a = stream();
|
|
645
661
|
const b = stream();
|
|
646
662
|
s = sync<any,any>({ src: { a, b } }).subscribe(trace("result: "));
|
|
@@ -703,6 +719,8 @@ topic function and `a` & `b` as subscribers for truthy (`a`) and falsy
|
|
|
703
719
|
`b` values.
|
|
704
720
|
|
|
705
721
|
```ts
|
|
722
|
+
import { bisect, fromIterable, trace } from "@thi.ng/rstream";
|
|
723
|
+
|
|
706
724
|
fromIterable([1, 2, 3, 4]).subscribe(
|
|
707
725
|
bisect((x) => !!(x & 1), trace("odd"), trace("even"))
|
|
708
726
|
);
|
|
@@ -719,6 +737,8 @@ first created as `Subscription` (if not already) and a reference kept
|
|
|
719
737
|
prior to calling `bisect()`.
|
|
720
738
|
|
|
721
739
|
```ts
|
|
740
|
+
import { bisect, fromIterable, subscription, trace } from "@thi.ng/rstream";
|
|
741
|
+
|
|
722
742
|
const odd = subscription();
|
|
723
743
|
const even = subscription();
|
|
724
744
|
odd.subscribe(trace("odd"));
|
|
@@ -752,6 +772,11 @@ optional predicate can be used to only trigger for specific values /
|
|
|
752
772
|
conditions.
|
|
753
773
|
|
|
754
774
|
```ts
|
|
775
|
+
import {
|
|
776
|
+
merge, fromEvent, fromRAF,
|
|
777
|
+
sidechainPartition, trace
|
|
778
|
+
} from "@thi.ng/rstream";
|
|
779
|
+
|
|
755
780
|
// queue event processing to only execute during the
|
|
756
781
|
// requestAnimationFrame cycle (RAF)
|
|
757
782
|
sidechainPartition(
|
|
@@ -766,7 +791,21 @@ sidechainPartition(
|
|
|
766
791
|
).subscribe(trace());
|
|
767
792
|
```
|
|
768
793
|
|
|
769
|
-
Since v8.0.0 there's
|
|
794
|
+
Since v8.0.0 there's
|
|
795
|
+
[`syncRAF()`](https://docs.thi.ng/umbrella/rstream/functions/syncRAF-1.html),
|
|
796
|
+
which allows the above to be simplified to:
|
|
797
|
+
|
|
798
|
+
```ts
|
|
799
|
+
import { merge, fromEvent, syncRAF, trace } from "@thi.ng/rstream";
|
|
800
|
+
|
|
801
|
+
syncRAF(
|
|
802
|
+
merge([
|
|
803
|
+
fromEvent(document, "mousemove"),
|
|
804
|
+
fromEvent(document, "mousedown"),
|
|
805
|
+
fromEvent(document, "mouseup")
|
|
806
|
+
])
|
|
807
|
+
).subscribe(trace());
|
|
808
|
+
```
|
|
770
809
|
|
|
771
810
|
#### Input toggling, controlled by sidechain
|
|
772
811
|
|
|
@@ -782,6 +821,8 @@ will be toggled on/off. Whilst switched off, no input values will be
|
|
|
782
821
|
forwarded.
|
|
783
822
|
|
|
784
823
|
```ts
|
|
824
|
+
import { sidechainToggle, fromInterval, trace } from "@thi.ng/rstream";
|
|
825
|
+
|
|
785
826
|
// use slower interval stream to toggle faster main stream on/off
|
|
786
827
|
sidechainToggle(fromInterval(500), fromInterval(1000)).subscribe(trace());
|
|
787
828
|
// 0
|
|
@@ -800,6 +841,8 @@ Buffers the most recent value received and only forwards it downstream whenever
|
|
|
800
841
|
a new control value is received from the sidechain.
|
|
801
842
|
|
|
802
843
|
```ts
|
|
844
|
+
import { sidechainTrigger, reactive, stream, trace } from "@thi.ng/rstream";
|
|
845
|
+
|
|
803
846
|
const src = reactive("payload");
|
|
804
847
|
|
|
805
848
|
const side = stream();
|
|
@@ -843,6 +886,8 @@ self.addEventListener("message", (e) => {
|
|
|
843
886
|
##### main.ts
|
|
844
887
|
|
|
845
888
|
```ts
|
|
889
|
+
import { forkJoin, trace } from "@thi.ng/rstream";
|
|
890
|
+
|
|
846
891
|
const src = stream<number[]>();
|
|
847
892
|
|
|
848
893
|
// fork worker jobs & re-join results
|
|
@@ -909,6 +954,8 @@ handler will be called, which _might_ put this subscription into an error
|
|
|
909
954
|
state and stop it from receiving new values.
|
|
910
955
|
|
|
911
956
|
```ts
|
|
957
|
+
import { subscription, State } from "@thi.ng/rstream";
|
|
958
|
+
|
|
912
959
|
src = subscription({ next(x) { throw x; } });
|
|
913
960
|
|
|
914
961
|
// triggers error, caught by subscription wrapper
|
package/object.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/rstream",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.10",
|
|
4
4
|
"description": "Reactive streams & subscription primitives for constructing dataflow graphs / pipelines",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"test": "bun test"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@thi.ng/api": "^8.9.
|
|
43
|
-
"@thi.ng/arrays": "^2.8.
|
|
44
|
-
"@thi.ng/associative": "^6.3.
|
|
45
|
-
"@thi.ng/atom": "^5.2.
|
|
46
|
-
"@thi.ng/checks": "^3.5.
|
|
47
|
-
"@thi.ng/errors": "^2.4.
|
|
48
|
-
"@thi.ng/logger": "^3.0.
|
|
49
|
-
"@thi.ng/transducers": "^8.9.
|
|
42
|
+
"@thi.ng/api": "^8.9.27",
|
|
43
|
+
"@thi.ng/arrays": "^2.8.5",
|
|
44
|
+
"@thi.ng/associative": "^6.3.45",
|
|
45
|
+
"@thi.ng/atom": "^5.2.35",
|
|
46
|
+
"@thi.ng/checks": "^3.5.1",
|
|
47
|
+
"@thi.ng/errors": "^2.4.19",
|
|
48
|
+
"@thi.ng/logger": "^3.0.4",
|
|
49
|
+
"@thi.ng/transducers": "^8.9.9"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@microsoft/api-extractor": "^7.40.1",
|
|
@@ -214,5 +214,5 @@
|
|
|
214
214
|
],
|
|
215
215
|
"year": 2017
|
|
216
216
|
},
|
|
217
|
-
"gitHead": "
|
|
217
|
+
"gitHead": "df9e312af741d87e6b450afcfea6a6e381662b1e\n"
|
|
218
218
|
}
|