@thi.ng/rstream 8.2.12 → 8.2.14

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**: 2023-12-03T12:13:31Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
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
@@ -245,6 +245,7 @@ directory are using this package:
245
245
  | | Demonstates various rdom usage patterns | [Demo](https://demo.thi.ng/umbrella/rdom-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-basics) |
246
246
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-canvas-basics.jpg" width="240"/> | Minimal rdom-canvas animation | [Demo](https://demo.thi.ng/umbrella/rdom-canvas-basics/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-canvas-basics) |
247
247
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-delayed-update.jpg" width="240"/> | Dynamically loaded images w/ preloader state | [Demo](https://demo.thi.ng/umbrella/rdom-delayed-update/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-delayed-update) |
248
+ | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-formgen.jpg" width="240"/> | Basic usage of the declarative rdom-forms generator | [Demo](https://demo.thi.ng/umbrella/rdom-formgen/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-formgen) |
248
249
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-key-sequences.jpg" width="240"/> | rstream & transducer-based FSM for converting key event sequences into high-level commands | [Demo](https://demo.thi.ng/umbrella/rdom-key-sequences/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-key-sequences) |
249
250
  | <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/rdom-lissajous.png" width="240"/> | rdom & hiccup-canvas interop test | [Demo](https://demo.thi.ng/umbrella/rdom-lissajous/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-lissajous) |
250
251
  | | Full umbrella repo doc string search w/ paginated results | [Demo](https://demo.thi.ng/umbrella/rdom-search-docs/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/rdom-search-docs) |
package/api.js CHANGED
@@ -1,26 +1,18 @@
1
- export var State;
2
- (function (State) {
3
- State[State["IDLE"] = 0] = "IDLE";
4
- State[State["ACTIVE"] = 1] = "ACTIVE";
5
- State[State["DONE"] = 2] = "DONE";
6
- State[State["UNSUBSCRIBED"] = 3] = "UNSUBSCRIBED";
7
- State[State["ERROR"] = 4] = "ERROR";
8
- })(State || (State = {}));
9
- /**
10
- * Closing behaviors.
11
- */
12
- export var CloseMode;
13
- (function (CloseMode) {
14
- /**
15
- * Never close, even if no more inputs/outputs.
16
- */
17
- CloseMode[CloseMode["NEVER"] = 0] = "NEVER";
18
- /**
19
- * Close when first input/output is done / removed.
20
- */
21
- CloseMode[CloseMode["FIRST"] = 1] = "FIRST";
22
- /**
23
- * Close when last input/output is done / removed.
24
- */
25
- CloseMode[CloseMode["LAST"] = 2] = "LAST";
26
- })(CloseMode || (CloseMode = {}));
1
+ var State = /* @__PURE__ */ ((State2) => {
2
+ State2[State2["IDLE"] = 0] = "IDLE";
3
+ State2[State2["ACTIVE"] = 1] = "ACTIVE";
4
+ State2[State2["DONE"] = 2] = "DONE";
5
+ State2[State2["UNSUBSCRIBED"] = 3] = "UNSUBSCRIBED";
6
+ State2[State2["ERROR"] = 4] = "ERROR";
7
+ return State2;
8
+ })(State || {});
9
+ var CloseMode = /* @__PURE__ */ ((CloseMode2) => {
10
+ CloseMode2[CloseMode2["NEVER"] = 0] = "NEVER";
11
+ CloseMode2[CloseMode2["FIRST"] = 1] = "FIRST";
12
+ CloseMode2[CloseMode2["LAST"] = 2] = "LAST";
13
+ return CloseMode2;
14
+ })(CloseMode || {});
15
+ export {
16
+ CloseMode,
17
+ State
18
+ };
package/asidechain.js CHANGED
@@ -1,22 +1,21 @@
1
1
  import { Subscription } from "./subscription.js";
2
- /**
3
- * Abstract base class for sidechained subscription types (e.g.
4
- * {@link sidechainPartition}, {@link sidechainToggle}).
5
- */
6
- export class ASidechain extends Subscription {
7
- sideSub;
8
- constructor(opts) {
9
- super(undefined, opts);
10
- }
11
- unsubscribe(sub) {
12
- const res = super.unsubscribe(sub);
13
- if (!sub || !this.subs.length) {
14
- this.sideSub.unsubscribe();
15
- }
16
- return res;
17
- }
18
- done() {
19
- this.sideSub.unsubscribe();
20
- super.done();
2
+ class ASidechain extends Subscription {
3
+ sideSub;
4
+ constructor(opts) {
5
+ super(void 0, opts);
6
+ }
7
+ unsubscribe(sub) {
8
+ const res = super.unsubscribe(sub);
9
+ if (!sub || !this.subs.length) {
10
+ this.sideSub.unsubscribe();
21
11
  }
12
+ return res;
13
+ }
14
+ done() {
15
+ this.sideSub.unsubscribe();
16
+ super.done();
17
+ }
22
18
  }
19
+ export {
20
+ ASidechain
21
+ };
package/atom.js CHANGED
@@ -1,50 +1,21 @@
1
1
  import { __optsWithID } from "./idgen.js";
2
2
  import { stream } from "./stream.js";
3
- /**
4
- * Yields {@link Stream} of value changes in given [Atom-like state
5
- * container](https://thi.ng/atom).
6
- *
7
- * @remarks
8
- * [Attaches a
9
- * watch](https://docs.thi.ng/umbrella/api/interfaces/IWatch.html#addWatch) to
10
- * the atom and checks for value changes with given `changed` predicate (`!==`
11
- * by default). If the predicate returns truthy result, the new value is emitted
12
- * on the stream. If `emitFirst` is true (default), also emits atom's current
13
- * value when first subscriber attaches to stream.
14
- *
15
- * Also see {@link fromView}, {@link fromViewUnsafe}
16
- *
17
- * @example
18
- * ```ts
19
- * db = new Atom({ a: 23, b: 88 });
20
- * cursor = new Cursor(db, "a")
21
- *
22
- * rs.fromAtom(cursor).subscribe(rs.trace("cursor val:"))
23
- * // cursor val: 23
24
- *
25
- * cursor.reset(42);
26
- * // cursor val: 42
27
- *
28
- * db.reset({a: 66})
29
- * // cursor val: 66
30
- * ```
31
- *
32
- * @param atom -
33
- * @param opts -
34
- */
35
- export const fromAtom = (atom, opts) => {
36
- opts = __optsWithID("atom", {
37
- emitFirst: true,
38
- changed: (a, b) => a !== b,
39
- ...opts,
3
+ const fromAtom = (atom, opts) => {
4
+ opts = __optsWithID("atom", {
5
+ emitFirst: true,
6
+ changed: (a, b) => a !== b,
7
+ ...opts
8
+ });
9
+ return stream((stream2) => {
10
+ atom.addWatch(stream2.id, (_, prev, curr) => {
11
+ if (opts.changed(prev, curr)) {
12
+ stream2.next(curr);
13
+ }
40
14
  });
41
- return stream((stream) => {
42
- atom.addWatch(stream.id, (_, prev, curr) => {
43
- if (opts.changed(prev, curr)) {
44
- stream.next(curr);
45
- }
46
- });
47
- opts.emitFirst && stream.next(atom.deref());
48
- return () => atom.removeWatch(stream.id);
49
- }, opts);
15
+ opts.emitFirst && stream2.next(atom.deref());
16
+ return () => atom.removeWatch(stream2.id);
17
+ }, opts);
18
+ };
19
+ export {
20
+ fromAtom
50
21
  };
package/bisect.js CHANGED
@@ -1,52 +1,11 @@
1
1
  import { __nextID } from "./idgen.js";
2
2
  import { PubSub } from "./pubsub.js";
3
- /**
4
- * Returns a {@link PubSub} using given predicate `pred` as boolean
5
- * {@link PubSubOpts.topic | topic function} and `truthy` & `falsey` as
6
- * subscribers for their respective values.
7
- *
8
- * @remarks
9
- * If `a` or `b` need to be subscribed to directly, then `a` / `b` MUST
10
- * be first created as `Subscription` (if not already) and a reference
11
- * kept prior to calling `bisect()`.
12
- *
13
- * @example
14
- * ```ts
15
- * fromIterable([1, 2, 3, 4]).subscribe(
16
- * bisect(
17
- * (x) => !!(x & 1),
18
- * trace("odd"),
19
- * trace("even")
20
- * )
21
- * );
22
- * // odd 1
23
- * // even 2
24
- * // odd 3
25
- * // even 4
26
- * // odd done
27
- * // even done
28
- * ```
29
- *
30
- * @example
31
- * ```ts
32
- * const odd = subscription();
33
- * const even = subscription();
34
- * odd.subscribe(trace("odd"));
35
- * odd.subscribe(trace("odd x10"), map((x) => x * 10));
36
- * even.subscribe(trace("even"));
37
- *
38
- * fromIterable([1, 2, 3, 4]).subscribe(
39
- * bisect((x) => !!(x & 1), odd, even)
40
- * );
41
- * ```
42
- *
43
- * @param pred - predicate function
44
- * @param truthy - subscription for truthy branch
45
- * @param falsy - subscription for falsy branch
46
- */
47
- export const bisect = (pred, truthy, falsy) => {
48
- const sub = new PubSub({ topic: pred, id: `bisect-${__nextID()}` });
49
- truthy && sub.subscribeTopic(true, truthy);
50
- falsy && sub.subscribeTopic(false, falsy);
51
- return sub;
3
+ const bisect = (pred, truthy, falsy) => {
4
+ const sub = new PubSub({ topic: pred, id: `bisect-${__nextID()}` });
5
+ truthy && sub.subscribeTopic(true, truthy);
6
+ falsy && sub.subscribeTopic(false, falsy);
7
+ return sub;
8
+ };
9
+ export {
10
+ bisect
52
11
  };
package/checks.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { implementsFunction } from "@thi.ng/checks/implements-function";
2
2
  import { CloseMode } from "./api.js";
3
- export const isSubscribable = (x) => implementsFunction(x, "subscribe");
4
- /**
5
- * Returns true if mode is FIRST, or if mode is LAST *and* `num = 0`.
6
- *
7
- * @internal
8
- */
9
- export const isFirstOrLastInput = (mode, num) => mode === CloseMode.FIRST || (mode === CloseMode.LAST && !num);
3
+ const isSubscribable = (x) => implementsFunction(x, "subscribe");
4
+ const isFirstOrLastInput = (mode, num) => mode === CloseMode.FIRST || mode === CloseMode.LAST && !num;
5
+ export {
6
+ isFirstOrLastInput,
7
+ isSubscribable
8
+ };
package/debounce.js CHANGED
@@ -1,21 +1,13 @@
1
1
  import { __optsWithID } from "./idgen.js";
2
2
  import { fromIterable } from "./iterable.js";
3
3
  import { metaStream } from "./metastream.js";
4
- /**
5
- * Returns a subscription which buffers any intermediate inputs arriving faster
6
- * than given `delay` time period, then emits last received value after `delay`
7
- * milliseconds.
8
- *
9
- * @example
10
- * ```ts
11
- * const src = fromIterable([1, 2, 3], { delay: 10 })
12
- * src.subscribe(debounce(20)).subscribe({ next: console.log });
13
- * // 3
14
- * ```
15
- *
16
- * @param delay -
17
- */
18
- export const debounce = (delay, opts) => metaStream((x) => fromIterable([x], { delay }), __optsWithID("debounce", {
4
+ const debounce = (delay, opts) => metaStream(
5
+ (x) => fromIterable([x], { delay }),
6
+ __optsWithID("debounce", {
19
7
  emitLast: true,
20
- ...opts,
21
- }));
8
+ ...opts
9
+ })
10
+ );
11
+ export {
12
+ debounce
13
+ };
package/defworker.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { isFunction } from "@thi.ng/checks/is-function";
2
- export const defInlineWorker = (src) => defWorker(new Blob([src], { type: "text/javascript" }));
3
- export const defWorker = (worker) => worker instanceof Worker
4
- ? worker
5
- : isFunction(worker)
6
- ? worker()
7
- : new Worker(worker instanceof Blob ? URL.createObjectURL(worker) : worker);
2
+ const defInlineWorker = (src) => defWorker(new Blob([src], { type: "text/javascript" }));
3
+ const defWorker = (worker) => worker instanceof Worker ? worker : isFunction(worker) ? worker() : new Worker(
4
+ worker instanceof Blob ? URL.createObjectURL(worker) : worker
5
+ );
6
+ export {
7
+ defInlineWorker,
8
+ defWorker
9
+ };
package/event.js CHANGED
@@ -1,41 +1,16 @@
1
1
  import { __optsWithID } from "./idgen.js";
2
2
  import { stream, Stream } from "./stream.js";
3
- /**
4
- * Creates a {@link Stream} of events attached to given element / event
5
- * target and using given event listener options (same as supported by
6
- * `addEventListener()`, default: false).
7
- *
8
- * @param src - event target
9
- * @param name - event name
10
- * @param listenerOpts - listener opts
11
- * @param streamOpts - stream opts
12
- */
13
- export const fromEvent = (src, name, listenerOpts = false, streamOpts) => {
14
- const result = stream((stream) => {
15
- let listener = (e) => stream.next(e);
16
- src.addEventListener(name, listener, listenerOpts);
17
- return () => src.removeEventListener(name, listener, listenerOpts);
18
- }, __optsWithID(`event-${name}`, streamOpts));
19
- streamOpts?.init !== undefined && result.next(streamOpts.init);
20
- return result;
3
+ const fromEvent = (src, name, listenerOpts = false, streamOpts) => {
4
+ const result = stream((stream2) => {
5
+ let listener = (e) => stream2.next(e);
6
+ src.addEventListener(name, listener, listenerOpts);
7
+ return () => src.removeEventListener(name, listener, listenerOpts);
8
+ }, __optsWithID(`event-${name}`, streamOpts));
9
+ streamOpts?.init !== void 0 && result.next(streamOpts.init);
10
+ return result;
11
+ };
12
+ const fromDOMEvent = (src, name, listenerOpts = false, streamOpts) => fromEvent(src, name, listenerOpts, streamOpts);
13
+ export {
14
+ fromDOMEvent,
15
+ fromEvent
21
16
  };
22
- /**
23
- * Same as {@link fromEvent}, however only supports well-known DOM event
24
- * names. Returned stream instance will use corresponding concrete event
25
- * type in its type signature, whereas {@link fromEvent} will only use the
26
- * generic `Event`.
27
- *
28
- * @example
29
- * ```ts
30
- * fromDOMEvent(document.body, "mousemove"); // Stream<MouseEvent>
31
- * fromEvent(document.body, "mousemove"); // Stream<Event>
32
- * ```
33
- *
34
- * Also see: {@link fromEvent}
35
- *
36
- * @param src -
37
- * @param name -
38
- * @param listenerOpts -
39
- * @param streamOpts -
40
- */
41
- export const fromDOMEvent = (src, name, listenerOpts = false, streamOpts) => fromEvent(src, name, listenerOpts, streamOpts);
package/forkjoin.js CHANGED
@@ -6,109 +6,43 @@ import { range } from "@thi.ng/transducers/range";
6
6
  import { transduce } from "@thi.ng/transducers/transduce";
7
7
  import { sync } from "./sync.js";
8
8
  import { tunnel } from "./tunnel.js";
9
- /**
10
- * Returns a {@link StreamSync} instance which creates & attaches
11
- * multiple subscriptions to given `src` input stream, processes each
12
- * received value in parallel via web workers, then recombines partial
13
- * results and passes the resulting transformed value downstream.
14
- *
15
- * @remarks
16
- * See {@link ForkJoinOpts} for further details & behavior options and
17
- * the {@link forkBuffer} and {@link joinBuffer} helpers for array-based
18
- * value processing (most likely use case).
19
- *
20
- * @param src - input stream
21
- * @param opts -
22
- */
23
- export const forkJoin = (opts) => {
24
- const numWorkers = opts.numWorkers || navigator.hardwareConcurrency || 4;
25
- const workerIDs = range(numWorkers);
26
- return sync({
27
- src: transduce(map((id) => [
28
- String(id),
29
- opts.src
30
- .transform(map((x) => opts.fork(id, numWorkers, x)))
31
- .subscribe(tunnel({
32
- src: opts.worker,
33
- transferables: opts.transferables,
34
- interrupt: opts.interrupt === true,
35
- terminate: opts.terminate,
36
- id: String(id),
37
- })),
38
- ]), assocObj(), workerIDs),
39
- xform: comp(
40
- // form result tuple in original order
41
- map((results) => [...map((id) => results[id], workerIDs)]),
42
- // apply user join function
43
- map(opts.join)),
44
- reset: true,
45
- backPressure: opts.backPressure,
46
- });
9
+ const forkJoin = (opts) => {
10
+ const numWorkers = opts.numWorkers || navigator.hardwareConcurrency || 4;
11
+ const workerIDs = range(numWorkers);
12
+ return sync({
13
+ src: transduce(
14
+ map((id) => [
15
+ String(id),
16
+ opts.src.transform(map((x) => opts.fork(id, numWorkers, x))).subscribe(
17
+ tunnel({
18
+ src: opts.worker,
19
+ transferables: opts.transferables,
20
+ interrupt: opts.interrupt === true,
21
+ terminate: opts.terminate,
22
+ id: String(id)
23
+ })
24
+ )
25
+ ]),
26
+ assocObj(),
27
+ workerIDs
28
+ ),
29
+ xform: comp(
30
+ // form result tuple in original order
31
+ map((results) => [...map((id) => results[id], workerIDs)]),
32
+ // apply user join function
33
+ map(opts.join)
34
+ ),
35
+ reset: true,
36
+ backPressure: opts.backPressure
37
+ });
47
38
  };
48
- /**
49
- * Higher-order fork function for scenarios involving the split-parallel
50
- * processing of a large buffer.
51
- *
52
- * @remarks
53
- * The returned function is meant to be used as `fork` function in a
54
- * {@link ForkJoinOpts} config and extracts a workload slice of the
55
- * original buffer for a single worker. The HOF itself takes a minimum
56
- * chunk size as optional parameter (default: 1).
57
- *
58
- * **Note:** Depending on the configured `minChunkSize` and the size of
59
- * the input buffer to be partitioned, the returned fork function might
60
- * produce empty sub-arrays for some workers, iff the configured number
61
- * of workers exceeds the resulting number of chunks / input values.
62
- * E.g. If the number of workers = 8, buffer size = 10 and min chunk
63
- * size = 2, then the last 3 (i.e. 8 - 10 / 2) workers will only receive
64
- * empty workloads.
65
- *
66
- * More generally, if the input buffer size is not equally distributable
67
- * over the given number of workers, the last worker(s) might receive a
68
- * larger, smaller or empty chunk.
69
- *
70
- * Also see {@link forkJoin} and {@link joinBuffer}.
71
- *
72
- * @example
73
- * ```ts
74
- * forkJoin<number[], number[], number[], number[]>({
75
- * src,
76
- * // job definition / split buffer into chunks (min size 256 values)
77
- * fork: forkBuffer(256),
78
- * // re-join partial results
79
- * join: joinBuffer(),
80
- * worker: "./worker.js",
81
- * })
82
- * ```
83
- *
84
- * @param minChunkSize -
85
- */
86
- export const forkBuffer = (minChunkSize = 1) => (id, numWorkers, buf) => {
87
- const chunkSize = Math.max(minChunkSize, (buf.length / numWorkers) | 0);
88
- return id < numWorkers - 1
89
- ? buf.slice(id * chunkSize, (id + 1) * chunkSize)
90
- : buf.slice(id * chunkSize);
39
+ const forkBuffer = (minChunkSize = 1) => (id, numWorkers, buf) => {
40
+ const chunkSize = Math.max(minChunkSize, buf.length / numWorkers | 0);
41
+ return id < numWorkers - 1 ? buf.slice(id * chunkSize, (id + 1) * chunkSize) : buf.slice(id * chunkSize);
42
+ };
43
+ const joinBuffer = (fn) => fn ? (parts) => [...mapcat(fn, parts)] : (parts) => Array.prototype.concat.apply([], parts);
44
+ export {
45
+ forkBuffer,
46
+ forkJoin,
47
+ joinBuffer
91
48
  };
92
- /**
93
- * Higher-order join function for scenarios involving the split-parallel
94
- * processing of a large buffer.
95
- *
96
- * @remarks
97
- * The returned function is meant to be used as `join` function in a
98
- * {@link ForkJoinOpts} config, receives the processed result chunks
99
- * from all workers (ordered by worker ID) and concatenates them back
100
- * into a single result array.
101
- *
102
- * The optional `fn` arg can be used to pick the actual result chunk
103
- * from each worker result. This is useful if the worker result type is
104
- * not an array and includes other data points (e.g. execution metrics
105
- * etc.). If `fn` is not given, it defaults to the identity function
106
- * (i.e. each worker's result is assumed to be an array).
107
- *
108
- * Also see {@link forkJoin} and {@link forkBuffer}.
109
- *
110
- * @param fn -
111
- */
112
- export const joinBuffer = (fn) => fn
113
- ? (parts) => [...mapcat(fn, parts)]
114
- : (parts) => Array.prototype.concat.apply([], parts);
package/idgen.js CHANGED
@@ -1,9 +1,7 @@
1
1
  let NEXT_ID = 0;
2
- export const __nextID = () => NEXT_ID++;
3
- /**
4
- * @param prefix -
5
- * @param opts -
6
- *
7
- * @internal
8
- */
9
- export const __optsWithID = (prefix, opts) => ((!opts || !opts.id ? { ...opts, id: prefix + "-" + __nextID() } : opts));
2
+ const __nextID = () => NEXT_ID++;
3
+ const __optsWithID = (prefix, opts) => !opts || !opts.id ? { ...opts, id: prefix + "-" + __nextID() } : opts;
4
+ export {
5
+ __nextID,
6
+ __optsWithID
7
+ };
@@ -1,7 +1,10 @@
1
- export const __removeAllIDs = (impl, ids) => {
2
- let ok = true;
3
- for (let id of ids) {
4
- ok = impl.removeID(id) && ok;
5
- }
6
- return ok;
1
+ const __removeAllIDs = (impl, ids) => {
2
+ let ok = true;
3
+ for (let id of ids) {
4
+ ok = impl.removeID(id) && ok;
5
+ }
6
+ return ok;
7
+ };
8
+ export {
9
+ __removeAllIDs
7
10
  };
package/interval.js CHANGED
@@ -1,33 +1,25 @@
1
1
  import { CloseMode } from "./api.js";
2
2
  import { __optsWithID } from "./idgen.js";
3
3
  import { stream } from "./stream.js";
4
- /**
5
- * Returns a {@link Stream} of monotonically increasing counter values,
6
- * emitted at given `delay` interval and up to the optionally defined
7
- * max value (default: ∞), after which the stream is closed.
8
- *
9
- * @remarks
10
- * The stream only starts when the first subscriber becomes available.
11
- *
12
- * @param delay -
13
- * @param opts -
14
- */
15
- export const fromInterval = (delay, opts) => {
16
- opts = __optsWithID("interval", {
17
- num: Infinity,
18
- ...opts,
19
- });
20
- return stream((stream) => {
21
- let i = 0;
22
- let count = opts.num;
23
- stream.next(i++);
24
- let id = setInterval(() => {
25
- stream.next(i++);
26
- if (--count <= 0) {
27
- clearInterval(id);
28
- stream.closeIn !== CloseMode.NEVER && stream.done();
29
- }
30
- }, delay);
31
- return () => clearInterval(id);
32
- }, opts);
4
+ const fromInterval = (delay, opts) => {
5
+ opts = __optsWithID("interval", {
6
+ num: Infinity,
7
+ ...opts
8
+ });
9
+ return stream((stream2) => {
10
+ let i = 0;
11
+ let count = opts.num;
12
+ stream2.next(i++);
13
+ let id = setInterval(() => {
14
+ stream2.next(i++);
15
+ if (--count <= 0) {
16
+ clearInterval(id);
17
+ stream2.closeIn !== CloseMode.NEVER && stream2.done();
18
+ }
19
+ }, delay);
20
+ return () => clearInterval(id);
21
+ }, opts);
22
+ };
23
+ export {
24
+ fromInterval
33
25
  };