@thi.ng/rstream 6.0.21 → 7.0.4
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 +49 -620
- package/README.md +70 -52
- package/api.d.ts +2 -4
- package/api.js +0 -3
- package/{subs/asidechain.d.ts → asidechain.d.ts} +2 -2
- package/{subs/asidechain.js → asidechain.js} +1 -1
- package/{from/atom.d.ts → atom.d.ts} +2 -3
- package/{from/atom.js → atom.js} +8 -4
- package/{subs/bisect.d.ts → bisect.d.ts} +2 -2
- package/{subs/bisect.js → bisect.js} +3 -3
- package/{utils/checks.d.ts → checks.d.ts} +2 -1
- package/{utils/checks.js → checks.js} +3 -1
- package/{subs/debounce.d.ts → debounce.d.ts} +2 -2
- package/{subs/debounce.js → debounce.js} +7 -4
- package/defworker.d.ts +3 -0
- package/defworker.js +4 -0
- package/{from/event.d.ts → event.d.ts} +2 -2
- package/{from/event.js → event.js} +4 -4
- package/forkjoin.d.ts +2 -2
- package/forkjoin.js +8 -3
- package/idgen.d.ts +10 -0
- package/idgen.js +9 -0
- package/index.d.ts +35 -33
- package/index.js +35 -33
- package/internal/remove.d.ts +4 -0
- package/internal/remove.js +7 -0
- package/{from/interval.d.ts → interval.d.ts} +2 -3
- package/{from/interval.js → interval.js} +8 -5
- package/{from/iterable.d.ts → iterable.d.ts} +3 -4
- package/{from/iterable.js → iterable.js} +7 -7
- package/logger.d.ts +4 -0
- package/logger.js +3 -0
- package/{stream-merge.d.ts → merge.d.ts} +3 -3
- package/{stream-merge.js → merge.js} +7 -10
- package/metastream.d.ts +3 -3
- package/metastream.js +5 -5
- package/{from/object.d.ts → object.d.ts} +2 -2
- package/{from/object.js → object.js} +13 -6
- package/package.json +140 -31
- package/{subs/post-worker.d.ts → post-worker.d.ts} +1 -1
- package/{subs/post-worker.js → post-worker.js} +5 -4
- package/{from/promise.d.ts → promise.d.ts} +2 -3
- package/{from/promise.js → promise.js} +5 -5
- package/{from/promises.d.ts → promises.d.ts} +1 -1
- package/{from/promises.js → promises.js} +4 -4
- package/pubsub.d.ts +3 -3
- package/pubsub.js +12 -8
- package/{from/raf.d.ts → raf.d.ts} +2 -3
- package/{from/raf.js → raf.js} +6 -6
- package/{subs/resolve.d.ts → resolve.d.ts} +1 -1
- package/{subs/resolve.js → resolve.js} +5 -4
- package/{subs/sidechain-partition.d.ts → sidechain-partition.d.ts} +4 -4
- package/{subs/sidechain-partition.js → sidechain-partition.js} +7 -7
- package/{subs/sidechain-toggle.d.ts → sidechain-toggle.d.ts} +3 -3
- package/{subs/sidechain-toggle.js → sidechain-toggle.js} +4 -4
- package/stream.d.ts +2 -2
- package/stream.js +6 -5
- package/subscription.d.ts +4 -3
- package/subscription.js +26 -12
- package/{stream-sync.d.ts → sync.d.ts} +4 -4
- package/{stream-sync.js → sync.js} +15 -12
- package/{subs/timeout.d.ts → timeout.d.ts} +2 -2
- package/{subs/timeout.js → timeout.js} +4 -4
- package/{subs/trace.d.ts → trace.d.ts} +1 -1
- package/{subs/trace.js → trace.js} +0 -0
- package/{subs/transduce.d.ts → transduce.d.ts} +1 -1
- package/{subs/transduce.js → transduce.js} +1 -1
- package/trigger.d.ts +2 -2
- package/trigger.js +3 -3
- package/{subs/tunnel.d.ts → tunnel.d.ts} +1 -1
- package/{subs/tunnel.js → tunnel.js} +7 -6
- package/tween.d.ts +5 -5
- package/tween.js +8 -6
- package/{from/view.d.ts → view.d.ts} +3 -3
- package/{from/view.js → view.js} +4 -4
- package/{from/worker.d.ts → worker.d.ts} +2 -3
- package/{from/worker.js → worker.js} +7 -7
- package/lib/index.js +0 -1148
- package/lib/index.js.map +0 -1
- package/lib/index.umd.js +0 -1
- package/lib/index.umd.js.map +0 -1
- package/utils/idgen.d.ts +0 -4
- package/utils/idgen.js +0 -3
- package/utils/worker.d.ts +0 -3
- package/utils/worker.js +0 -4
package/pubsub.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { EquivMap } from "@thi.ng/associative";
|
|
2
|
-
import { unsupported } from "@thi.ng/errors";
|
|
3
|
-
import { CloseMode,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { EquivMap } from "@thi.ng/associative/equiv-map";
|
|
2
|
+
import { unsupported } from "@thi.ng/errors/unsupported";
|
|
3
|
+
import { CloseMode, } from "./api.js";
|
|
4
|
+
import { __optsWithID } from "./idgen.js";
|
|
5
|
+
import { LOGGER } from "./logger.js";
|
|
6
|
+
import { Subscription, subscription } from "./subscription.js";
|
|
6
7
|
/**
|
|
7
8
|
* Topic based stream splitter. Applies `topic` function to each received value
|
|
8
9
|
* and only forwards it to the child subscriptions of the returned topic.
|
|
@@ -35,7 +36,7 @@ export const pubsub = (opts) => new PubSub(opts);
|
|
|
35
36
|
*/
|
|
36
37
|
export class PubSub extends Subscription {
|
|
37
38
|
constructor(opts) {
|
|
38
|
-
super(undefined,
|
|
39
|
+
super(undefined, __optsWithID("pubsub", {
|
|
39
40
|
xform: opts.xform,
|
|
40
41
|
}));
|
|
41
42
|
this.topicfn = opts.topic;
|
|
@@ -58,13 +59,16 @@ export class PubSub extends Subscription {
|
|
|
58
59
|
subscribeTopic(topicID, sub, opts) {
|
|
59
60
|
let t = this.topics.get(topicID);
|
|
60
61
|
!t &&
|
|
61
|
-
this.topics.set(topicID, (t = subscription(undefined,
|
|
62
|
+
this.topics.set(topicID, (t = subscription(undefined, __optsWithID("topic", {
|
|
62
63
|
closeOut: CloseMode.NEVER,
|
|
63
64
|
}))));
|
|
64
65
|
return t.subscribe(sub, opts);
|
|
65
66
|
}
|
|
66
67
|
transformTopic(topicID, xform, opts = {}) {
|
|
67
|
-
return this.subscribeTopic(topicID, { error: opts.error },
|
|
68
|
+
return this.subscribeTopic(topicID, { error: opts.error }, {
|
|
69
|
+
...opts,
|
|
70
|
+
xform,
|
|
71
|
+
});
|
|
68
72
|
}
|
|
69
73
|
unsubscribeTopic(topicID, sub) {
|
|
70
74
|
const t = this.topics.get(topicID);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { CommonOpts } from "
|
|
2
|
-
import { Stream } from "../stream";
|
|
1
|
+
import type { CommonOpts } from "./api.js";
|
|
3
2
|
/**
|
|
4
3
|
* Yields {@link Stream} of a monotonically increasing counter,
|
|
5
4
|
* triggered by a `requestAnimationFrame()` loop (only available in
|
|
@@ -12,5 +11,5 @@ import { Stream } from "../stream";
|
|
|
12
11
|
* All subscribers to this stream will be processed during that same
|
|
13
12
|
* loop iteration.
|
|
14
13
|
*/
|
|
15
|
-
export declare const fromRAF: (opts?: Partial<CommonOpts> | undefined) => Stream<number>;
|
|
14
|
+
export declare const fromRAF: (opts?: Partial<CommonOpts> | undefined) => import("./stream.js").Stream<number>;
|
|
16
15
|
//# sourceMappingURL=raf.d.ts.map
|
package/{from/raf.js → raf.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isNode } from "@thi.ng/checks";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { isNode } from "@thi.ng/checks/is-node";
|
|
2
|
+
import { __optsWithID } from "./idgen.js";
|
|
3
|
+
import { fromInterval } from "./interval.js";
|
|
4
|
+
import { stream } from "./stream.js";
|
|
5
5
|
/**
|
|
6
6
|
* Yields {@link Stream} of a monotonically increasing counter,
|
|
7
7
|
* triggered by a `requestAnimationFrame()` loop (only available in
|
|
@@ -16,7 +16,7 @@ import { fromInterval } from "./interval";
|
|
|
16
16
|
*/
|
|
17
17
|
export const fromRAF = (opts) => isNode()
|
|
18
18
|
? fromInterval(16, opts)
|
|
19
|
-
:
|
|
19
|
+
: stream((stream) => {
|
|
20
20
|
let i = 0;
|
|
21
21
|
let isActive = true;
|
|
22
22
|
const loop = () => {
|
|
@@ -28,4 +28,4 @@ export const fromRAF = (opts) => isNode()
|
|
|
28
28
|
isActive = false;
|
|
29
29
|
cancelAnimationFrame(id);
|
|
30
30
|
};
|
|
31
|
-
},
|
|
31
|
+
}, __optsWithID("raf", opts));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { State } from "./api.js";
|
|
2
|
+
import { __optsWithID } from "./idgen.js";
|
|
3
|
+
import { LOGGER } from "./logger.js";
|
|
4
|
+
import { Subscription } from "./subscription.js";
|
|
4
5
|
/**
|
|
5
6
|
* Creates a {@link Subscription} which receives promises, buffers them
|
|
6
7
|
* and then passes their resolved values downstream.
|
|
@@ -28,7 +29,7 @@ import { optsWithID } from "../utils/idgen";
|
|
|
28
29
|
export const resolve = (opts) => new Resolver(opts);
|
|
29
30
|
export class Resolver extends Subscription {
|
|
30
31
|
constructor(opts = {}) {
|
|
31
|
-
super(undefined,
|
|
32
|
+
super(undefined, __optsWithID("resolve"));
|
|
32
33
|
this.outstanding = 0;
|
|
33
34
|
this.fail = opts.fail;
|
|
34
35
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Predicate } from "@thi.ng/api";
|
|
2
|
-
import { CommonOpts, ISubscribable } from "
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
2
|
+
import { CommonOpts, ISubscribable } from "./api.js";
|
|
3
|
+
import { ASidechain } from "./asidechain.js";
|
|
4
|
+
import type { Subscription } from "./subscription.js";
|
|
5
5
|
export interface SidechainPartitionOpts<T> extends CommonOpts {
|
|
6
6
|
pred: Predicate<T>;
|
|
7
7
|
}
|
|
@@ -43,7 +43,7 @@ export declare const sidechainPartition: <A, B>(side: ISubscribable<B>, opts?: P
|
|
|
43
43
|
* @param src
|
|
44
44
|
* @returns
|
|
45
45
|
*/
|
|
46
|
-
export declare const sidechainPartitionRAF: <T>(src: ISubscribable<T>) => import("
|
|
46
|
+
export declare const sidechainPartitionRAF: <T>(src: ISubscribable<T>) => import("./api.js").ISubscription<T[], T>;
|
|
47
47
|
export declare class SidechainPartition<T, S> extends ASidechain<T, S, T[]> {
|
|
48
48
|
buf: T[];
|
|
49
49
|
constructor(side: ISubscribable<S>, opts?: Partial<SidechainPartitionOpts<S>>);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { peek } from "@thi.ng/arrays";
|
|
2
|
-
import { map } from "@thi.ng/transducers";
|
|
3
|
-
import { State } from "
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { peek } from "@thi.ng/arrays/peek";
|
|
2
|
+
import { map } from "@thi.ng/transducers/map";
|
|
3
|
+
import { State } from "./api.js";
|
|
4
|
+
import { ASidechain } from "./asidechain.js";
|
|
5
|
+
import { __optsWithID } from "./idgen.js";
|
|
6
|
+
import { fromRAF } from "./raf.js";
|
|
7
7
|
/**
|
|
8
8
|
* Returns a {@link Subscription} which buffers values from `src` until
|
|
9
9
|
* side chain fires, then emits buffer (unless empty) and repeats
|
|
@@ -47,7 +47,7 @@ export const sidechainPartitionRAF = (src) => src
|
|
|
47
47
|
.transform(map(peek));
|
|
48
48
|
export class SidechainPartition extends ASidechain {
|
|
49
49
|
constructor(side, opts) {
|
|
50
|
-
opts =
|
|
50
|
+
opts = __optsWithID("sidepart", opts);
|
|
51
51
|
super(opts);
|
|
52
52
|
this.buf = [];
|
|
53
53
|
const pred = opts.pred || (() => true);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Predicate } from "@thi.ng/api";
|
|
2
|
-
import { CommonOpts, ISubscribable } from "
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
2
|
+
import { CommonOpts, ISubscribable } from "./api.js";
|
|
3
|
+
import { ASidechain } from "./asidechain.js";
|
|
4
|
+
import type { Subscription } from "./subscription.js";
|
|
5
5
|
export interface SidechainToggleOpts<T> extends CommonOpts {
|
|
6
6
|
pred: Predicate<T>;
|
|
7
7
|
initial: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { State } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { State } from "./api.js";
|
|
2
|
+
import { ASidechain } from "./asidechain.js";
|
|
3
|
+
import { __optsWithID } from "./idgen.js";
|
|
4
4
|
/**
|
|
5
5
|
* Returns {@link Subscription} which filters values from input based on
|
|
6
6
|
* values received from side chain.
|
|
@@ -32,7 +32,7 @@ import { ASidechain } from "./asidechain";
|
|
|
32
32
|
export const sidechainToggle = (side, opts) => new SidechainToggle(side, opts);
|
|
33
33
|
export class SidechainToggle extends ASidechain {
|
|
34
34
|
constructor(side, opts) {
|
|
35
|
-
opts =
|
|
35
|
+
opts = __optsWithID("sidetoggle", opts);
|
|
36
36
|
super(opts);
|
|
37
37
|
this.isActive = !!opts.initial;
|
|
38
38
|
const pred = opts.pred || (() => true);
|
package/stream.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CommonOpts, IStream, ISubscriber, ISubscription, StreamCancel, StreamSource, TransformableOpts, WithErrorHandlerOpts } from "./api";
|
|
2
|
-
import { Subscription } from "./subscription";
|
|
1
|
+
import { CommonOpts, IStream, ISubscriber, ISubscription, StreamCancel, StreamSource, TransformableOpts, WithErrorHandlerOpts } from "./api.js";
|
|
2
|
+
import { Subscription } from "./subscription.js";
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new {@link Stream} instance, optionally with given
|
|
5
5
|
* `StreamSource` function and / or options.
|
package/stream.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { isFunction } from "@thi.ng/checks";
|
|
2
|
-
import { CloseMode,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { isFunction } from "@thi.ng/checks/is-function";
|
|
2
|
+
import { CloseMode, } from "./api.js";
|
|
3
|
+
import { __optsWithID } from "./idgen.js";
|
|
4
|
+
import { LOGGER } from "./logger.js";
|
|
5
|
+
import { Subscription } from "./subscription.js";
|
|
5
6
|
export function stream(src, opts) {
|
|
6
7
|
return new Stream(src, opts);
|
|
7
8
|
}
|
|
@@ -26,7 +27,7 @@ export class Stream extends Subscription {
|
|
|
26
27
|
const [_src, _opts] = isFunction(src)
|
|
27
28
|
? [src, opts || {}]
|
|
28
29
|
: [undefined, src || {}];
|
|
29
|
-
super(_opts.error ? { error: _opts.error } : undefined,
|
|
30
|
+
super(_opts.error ? { error: _opts.error } : undefined, __optsWithID("stream", _opts));
|
|
30
31
|
this.src = _src;
|
|
31
32
|
this._inited = false;
|
|
32
33
|
}
|
package/subscription.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Fn } from "@thi.ng/api";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { Fn } from "@thi.ng/api";
|
|
2
|
+
import type { Reducer, Transducer } from "@thi.ng/transducers";
|
|
3
|
+
import { Reduced } from "@thi.ng/transducers/reduced";
|
|
4
|
+
import { CloseMode, CommonOpts, ISubscriber, ISubscription, State, SubscriptionOpts, TransformableOpts, WithErrorHandlerOpts, WithTransform } from "./api.js";
|
|
4
5
|
/**
|
|
5
6
|
* Creates a new {@link Subscription} instance, the fundamental datatype
|
|
6
7
|
* and building block provided by this package.
|
package/subscription.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { peek } from "@thi.ng/arrays";
|
|
3
|
-
import { isPlainObject } from "@thi.ng/checks";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { SEMAPHORE } from "@thi.ng/api/api";
|
|
2
|
+
import { peek } from "@thi.ng/arrays/peek";
|
|
3
|
+
import { isPlainObject } from "@thi.ng/checks/is-plain-object";
|
|
4
|
+
import { assert } from "@thi.ng/errors/assert";
|
|
5
|
+
import { illegalState } from "@thi.ng/errors/illegal-state";
|
|
6
|
+
import { NULL_LOGGER } from "@thi.ng/logger/null";
|
|
7
|
+
import { comp } from "@thi.ng/transducers/comp";
|
|
8
|
+
import { map } from "@thi.ng/transducers/map";
|
|
9
|
+
import { push } from "@thi.ng/transducers/push";
|
|
10
|
+
import { isReduced, unreduced } from "@thi.ng/transducers/reduced";
|
|
11
|
+
import { CloseMode, State, } from "./api.js";
|
|
12
|
+
import { __optsWithID } from "./idgen.js";
|
|
13
|
+
import { LOGGER } from "./logger.js";
|
|
8
14
|
/**
|
|
9
15
|
* Creates a new {@link Subscription} instance, the fundamental datatype
|
|
10
16
|
* and building block provided by this package.
|
|
@@ -61,7 +67,12 @@ export class Subscription {
|
|
|
61
67
|
this.last = SEMAPHORE;
|
|
62
68
|
this.state = State.IDLE;
|
|
63
69
|
this.subs = [];
|
|
64
|
-
opts =
|
|
70
|
+
opts = __optsWithID(`sub`, {
|
|
71
|
+
closeIn: CloseMode.LAST,
|
|
72
|
+
closeOut: CloseMode.LAST,
|
|
73
|
+
cache: true,
|
|
74
|
+
...opts,
|
|
75
|
+
});
|
|
65
76
|
this.parent = opts.parent;
|
|
66
77
|
this.id = opts.id;
|
|
67
78
|
this.closeIn = opts.closeIn;
|
|
@@ -89,7 +100,7 @@ export class Subscription {
|
|
|
89
100
|
$sub = sub;
|
|
90
101
|
}
|
|
91
102
|
else {
|
|
92
|
-
$sub = new Subscription(sub,
|
|
103
|
+
$sub = new Subscription(sub, { ...opts, parent: this });
|
|
93
104
|
}
|
|
94
105
|
this.subs.push($sub);
|
|
95
106
|
this.setState(State.ACTIVE);
|
|
@@ -104,10 +115,13 @@ export class Subscription {
|
|
|
104
115
|
opts = args.pop();
|
|
105
116
|
sub = { error: opts.error };
|
|
106
117
|
}
|
|
107
|
-
return this.subscribe(sub,
|
|
108
|
-
?
|
|
118
|
+
return this.subscribe(sub, __optsWithID("xform", args.length > 0
|
|
119
|
+
? {
|
|
120
|
+
...opts,
|
|
109
121
|
// @ts-ignore
|
|
110
|
-
xform: comp(...args)
|
|
122
|
+
xform: comp(...args),
|
|
123
|
+
}
|
|
124
|
+
: opts));
|
|
111
125
|
}
|
|
112
126
|
/**
|
|
113
127
|
* Syntax sugar for {@link Subscription.transform} when using a
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Always, Derefed, IObjectOf } from "@thi.ng/api";
|
|
2
|
-
import { PartitionSync } from "@thi.ng/transducers";
|
|
3
|
-
import { ISubscribable, ISubscription, TransformableOpts } from "./api";
|
|
4
|
-
import { Subscription } from "./subscription";
|
|
2
|
+
import { PartitionSync } from "@thi.ng/transducers/partition-sync";
|
|
3
|
+
import type { ISubscribable, ISubscription, TransformableOpts } from "./api.js";
|
|
4
|
+
import { Subscription } from "./subscription.js";
|
|
5
5
|
export declare type SyncTuple<T extends IObjectOf<ISubscribable<any>>> = {
|
|
6
6
|
[id in keyof T]: Always<Derefed<T[id]>>;
|
|
7
7
|
};
|
|
@@ -140,4 +140,4 @@ export declare class StreamSync<A extends IObjectOf<ISubscribable<any>>, B = Syn
|
|
|
140
140
|
unsubscribe(sub?: ISubscription<B, any>): boolean;
|
|
141
141
|
protected markDone(src: ISubscribable<any>): void;
|
|
142
142
|
}
|
|
143
|
-
//# sourceMappingURL=
|
|
143
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { comp
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { comp } from "@thi.ng/transducers/comp";
|
|
2
|
+
import { labeled } from "@thi.ng/transducers/labeled";
|
|
3
|
+
import { mapVals } from "@thi.ng/transducers/map-vals";
|
|
4
|
+
import { partitionSync, } from "@thi.ng/transducers/partition-sync";
|
|
5
|
+
import { isFirstOrLastInput } from "./checks.js";
|
|
6
|
+
import { __optsWithID } from "./idgen.js";
|
|
7
|
+
import { __removeAllIDs } from "./internal/remove.js";
|
|
8
|
+
import { LOGGER } from "./logger.js";
|
|
9
|
+
import { Subscription } from "./subscription.js";
|
|
6
10
|
/**
|
|
7
11
|
* Similar to {@link StreamMerge}, but with extra synchronization of inputs.
|
|
8
12
|
* Before emitting any new values, {@link StreamSync} collects values until at
|
|
@@ -67,9 +71,12 @@ export class StreamSync extends Subscription {
|
|
|
67
71
|
backPressure: opts.backPressure || 0,
|
|
68
72
|
});
|
|
69
73
|
const mapv = mapVals((x) => x[1]);
|
|
70
|
-
super(undefined,
|
|
74
|
+
super(undefined, __optsWithID("streamsync", {
|
|
75
|
+
...opts,
|
|
76
|
+
xform: opts.xform
|
|
71
77
|
? comp(psync, mapv, opts.xform)
|
|
72
|
-
: comp(psync, mapv)
|
|
78
|
+
: comp(psync, mapv),
|
|
79
|
+
}));
|
|
73
80
|
this.sources = new Map();
|
|
74
81
|
this.realSourceIDs = new Map();
|
|
75
82
|
this.invRealSourceIDs = new Map();
|
|
@@ -135,11 +142,7 @@ export class StreamSync extends Subscription {
|
|
|
135
142
|
return ok;
|
|
136
143
|
}
|
|
137
144
|
removeAllIDs(ids) {
|
|
138
|
-
|
|
139
|
-
for (let id of ids) {
|
|
140
|
-
ok = this.removeID(id) && ok;
|
|
141
|
-
}
|
|
142
|
-
return ok;
|
|
145
|
+
return __removeAllIDs(this, ids);
|
|
143
146
|
}
|
|
144
147
|
getSourceForID(id) {
|
|
145
148
|
return this.idSources.get(this.realSourceIDs.get(id));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { State } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { State } from "./api.js";
|
|
2
|
+
import { __optsWithID } from "./idgen.js";
|
|
3
|
+
import { Subscription } from "./subscription.js";
|
|
4
4
|
/**
|
|
5
5
|
* Returns a {@link Subscription} that calls the
|
|
6
6
|
* {@link ISubscriber.error} handlers of all child subscriptions with an
|
|
@@ -22,7 +22,7 @@ export const timeout = (timeoutMs, opts) => new Timeout(timeoutMs, opts);
|
|
|
22
22
|
*/
|
|
23
23
|
class Timeout extends Subscription {
|
|
24
24
|
constructor(timeoutMs, opts) {
|
|
25
|
-
opts =
|
|
25
|
+
opts = __optsWithID("timeout", opts);
|
|
26
26
|
super(undefined, opts);
|
|
27
27
|
this.timeoutMs = timeoutMs;
|
|
28
28
|
this.errorObj = opts.error;
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Reducer, Transducer } from "@thi.ng/transducers";
|
|
2
|
-
import type { Subscription } from "
|
|
2
|
+
import type { Subscription } from "./subscription.js";
|
|
3
3
|
/**
|
|
4
4
|
* Returns a promise which subscribes to given input and transforms
|
|
5
5
|
* incoming values using given transducer `xform` and reducer `rfn`.
|
package/trigger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CommonOpts } from "./api";
|
|
2
|
-
import type { Stream } from "./stream";
|
|
1
|
+
import type { CommonOpts } from "./api.js";
|
|
2
|
+
import type { Stream } from "./stream.js";
|
|
3
3
|
/**
|
|
4
4
|
* Utility stream. Returns a new stream which emits a single value `x` (if
|
|
5
5
|
* given) and then closes. If no arg is provided, the stream emits a single
|
package/trigger.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { __optsWithID } from "./idgen.js";
|
|
2
|
+
import { fromIterableSync } from "./iterable.js";
|
|
3
3
|
export function trigger(x = true, opts) {
|
|
4
|
-
return fromIterableSync([x],
|
|
4
|
+
return fromIterableSync([x], __optsWithID("trigger", opts));
|
|
5
5
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { State } from "./api.js";
|
|
2
|
+
import { __nextID } from "./idgen.js";
|
|
3
|
+
import { LOGGER } from "./logger.js";
|
|
4
|
+
import { Subscription } from "./subscription.js";
|
|
5
|
+
import { defWorker } from "./defworker.js";
|
|
5
6
|
/**
|
|
6
7
|
* Returns a {@link Subscription} which processes received values via
|
|
7
8
|
* the configured worker(s) and then passes values received back from
|
|
@@ -22,7 +23,7 @@ export const tunnel = (opts) => new Tunnel(opts);
|
|
|
22
23
|
*/
|
|
23
24
|
export class Tunnel extends Subscription {
|
|
24
25
|
constructor(opts) {
|
|
25
|
-
super(undefined, { id: opts.id || `tunnel-${
|
|
26
|
+
super(undefined, { id: opts.id || `tunnel-${__nextID()}` });
|
|
26
27
|
this.src = opts.src;
|
|
27
28
|
this.workers = new Array(opts.maxWorkers || 1);
|
|
28
29
|
this.transferables = opts.transferables;
|
|
@@ -42,7 +43,7 @@ export class Tunnel extends Subscription {
|
|
|
42
43
|
worker = null;
|
|
43
44
|
}
|
|
44
45
|
if (!worker) {
|
|
45
|
-
this.workers[this.index++] = worker =
|
|
46
|
+
this.workers[this.index++] = worker = defWorker(this.src);
|
|
46
47
|
this.index %= this.workers.length;
|
|
47
48
|
worker.addEventListener("message", (e) => this.dispatch(e.data));
|
|
48
49
|
worker.addEventListener("error", (e) => this.error(e));
|
package/tween.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Fn2 } from "@thi.ng/api";
|
|
2
|
-
import { ISubscribable } from "./api";
|
|
2
|
+
import { ISubscribable } from "./api.js";
|
|
3
3
|
/**
|
|
4
4
|
* Takes an existing stream/subscription `src` and attaches new
|
|
5
5
|
* subscription which interpolates between incoming values from `src`
|
|
@@ -54,9 +54,9 @@ import { ISubscribable } from "./api";
|
|
|
54
54
|
* @param stop -
|
|
55
55
|
* @param clock -
|
|
56
56
|
*/
|
|
57
|
-
export declare const tween: <T>(src: ISubscribable<T>, initial: T, mix: Fn2<T, T, T>, stop?: Fn2<T, T, boolean> | undefined, clock?: number | ISubscribable<any> | undefined) => import("./api").ISubscription<import("./
|
|
57
|
+
export declare const tween: <T>(src: ISubscribable<T>, initial: T, mix: Fn2<T, T, T>, stop?: Fn2<T, T, boolean> | undefined, clock?: number | ISubscribable<any> | undefined) => import("./api.js").ISubscription<import("./sync.js").SyncTuple<{
|
|
58
58
|
src: ISubscribable<T>;
|
|
59
|
-
_: ISubscribable<any> | import("./stream").Stream<number>;
|
|
59
|
+
_: ISubscribable<any> | import("./stream.js").Stream<number>;
|
|
60
60
|
}>, T>;
|
|
61
61
|
/**
|
|
62
62
|
* Convenience version of {@link tween} for its most common use case, tweening
|
|
@@ -68,8 +68,8 @@ export declare const tween: <T>(src: ISubscribable<T>, initial: T, mix: Fn2<T, T
|
|
|
68
68
|
* @param eps -
|
|
69
69
|
* @param clock -
|
|
70
70
|
*/
|
|
71
|
-
export declare const tweenNumber: (src: ISubscribable<number>, init?: number, speed?: number, eps?: number, clock?: number | ISubscribable<any> | undefined) => import("./api").ISubscription<import("./
|
|
71
|
+
export declare const tweenNumber: (src: ISubscribable<number>, init?: number, speed?: number, eps?: number, clock?: number | ISubscribable<any> | undefined) => import("./api.js").ISubscription<import("./sync.js").SyncTuple<{
|
|
72
72
|
src: ISubscribable<number>;
|
|
73
|
-
_: ISubscribable<any> | import("./stream").Stream<number>;
|
|
73
|
+
_: ISubscribable<any> | import("./stream.js").Stream<number>;
|
|
74
74
|
}>, number>;
|
|
75
75
|
//# sourceMappingURL=tween.d.ts.map
|
package/tween.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { isNumber } from "@thi.ng/checks";
|
|
2
|
-
import { dedupe
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { isNumber } from "@thi.ng/checks/is-number";
|
|
2
|
+
import { dedupe } from "@thi.ng/transducers/dedupe";
|
|
3
|
+
import { reducer } from "@thi.ng/transducers/reduce";
|
|
4
|
+
import { scan } from "@thi.ng/transducers/scan";
|
|
5
|
+
import { CloseMode } from "./api.js";
|
|
6
|
+
import { fromInterval } from "./interval.js";
|
|
7
|
+
import { fromRAF } from "./raf.js";
|
|
8
|
+
import { sync } from "./sync.js";
|
|
7
9
|
/**
|
|
8
10
|
* Takes an existing stream/subscription `src` and attaches new
|
|
9
11
|
* subscription which interpolates between incoming values from `src`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DeepPath, Fn, OptPathVal, Path, Path0, Path1, Path2, Path3, Path4, Path5, Path6, Path7, Path8, Predicate2 } from "@thi.ng/api";
|
|
2
|
-
import { ReadonlyAtom } from "@thi.ng/atom";
|
|
3
|
-
import type { CommonOpts } from "
|
|
4
|
-
import { Stream } from "
|
|
2
|
+
import type { ReadonlyAtom } from "@thi.ng/atom";
|
|
3
|
+
import type { CommonOpts } from "./api.js";
|
|
4
|
+
import { Stream } from "./stream.js";
|
|
5
5
|
export interface FromViewOpts<P, A, B> extends Partial<CommonOpts> {
|
|
6
6
|
path: P;
|
|
7
7
|
tx?: Fn<A, B>;
|
package/{from/view.js → view.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { View } from "@thi.ng/atom";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { View } from "@thi.ng/atom/view";
|
|
2
|
+
import { __optsWithID } from "./idgen.js";
|
|
3
|
+
import { Stream } from "./stream.js";
|
|
4
4
|
/**
|
|
5
5
|
* Unchecked version of {@link fromView}. Paths can be given as string
|
|
6
6
|
* or tuple.
|
|
@@ -32,7 +32,7 @@ import { optsWithID } from "../utils/idgen";
|
|
|
32
32
|
*/
|
|
33
33
|
export const fromViewUnsafe = (atom, opts) => fromView(atom, opts);
|
|
34
34
|
export function fromView(atom, opts) {
|
|
35
|
-
opts =
|
|
35
|
+
opts = __optsWithID("view", opts);
|
|
36
36
|
return new Stream((stream) => {
|
|
37
37
|
let isActive = true;
|
|
38
38
|
const tx = opts.tx;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { WithErrorHandlerOpts } from "
|
|
2
|
-
import { Stream } from "../stream";
|
|
1
|
+
import type { WithErrorHandlerOpts } from "./api.js";
|
|
3
2
|
export interface FromWorkerOpts extends WithErrorHandlerOpts {
|
|
4
3
|
/**
|
|
5
4
|
* If true, the worker will be terminated when the stream
|
|
@@ -32,5 +31,5 @@ export interface FromWorkerOpts extends WithErrorHandlerOpts {
|
|
|
32
31
|
* @param worker -
|
|
33
32
|
* @param opts -
|
|
34
33
|
*/
|
|
35
|
-
export declare const fromWorker: <T>(worker: Worker | Blob | string, opts?: Partial<FromWorkerOpts> | undefined) => Stream<T>;
|
|
34
|
+
export declare const fromWorker: <T>(worker: Worker | Blob | string, opts?: Partial<FromWorkerOpts> | undefined) => import("./stream.js").Stream<T>;
|
|
36
35
|
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { defWorker } from "./defworker.js";
|
|
2
|
+
import { __optsWithID } from "./idgen.js";
|
|
3
|
+
import { LOGGER } from "./logger.js";
|
|
4
|
+
import { stream } from "./stream.js";
|
|
5
5
|
/**
|
|
6
6
|
* Returns a {@link Stream} which adds `message` and `error` event
|
|
7
7
|
* listeners to given `worker` and then emits received values.
|
|
@@ -26,9 +26,9 @@ import { makeWorker } from "../utils/worker";
|
|
|
26
26
|
* @param opts -
|
|
27
27
|
*/
|
|
28
28
|
export const fromWorker = (worker, opts) => {
|
|
29
|
-
const _worker =
|
|
30
|
-
opts =
|
|
31
|
-
return
|
|
29
|
+
const _worker = defWorker(worker);
|
|
30
|
+
opts = __optsWithID("worker", opts);
|
|
31
|
+
return stream((stream) => {
|
|
32
32
|
const msgListener = (e) => {
|
|
33
33
|
stream.next(e.data);
|
|
34
34
|
};
|