@thi.ng/rstream 8.3.9 → 8.3.11

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-03-01T15:22:50Z
3
+ - **Last updated**: 2024-03-07T20:40:47Z
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
@@ -135,6 +135,9 @@ src.transform({ xform: map(...), error: handleError });
135
135
  (transducer) must now be given as part of the options object:
136
136
 
137
137
  ```ts
138
+ import { reactive, trace } from "@thi.ng/rstream";
139
+ import { filter } from "@thi.ng/transducers";
140
+
138
141
  const src = reactive(1);
139
142
 
140
143
  // old
@@ -149,6 +152,9 @@ src.subscribe(trace("foo"), { xform: filter((x) => x < 10), id: "child-sub" });
149
152
  similarity to above.
150
153
 
151
154
  ```ts
155
+ import { pubsub } from "@thi.ng/rstream";
156
+ import { map } from "@thi.ng/transducers";
157
+
152
158
  type Event = { id: string; value: any; };
153
159
 
154
160
  const src = pubsub<Event>({ topic: (e) => e.id });
@@ -341,6 +347,8 @@ triggered manually (from outside the stream), in which case the user
341
347
  should call `stream.next()` to cause value propagation.
342
348
 
343
349
  ```ts
350
+ import { stream, trace } from "@thi.ng/rstream";
351
+
344
352
  a = stream<number>((s) => {
345
353
  s.next(1);
346
354
  s.next(2);
@@ -400,14 +408,19 @@ too). Subscriptions can be:
400
408
  - implement the @thi.ng/api `IDeref` interface
401
409
 
402
410
  ```ts
411
+ import { subscription, trace } from "@thi.ng/rstream";
412
+ import { filter } from "@thi.ng/transducers";
413
+
403
414
  // as reactive value mechanism (same as with stream() above)
404
415
  s = subscription<any, any>();
405
416
  s.subscribe(trace("s1"));
406
- s.subscribe(trace("s2"), tx.filter((x) => x > 25));
417
+ s.subscribe(trace("s2"), filter((x) => x > 25));
407
418
 
408
419
  // external trigger
409
420
  s.next(23);
410
421
  // s1 23
422
+ // (s2 doesn't receive value here due to its filter)
423
+
411
424
  s.next(42);
412
425
  // s2 42
413
426
  // s1 42
@@ -457,12 +470,15 @@ function returns `null` / `undefined`, no further action will be taken
457
470
  ignored).
458
471
 
459
472
  ```ts
473
+ import { metastream, fromIterable, trace } from "@thi.ng/rstream";
474
+ import { repeat } from "@thi.ng/transducers";
475
+
460
476
  // transform each received odd number into a stream
461
477
  // producing 3 copies of that number in the metastream
462
478
  // even numbers are ignored
463
479
  a = metastream<number, string>(
464
480
  (x) => (x & 1)
465
- ? fromIterable(tx.repeat("odd: " + x, 3), { delay: 100 })
481
+ ? fromIterable(repeat("odd: " + x, 3), { delay: 100 })
466
482
  : null
467
483
  );
468
484
 
@@ -491,14 +507,17 @@ inputs. This keeps them alive and allows for dynamic switching between
491
507
  them.
492
508
 
493
509
  ```ts
510
+ import { metastream, fromIterable, trace, CloseMode } from "@thi.ng/rstream";
511
+ import { repeat } from "@thi.ng/transducers";
512
+
494
513
  // infinite inputs
495
514
  a = fromIterable(
496
- tx.repeat("a"),
515
+ repeat("a"),
497
516
  { delay: 1000, closeOut: CloseMode.NEVER }
498
517
  );
499
518
 
500
519
  b = fromIterable(
501
- tx.repeat("b"),
520
+ repeat("b"),
502
521
  { delay: 1000, closeOut: CloseMode.NEVER }
503
522
  );
504
523
 
@@ -532,6 +551,8 @@ done, but this behavior can be overridden via the `close` option, using
532
551
  `CloseMode` enums.
533
552
 
534
553
  ```ts
554
+ import { merge, fromIterable, trace } from "@thi.ng/rstream";
555
+
535
556
  merge({
536
557
  // input streams w/ different frequencies
537
558
  src: [
@@ -556,10 +577,13 @@ transducer](https://docs.thi.ng/umbrella/transducers/functions/labeled.html) for
556
577
  each input to create a stream of labeled values and track their provenance:
557
578
 
558
579
  ```ts
580
+ import { merge, fromIterable, trace } from "@thi.ng/rstream";
581
+ import { labeled } from "@thi.ng/transducers";
582
+
559
583
  merge({
560
584
  src: [
561
- fromIterable([1, 2, 3]).transform(tx.labeled("a")),
562
- fromIterable([10, 20, 30]).transform(tx.labeled("b")),
585
+ fromIterable([1, 2, 3]).transform(labeled("a")),
586
+ fromIterable([10, 20, 30]).transform(labeled("b")),
563
587
  ]
564
588
  }).subscribe(trace());
565
589
  // ["a", 1]
@@ -582,12 +606,13 @@ as new input to the merge and then automatically remove once that stream
582
606
  is exhausted.
583
607
 
584
608
  ```ts
609
+ import { merge, stream, fromIterable, trace } from "@thi.ng/rstream";
585
610
  import { repeat } from "@thi.ng/transducers";
586
611
 
587
612
  // stream source w/ transducer mapping values to new streams
588
613
  a = stream().map((x) => fromIterable(repeat(x, 3)));
589
614
  // simple 1Hz counter
590
- b = fromInterval(1000);
615
+ b = fromInterval(1000).map((x) => "b" + x);
591
616
 
592
617
  merge({ src: [a, b] }).subscribe(trace());
593
618
  // 0
@@ -630,6 +655,8 @@ calls `done()` when the last active input is done, but this behavior can
630
655
  be overridden via the `close` constructor option, using `CloseMode` enums.
631
656
 
632
657
  ```ts
658
+ import { sync, stream, trace } from "@thi.ng/rstream";
659
+
633
660
  const a = stream();
634
661
  const b = stream();
635
662
  s = sync<any,any>({ src: { a, b } }).subscribe(trace("result: "));
@@ -692,6 +719,8 @@ topic function and `a` & `b` as subscribers for truthy (`a`) and falsy
692
719
  `b` values.
693
720
 
694
721
  ```ts
722
+ import { bisect, fromIterable, trace } from "@thi.ng/rstream";
723
+
695
724
  fromIterable([1, 2, 3, 4]).subscribe(
696
725
  bisect((x) => !!(x & 1), trace("odd"), trace("even"))
697
726
  );
@@ -708,6 +737,8 @@ first created as `Subscription` (if not already) and a reference kept
708
737
  prior to calling `bisect()`.
709
738
 
710
739
  ```ts
740
+ import { bisect, fromIterable, subscription, trace } from "@thi.ng/rstream";
741
+
711
742
  const odd = subscription();
712
743
  const even = subscription();
713
744
  odd.subscribe(trace("odd"));
@@ -741,6 +772,11 @@ optional predicate can be used to only trigger for specific values /
741
772
  conditions.
742
773
 
743
774
  ```ts
775
+ import {
776
+ merge, fromEvent, fromRAF,
777
+ sidechainPartition, trace
778
+ } from "@thi.ng/rstream";
779
+
744
780
  // queue event processing to only execute during the
745
781
  // requestAnimationFrame cycle (RAF)
746
782
  sidechainPartition(
@@ -755,7 +791,21 @@ sidechainPartition(
755
791
  ).subscribe(trace());
756
792
  ```
757
793
 
758
- Since v8.0.0 there's [`syncRAF()`](https://docs.thi.ng/umbrella/rstream/functions/syncRAF-1.html)
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
+ ```
759
809
 
760
810
  #### Input toggling, controlled by sidechain
761
811
 
@@ -771,6 +821,8 @@ will be toggled on/off. Whilst switched off, no input values will be
771
821
  forwarded.
772
822
 
773
823
  ```ts
824
+ import { sidechainToggle, fromInterval, trace } from "@thi.ng/rstream";
825
+
774
826
  // use slower interval stream to toggle faster main stream on/off
775
827
  sidechainToggle(fromInterval(500), fromInterval(1000)).subscribe(trace());
776
828
  // 0
@@ -789,6 +841,8 @@ Buffers the most recent value received and only forwards it downstream whenever
789
841
  a new control value is received from the sidechain.
790
842
 
791
843
  ```ts
844
+ import { sidechainTrigger, reactive, stream, trace } from "@thi.ng/rstream";
845
+
792
846
  const src = reactive("payload");
793
847
 
794
848
  const side = stream();
@@ -832,6 +886,8 @@ self.addEventListener("message", (e) => {
832
886
  ##### main.ts
833
887
 
834
888
  ```ts
889
+ import { forkJoin, trace } from "@thi.ng/rstream";
890
+
835
891
  const src = stream<number[]>();
836
892
 
837
893
  // fork worker jobs & re-join results
@@ -898,6 +954,8 @@ handler will be called, which _might_ put this subscription into an error
898
954
  state and stop it from receiving new values.
899
955
 
900
956
  ```ts
957
+ import { subscription, State } from "@thi.ng/rstream";
958
+
901
959
  src = subscription({ next(x) { throw x; } });
902
960
 
903
961
  // triggers error, caught by subscription wrapper
package/object.d.ts CHANGED
@@ -66,7 +66,7 @@ export interface StreamObjOpts<T, K extends Keys<T>> extends CommonOpts {
66
66
  * The structure of the returned object is
67
67
  * {@link StreamObj | as follows}:
68
68
  *
69
- * ```ts
69
+ * ```text
70
70
  * {
71
71
  * streams: { ... },
72
72
  * next(x): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rstream",
3
- "version": "8.3.9",
3
+ "version": "8.3.11",
4
4
  "description": "Reactive streams & subscription primitives for constructing dataflow graphs / pipelines",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -36,17 +36,18 @@
36
36
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
37
37
  "doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
38
38
  "pub": "yarn npm publish --access public",
39
- "test": "bun test"
39
+ "test": "bun test",
40
+ "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
40
41
  },
41
42
  "dependencies": {
42
- "@thi.ng/api": "^8.9.27",
43
- "@thi.ng/arrays": "^2.8.4",
44
- "@thi.ng/associative": "^6.3.44",
45
- "@thi.ng/atom": "^5.2.34",
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.8"
43
+ "@thi.ng/api": "^8.9.28",
44
+ "@thi.ng/arrays": "^2.8.6",
45
+ "@thi.ng/associative": "^6.3.46",
46
+ "@thi.ng/atom": "^5.2.36",
47
+ "@thi.ng/checks": "^3.5.2",
48
+ "@thi.ng/errors": "^2.4.20",
49
+ "@thi.ng/logger": "^3.0.5",
50
+ "@thi.ng/transducers": "^8.9.10"
50
51
  },
51
52
  "devDependencies": {
52
53
  "@microsoft/api-extractor": "^7.40.1",
@@ -214,5 +215,5 @@
214
215
  ],
215
216
  "year": 2017
216
217
  },
217
- "gitHead": "d660ae8fd1bf64d919b4334f19509f1f539d70f6\n"
218
+ "gitHead": "a421058a65ba76608d94129ac29451bfedaf201c\n"
218
219
  }