@thi.ng/rstream 6.0.19 → 7.0.1
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 +44 -703
- package/README.md +68 -50
- 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} +2 -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} +8 -10
- package/metastream.d.ts +3 -3
- package/metastream.js +10 -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 +14 -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} +7 -5
- package/{subs/sidechain-partition.d.ts → sidechain-partition.d.ts} +4 -4
- package/{subs/sidechain-partition.js → sidechain-partition.js} +8 -7
- package/{subs/sidechain-toggle.d.ts → sidechain-toggle.d.ts} +3 -3
- package/{subs/sidechain-toggle.js → sidechain-toggle.js} +5 -4
- package/stream.d.ts +2 -2
- package/stream.js +9 -5
- package/subscription.d.ts +4 -3
- package/subscription.js +37 -15
- package/{stream-sync.d.ts → sync.d.ts} +4 -4
- package/{stream-sync.js → sync.js} +33 -12
- package/{subs/timeout.d.ts → timeout.d.ts} +2 -2
- package/{subs/timeout.js → timeout.js} +8 -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} +13 -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.
|
|
@@ -34,8 +35,10 @@ export const pubsub = (opts) => new PubSub(opts);
|
|
|
34
35
|
* @see {@link pubsub} for reference & examples.
|
|
35
36
|
*/
|
|
36
37
|
export class PubSub extends Subscription {
|
|
38
|
+
topicfn;
|
|
39
|
+
topics;
|
|
37
40
|
constructor(opts) {
|
|
38
|
-
super(undefined,
|
|
41
|
+
super(undefined, __optsWithID("pubsub", {
|
|
39
42
|
xform: opts.xform,
|
|
40
43
|
}));
|
|
41
44
|
this.topicfn = opts.topic;
|
|
@@ -58,13 +61,16 @@ export class PubSub extends Subscription {
|
|
|
58
61
|
subscribeTopic(topicID, sub, opts) {
|
|
59
62
|
let t = this.topics.get(topicID);
|
|
60
63
|
!t &&
|
|
61
|
-
this.topics.set(topicID, (t = subscription(undefined,
|
|
64
|
+
this.topics.set(topicID, (t = subscription(undefined, __optsWithID("topic", {
|
|
62
65
|
closeOut: CloseMode.NEVER,
|
|
63
66
|
}))));
|
|
64
67
|
return t.subscribe(sub, opts);
|
|
65
68
|
}
|
|
66
69
|
transformTopic(topicID, xform, opts = {}) {
|
|
67
|
-
return this.subscribeTopic(topicID, { error: opts.error },
|
|
70
|
+
return this.subscribeTopic(topicID, { error: opts.error }, {
|
|
71
|
+
...opts,
|
|
72
|
+
xform,
|
|
73
|
+
});
|
|
68
74
|
}
|
|
69
75
|
unsubscribeTopic(topicID, sub) {
|
|
70
76
|
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.
|
|
@@ -27,9 +28,10 @@ import { optsWithID } from "../utils/idgen";
|
|
|
27
28
|
*/
|
|
28
29
|
export const resolve = (opts) => new Resolver(opts);
|
|
29
30
|
export class Resolver extends Subscription {
|
|
31
|
+
outstanding = 0;
|
|
32
|
+
fail;
|
|
30
33
|
constructor(opts = {}) {
|
|
31
|
-
super(undefined,
|
|
32
|
-
this.outstanding = 0;
|
|
34
|
+
super(undefined, __optsWithID("resolve"));
|
|
33
35
|
this.fail = opts.fail;
|
|
34
36
|
}
|
|
35
37
|
next(x) {
|
|
@@ -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
|
|
@@ -46,8 +46,9 @@ export const sidechainPartitionRAF = (src) => src
|
|
|
46
46
|
.subscribe(sidechainPartition(fromRAF()))
|
|
47
47
|
.transform(map(peek));
|
|
48
48
|
export class SidechainPartition extends ASidechain {
|
|
49
|
+
buf;
|
|
49
50
|
constructor(side, opts) {
|
|
50
|
-
opts =
|
|
51
|
+
opts = __optsWithID("sidepart", opts);
|
|
51
52
|
super(opts);
|
|
52
53
|
this.buf = [];
|
|
53
54
|
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.
|
|
@@ -31,8 +31,9 @@ import { ASidechain } from "./asidechain";
|
|
|
31
31
|
*/
|
|
32
32
|
export const sidechainToggle = (side, opts) => new SidechainToggle(side, opts);
|
|
33
33
|
export class SidechainToggle extends ASidechain {
|
|
34
|
+
isActive;
|
|
34
35
|
constructor(side, opts) {
|
|
35
|
-
opts =
|
|
36
|
+
opts = __optsWithID("sidetoggle", opts);
|
|
36
37
|
super(opts);
|
|
37
38
|
this.isActive = !!opts.initial;
|
|
38
39
|
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
|
}
|
|
@@ -22,11 +23,14 @@ export const reactive = (val, opts) => {
|
|
|
22
23
|
* @see {@link stream} & {@link reactive} for reference & examples.
|
|
23
24
|
*/
|
|
24
25
|
export class Stream extends Subscription {
|
|
26
|
+
src;
|
|
27
|
+
_cancel;
|
|
28
|
+
_inited;
|
|
25
29
|
constructor(src, opts) {
|
|
26
30
|
const [_src, _opts] = isFunction(src)
|
|
27
31
|
? [src, opts || {}]
|
|
28
32
|
: [undefined, src || {}];
|
|
29
|
-
super(_opts.error ? { error: _opts.error } : undefined,
|
|
33
|
+
super(_opts.error ? { error: _opts.error } : undefined, __optsWithID("stream", _opts));
|
|
30
34
|
this.src = _src;
|
|
31
35
|
this._inited = false;
|
|
32
36
|
}
|
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.
|
|
@@ -56,12 +62,25 @@ import { optsWithID } from "./utils/idgen";
|
|
|
56
62
|
*/
|
|
57
63
|
export const subscription = (sub, opts) => new Subscription(sub, opts);
|
|
58
64
|
export class Subscription {
|
|
65
|
+
wrapped;
|
|
66
|
+
id;
|
|
67
|
+
closeIn;
|
|
68
|
+
closeOut;
|
|
69
|
+
parent;
|
|
70
|
+
__owner;
|
|
71
|
+
xform;
|
|
72
|
+
cacheLast;
|
|
73
|
+
last = SEMAPHORE;
|
|
74
|
+
state = State.IDLE;
|
|
75
|
+
subs = [];
|
|
59
76
|
constructor(wrapped, opts) {
|
|
60
77
|
this.wrapped = wrapped;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
opts = __optsWithID(`sub`, {
|
|
79
|
+
closeIn: CloseMode.LAST,
|
|
80
|
+
closeOut: CloseMode.LAST,
|
|
81
|
+
cache: true,
|
|
82
|
+
...opts,
|
|
83
|
+
});
|
|
65
84
|
this.parent = opts.parent;
|
|
66
85
|
this.id = opts.id;
|
|
67
86
|
this.closeIn = opts.closeIn;
|
|
@@ -89,7 +108,7 @@ export class Subscription {
|
|
|
89
108
|
$sub = sub;
|
|
90
109
|
}
|
|
91
110
|
else {
|
|
92
|
-
$sub = new Subscription(sub,
|
|
111
|
+
$sub = new Subscription(sub, { ...opts, parent: this });
|
|
93
112
|
}
|
|
94
113
|
this.subs.push($sub);
|
|
95
114
|
this.setState(State.ACTIVE);
|
|
@@ -104,10 +123,13 @@ export class Subscription {
|
|
|
104
123
|
opts = args.pop();
|
|
105
124
|
sub = { error: opts.error };
|
|
106
125
|
}
|
|
107
|
-
return this.subscribe(sub,
|
|
108
|
-
?
|
|
126
|
+
return this.subscribe(sub, __optsWithID("xform", args.length > 0
|
|
127
|
+
? {
|
|
128
|
+
...opts,
|
|
109
129
|
// @ts-ignore
|
|
110
|
-
xform: comp(...args)
|
|
130
|
+
xform: comp(...args),
|
|
131
|
+
}
|
|
132
|
+
: opts));
|
|
111
133
|
}
|
|
112
134
|
/**
|
|
113
135
|
* 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
|
|
@@ -58,6 +62,24 @@ export const sync = (opts) => new StreamSync(opts);
|
|
|
58
62
|
* @see {@link sync} for reference & examples.
|
|
59
63
|
*/
|
|
60
64
|
export class StreamSync extends Subscription {
|
|
65
|
+
/**
|
|
66
|
+
* maps actual inputs to their virtual input subs
|
|
67
|
+
*/
|
|
68
|
+
sources;
|
|
69
|
+
/**
|
|
70
|
+
* maps real source IDs to their actual input
|
|
71
|
+
*/
|
|
72
|
+
idSources;
|
|
73
|
+
/**
|
|
74
|
+
* maps (potentially aliased) input IDs to their actual src.id
|
|
75
|
+
*/
|
|
76
|
+
realSourceIDs;
|
|
77
|
+
/**
|
|
78
|
+
* maps real src.id to (potentially aliased) input IDs
|
|
79
|
+
*/
|
|
80
|
+
invRealSourceIDs;
|
|
81
|
+
psync;
|
|
82
|
+
clean;
|
|
61
83
|
constructor(opts) {
|
|
62
84
|
const psync = partitionSync(new Set(), {
|
|
63
85
|
key: (x) => x[0],
|
|
@@ -67,9 +89,12 @@ export class StreamSync extends Subscription {
|
|
|
67
89
|
backPressure: opts.backPressure || 0,
|
|
68
90
|
});
|
|
69
91
|
const mapv = mapVals((x) => x[1]);
|
|
70
|
-
super(undefined,
|
|
92
|
+
super(undefined, __optsWithID("streamsync", {
|
|
93
|
+
...opts,
|
|
94
|
+
xform: opts.xform
|
|
71
95
|
? comp(psync, mapv, opts.xform)
|
|
72
|
-
: comp(psync, mapv)
|
|
96
|
+
: comp(psync, mapv),
|
|
97
|
+
}));
|
|
73
98
|
this.sources = new Map();
|
|
74
99
|
this.realSourceIDs = new Map();
|
|
75
100
|
this.invRealSourceIDs = new Map();
|
|
@@ -135,11 +160,7 @@ export class StreamSync extends Subscription {
|
|
|
135
160
|
return ok;
|
|
136
161
|
}
|
|
137
162
|
removeAllIDs(ids) {
|
|
138
|
-
|
|
139
|
-
for (let id of ids) {
|
|
140
|
-
ok = this.removeID(id) && ok;
|
|
141
|
-
}
|
|
142
|
-
return ok;
|
|
163
|
+
return __removeAllIDs(this, ids);
|
|
143
164
|
}
|
|
144
165
|
getSourceForID(id) {
|
|
145
166
|
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
|
|
@@ -21,8 +21,12 @@ export const timeout = (timeoutMs, opts) => new Timeout(timeoutMs, opts);
|
|
|
21
21
|
* @see {@link timeout} for reference & examples.
|
|
22
22
|
*/
|
|
23
23
|
class Timeout extends Subscription {
|
|
24
|
+
timeoutMs;
|
|
25
|
+
timeoutId;
|
|
26
|
+
errorObj;
|
|
27
|
+
resetTimeout;
|
|
24
28
|
constructor(timeoutMs, opts) {
|
|
25
|
-
opts =
|
|
29
|
+
opts = __optsWithID("timeout", opts);
|
|
26
30
|
super(undefined, opts);
|
|
27
31
|
this.timeoutMs = timeoutMs;
|
|
28
32
|
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
|
|
@@ -21,8 +22,14 @@ export const tunnel = (opts) => new Tunnel(opts);
|
|
|
21
22
|
* @see {@link tunnel} for reference & examples.
|
|
22
23
|
*/
|
|
23
24
|
export class Tunnel extends Subscription {
|
|
25
|
+
workers;
|
|
26
|
+
src;
|
|
27
|
+
transferables;
|
|
28
|
+
terminate;
|
|
29
|
+
interrupt;
|
|
30
|
+
index;
|
|
24
31
|
constructor(opts) {
|
|
25
|
-
super(undefined, { id: opts.id || `tunnel-${
|
|
32
|
+
super(undefined, { id: opts.id || `tunnel-${__nextID()}` });
|
|
26
33
|
this.src = opts.src;
|
|
27
34
|
this.workers = new Array(opts.maxWorkers || 1);
|
|
28
35
|
this.transferables = opts.transferables;
|
|
@@ -42,7 +49,7 @@ export class Tunnel extends Subscription {
|
|
|
42
49
|
worker = null;
|
|
43
50
|
}
|
|
44
51
|
if (!worker) {
|
|
45
|
-
this.workers[this.index++] = worker =
|
|
52
|
+
this.workers[this.index++] = worker = defWorker(this.src);
|
|
46
53
|
this.index %= this.workers.length;
|
|
47
54
|
worker.addEventListener("message", (e) => this.dispatch(e.data));
|
|
48
55
|
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;
|