@vielzeug/flux 1.0.7 → 2.0.0
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/README.md +22 -25
- package/dist/_dev.cjs +1 -1
- package/dist/_dev.cjs.map +1 -1
- package/dist/_dev.js +2 -8
- package/dist/_dev.js.map +1 -1
- package/dist/_iterator.cjs +1 -1
- package/dist/_iterator.cjs.map +1 -1
- package/dist/_iterator.d.ts +3 -1
- package/dist/_iterator.d.ts.map +1 -1
- package/dist/_iterator.js +57 -35
- package/dist/_iterator.js.map +1 -1
- package/dist/_link.cjs +2 -0
- package/dist/_link.cjs.map +1 -0
- package/dist/_link.d.ts +4 -0
- package/dist/_link.d.ts.map +1 -0
- package/dist/_link.js +8 -0
- package/dist/_link.js.map +1 -0
- package/dist/_numeric.cjs +1 -1
- package/dist/_numeric.cjs.map +1 -1
- package/dist/_numeric.d.ts +2 -1
- package/dist/_numeric.d.ts.map +1 -1
- package/dist/_numeric.js +3 -7
- package/dist/_numeric.js.map +1 -1
- package/dist/_pipe.cjs +1 -1
- package/dist/_pipe.cjs.map +1 -1
- package/dist/_pipe.d.ts +2 -1
- package/dist/_pipe.d.ts.map +1 -1
- package/dist/_pipe.js +3 -3
- package/dist/_pipe.js.map +1 -1
- package/dist/_safe.cjs +1 -1
- package/dist/_safe.cjs.map +1 -1
- package/dist/_safe.d.ts +1 -1
- package/dist/_safe.d.ts.map +1 -1
- package/dist/_safe.js +2 -2
- package/dist/_safe.js.map +1 -1
- package/dist/_scheduler.cjs +1 -1
- package/dist/_scheduler.cjs.map +1 -1
- package/dist/_scheduler.d.ts +5 -2
- package/dist/_scheduler.d.ts.map +1 -1
- package/dist/_scheduler.js +1 -1
- package/dist/_scheduler.js.map +1 -1
- package/dist/_subscription.cjs +2 -0
- package/dist/_subscription.cjs.map +1 -0
- package/dist/_subscription.d.ts +8 -0
- package/dist/_subscription.d.ts.map +1 -0
- package/dist/_subscription.js +80 -0
- package/dist/_subscription.js.map +1 -0
- package/dist/adapters/courier.cjs +1 -1
- package/dist/adapters/courier.cjs.map +1 -1
- package/dist/adapters/courier.d.ts +35 -21
- package/dist/adapters/courier.d.ts.map +1 -1
- package/dist/adapters/courier.js +25 -6
- package/dist/adapters/courier.js.map +1 -1
- package/dist/adapters/herald.cjs +1 -1
- package/dist/adapters/herald.cjs.map +1 -1
- package/dist/adapters/herald.d.ts +2 -16
- package/dist/adapters/herald.d.ts.map +1 -1
- package/dist/adapters/herald.js +12 -8
- package/dist/adapters/herald.js.map +1 -1
- package/dist/adapters/pulse.cjs +1 -1
- package/dist/adapters/pulse.cjs.map +1 -1
- package/dist/adapters/pulse.d.ts +3 -20
- package/dist/adapters/pulse.d.ts.map +1 -1
- package/dist/adapters/pulse.js +2 -6
- package/dist/adapters/pulse.js.map +1 -1
- package/dist/adapters/ripple.cjs +1 -1
- package/dist/adapters/ripple.cjs.map +1 -1
- package/dist/adapters/ripple.d.ts +3 -39
- package/dist/adapters/ripple.d.ts.map +1 -1
- package/dist/adapters/ripple.js +22 -29
- package/dist/adapters/ripple.js.map +1 -1
- package/dist/async.cjs +2 -0
- package/dist/async.cjs.map +1 -0
- package/dist/async.d.ts +4 -0
- package/dist/async.d.ts.map +1 -0
- package/dist/async.js +11 -0
- package/dist/async.js.map +1 -0
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +3 -16
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +12 -81
- package/dist/core.js.map +1 -1
- package/dist/courier.cjs +1 -0
- package/dist/courier.d.ts +2 -0
- package/dist/courier.d.ts.map +1 -0
- package/dist/courier.js +2 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/flux.cjs +1 -1
- package/dist/flux.cjs.map +1 -1
- package/dist/flux.iife.js +1 -1
- package/dist/flux.iife.js.map +1 -1
- package/dist/flux.js +1 -1
- package/dist/flux.js.map +1 -1
- package/dist/herald.cjs +1 -0
- package/dist/herald.d.ts +2 -0
- package/dist/herald.d.ts.map +1 -0
- package/dist/herald.js +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +13 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -14
- package/dist/operators/combination.cjs +1 -1
- package/dist/operators/combination.cjs.map +1 -1
- package/dist/operators/combination.d.ts +9 -64
- package/dist/operators/combination.d.ts.map +1 -1
- package/dist/operators/combination.js +46 -160
- package/dist/operators/combination.js.map +1 -1
- package/dist/operators/creation.cjs +1 -1
- package/dist/operators/creation.cjs.map +1 -1
- package/dist/operators/creation.d.ts +13 -46
- package/dist/operators/creation.d.ts.map +1 -1
- package/dist/operators/creation.js +61 -65
- package/dist/operators/creation.js.map +1 -1
- package/dist/operators/filtering.cjs +1 -1
- package/dist/operators/filtering.cjs.map +1 -1
- package/dist/operators/filtering.d.ts +10 -60
- package/dist/operators/filtering.d.ts.map +1 -1
- package/dist/operators/filtering.js +62 -109
- package/dist/operators/filtering.js.map +1 -1
- package/dist/operators/transformation.cjs +1 -1
- package/dist/operators/transformation.cjs.map +1 -1
- package/dist/operators/transformation.d.ts +9 -62
- package/dist/operators/transformation.d.ts.map +1 -1
- package/dist/operators/transformation.js +91 -142
- package/dist/operators/transformation.js.map +1 -1
- package/dist/operators/utility.cjs +1 -1
- package/dist/operators/utility.cjs.map +1 -1
- package/dist/operators/utility.d.ts +16 -97
- package/dist/operators/utility.d.ts.map +1 -1
- package/dist/operators/utility.js +75 -191
- package/dist/operators/utility.js.map +1 -1
- package/dist/pipe.cjs +2 -0
- package/dist/pipe.cjs.map +1 -0
- package/dist/pipe.d.ts +15 -0
- package/dist/pipe.d.ts.map +1 -0
- package/dist/pipe.js +9 -0
- package/dist/pipe.js.map +1 -0
- package/dist/pulse.cjs +1 -0
- package/dist/pulse.d.ts +2 -0
- package/dist/pulse.d.ts.map +1 -0
- package/dist/pulse.js +2 -0
- package/dist/ripple.cjs +1 -0
- package/dist/ripple.d.ts +3 -0
- package/dist/ripple.d.ts.map +1 -0
- package/dist/ripple.js +2 -0
- package/dist/subject.cjs +1 -1
- package/dist/subject.cjs.map +1 -1
- package/dist/subject.d.ts +14 -65
- package/dist/subject.d.ts.map +1 -1
- package/dist/subject.js +31 -166
- package/dist/subject.js.map +1 -1
- package/dist/subjects.cjs +1 -0
- package/dist/subjects.d.ts +3 -0
- package/dist/subjects.d.ts.map +1 -0
- package/dist/subjects.js +2 -0
- package/dist/types.d.ts +32 -79
- package/dist/types.d.ts.map +1 -1
- package/package.json +54 -15
|
@@ -1,65 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare function
|
|
9
|
-
|
|
10
|
-
* Subscribe to each source sequentially — the next source only starts after
|
|
11
|
-
* the previous one completes.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* concat(of(1, 2), of(3, 4)); // emits 1, 2, 3, 4
|
|
15
|
-
*/
|
|
16
|
-
export declare function concat<T>(...sources: Flux<T>[]): Flux<T>;
|
|
17
|
-
/**
|
|
18
|
-
* Combine the latest values from all sources into a tuple whenever any source emits.
|
|
19
|
-
* Waits until all sources have emitted at least once before emitting.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* combineLatest(a$, b$).subscribe(([a, b]) => console.log(a, b));
|
|
23
|
-
*/
|
|
24
|
-
export declare function combineLatest<T extends Flux<unknown>[]>(...sources: T): Flux<{
|
|
25
|
-
[K in keyof T]: T[K] extends Flux<infer V> ? V : never;
|
|
26
|
-
}>;
|
|
27
|
-
/**
|
|
28
|
-
* Emit from `source` combined with the latest values from `others` as a tuple.
|
|
29
|
-
* Does not wait for others to emit — emits whenever `source` emits (if others have a value).
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* a$.pipe(withLatestFrom(b$)).subscribe(([a, b]) => console.log(a, b));
|
|
33
|
-
*/
|
|
34
|
-
export declare function withLatestFrom<T, U extends Flux<unknown>[]>(...others: U): Operator<T, [T, ...{
|
|
35
|
-
[K in keyof U]: U[K] extends Flux<infer V> ? V : never;
|
|
36
|
-
}]>;
|
|
37
|
-
/**
|
|
38
|
-
* Subscribe to all sources; emit the first value from whichever source emits first,
|
|
39
|
-
* then unsubscribe from all others.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* race(timedOut$, userClicked$).subscribe(console.log);
|
|
43
|
-
*/
|
|
44
|
-
export declare function race<T>(...sources: Flux<T>[]): Flux<T>;
|
|
45
|
-
/**
|
|
46
|
-
* Pair emissions by index across all sources. Emits a tuple when all sources
|
|
47
|
-
* have each emitted their N-th value. Completes when any source completes.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* zip(of(1, 2), of('a', 'b')); // emits [1,'a'], [2,'b']
|
|
51
|
-
*/
|
|
52
|
-
export declare function zip<T extends Flux<unknown>[]>(...sources: T): Flux<{
|
|
53
|
-
[K in keyof T]: T[K] extends Flux<infer V> ? V : never;
|
|
54
|
-
}>;
|
|
55
|
-
/**
|
|
56
|
-
* Wait for all sources to complete, then emit a single tuple of last values.
|
|
57
|
-
* Similar to `Promise.all`.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* forkJoin(fetch1$, fetch2$).subscribe(([r1, r2]) => console.log(r1, r2));
|
|
61
|
-
*/
|
|
62
|
-
export declare function forkJoin<T extends Flux<unknown>[]>(...sources: T): Flux<{
|
|
63
|
-
[K in keyof T]: T[K] extends Flux<infer V> ? V : never;
|
|
64
|
-
}>;
|
|
1
|
+
import type { Stream } from '../types';
|
|
2
|
+
type StreamValue<T> = T extends Stream<infer Value> ? Value : never;
|
|
3
|
+
type StreamValues<T extends readonly Stream<unknown>[]> = {
|
|
4
|
+
[Key in keyof T]: StreamValue<T[Key]>;
|
|
5
|
+
};
|
|
6
|
+
export declare function merge<T>(...sources: Stream<T>[]): Stream<T>;
|
|
7
|
+
export declare function concat<T>(...sources: Stream<T>[]): Stream<T>;
|
|
8
|
+
export declare function combineLatest<T extends readonly Stream<unknown>[]>(...sources: T): Stream<StreamValues<T>>;
|
|
9
|
+
export {};
|
|
65
10
|
//# sourceMappingURL=combination.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combination.d.ts","sourceRoot":"","sources":["../../src/operators/combination.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"combination.d.ts","sourceRoot":"","sources":["../../src/operators/combination.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAC;AAKrD,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,KAAK,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;AACpE,KAAK,YAAY,CAAC,CAAC,SAAS,SAAS,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI;KAAG,GAAG,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAAE,CAAC;AAEpG,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAiC3D;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAiC5D;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,SAAS,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CA8C1G"}
|
|
@@ -1,187 +1,73 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { stream as e } from "../core.js";
|
|
2
|
+
import { link as t } from "../_link.js";
|
|
2
3
|
//#region src/operators/combination.ts
|
|
3
|
-
function
|
|
4
|
-
return e((e) => {
|
|
5
|
-
if (
|
|
6
|
-
e.complete
|
|
4
|
+
function n(...n) {
|
|
5
|
+
return e((e, r) => {
|
|
6
|
+
if (n.length === 0) {
|
|
7
|
+
e.complete();
|
|
7
8
|
return;
|
|
8
9
|
}
|
|
9
|
-
let
|
|
10
|
-
for (let
|
|
11
|
-
|
|
12
|
-
n++, n === t.length && e.complete?.();
|
|
13
|
-
},
|
|
14
|
-
error: e.error,
|
|
15
|
-
next: e.next
|
|
16
|
-
}));
|
|
17
|
-
return () => {
|
|
18
|
-
for (let e of r) e();
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
function n(...t) {
|
|
23
|
-
return e((e) => {
|
|
24
|
-
let n = 0, r;
|
|
25
|
-
function i() {
|
|
26
|
-
if (n >= t.length) {
|
|
27
|
-
e.complete?.();
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
r = t[n++].subscribe({
|
|
10
|
+
let i = 0, a = [];
|
|
11
|
+
for (let o of n) {
|
|
12
|
+
let s = t(o, {
|
|
31
13
|
complete() {
|
|
32
|
-
|
|
14
|
+
i++, i === n.length && e.complete();
|
|
33
15
|
},
|
|
34
16
|
error: e.error,
|
|
35
17
|
next: e.next
|
|
36
|
-
});
|
|
18
|
+
}, r);
|
|
19
|
+
if (a.push(s), r.aborted) break;
|
|
37
20
|
}
|
|
38
|
-
return
|
|
21
|
+
return () => a.forEach((e) => e.unsubscribe());
|
|
39
22
|
});
|
|
40
23
|
}
|
|
41
|
-
function r(...
|
|
42
|
-
return e((e) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
a.push(o.subscribe({
|
|
50
|
-
complete() {
|
|
51
|
-
i++, i === t.length && e.complete?.();
|
|
52
|
-
},
|
|
53
|
-
error: e.error,
|
|
54
|
-
next(t) {
|
|
55
|
-
n[s] = t, r[s] = !0, r.every(Boolean) && e.next([...n]);
|
|
56
|
-
}
|
|
57
|
-
}));
|
|
58
|
-
}), () => {
|
|
59
|
-
for (let e of a) e();
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
function i(...t) {
|
|
64
|
-
return (n) => e((e) => {
|
|
65
|
-
let r = Array(t.length), i = Array(t.length).fill(!1), a = [];
|
|
66
|
-
t.forEach((t, n) => {
|
|
67
|
-
a.push(t.subscribe({
|
|
68
|
-
error: e.error,
|
|
69
|
-
next(e) {
|
|
70
|
-
r[n] = e, i[n] = !0;
|
|
71
|
-
}
|
|
72
|
-
}));
|
|
73
|
-
});
|
|
74
|
-
let o = n.subscribe({
|
|
75
|
-
complete: e.complete,
|
|
76
|
-
error: e.error,
|
|
77
|
-
next(t) {
|
|
78
|
-
i.every(Boolean) && e.next([t, ...r]);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
return () => {
|
|
82
|
-
o();
|
|
83
|
-
for (let e of a) e();
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
function a(...t) {
|
|
88
|
-
return e((e) => {
|
|
89
|
-
if (t.length === 0) {
|
|
90
|
-
e.complete?.();
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
let n = !1, r = [];
|
|
94
|
-
for (let i of t) r.push(i.subscribe({
|
|
95
|
-
complete() {
|
|
96
|
-
if (!n) {
|
|
97
|
-
n = !0, e.complete?.();
|
|
98
|
-
for (let e of r) e();
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
error(t) {
|
|
102
|
-
if (!n) {
|
|
103
|
-
n = !0, e.error?.(t);
|
|
104
|
-
for (let e of r) e();
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
next(t) {
|
|
108
|
-
if (!n) {
|
|
109
|
-
n = !0, e.next(t);
|
|
110
|
-
for (let e of r) e();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}));
|
|
114
|
-
return () => {
|
|
115
|
-
for (let e of r) e();
|
|
116
|
-
};
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
function o(...t) {
|
|
120
|
-
return e((e) => {
|
|
121
|
-
if (t.length === 0) {
|
|
122
|
-
e.complete?.();
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
let n = t.map(() => []), r = Array(t.length).fill(!1), i = [], a = !1;
|
|
126
|
-
function o() {
|
|
127
|
-
if (!a) {
|
|
128
|
-
for (; n.every((e) => e.length > 0);) {
|
|
129
|
-
let t = n.map((e) => e.shift());
|
|
130
|
-
e.next(t);
|
|
131
|
-
}
|
|
132
|
-
if (n.some((e, t) => r[t] && e.length === 0)) {
|
|
133
|
-
a = !0, e.complete?.();
|
|
134
|
-
for (let e of i) e();
|
|
135
|
-
}
|
|
24
|
+
function r(...n) {
|
|
25
|
+
return e((e, r) => {
|
|
26
|
+
let i = 0, a, o = () => {
|
|
27
|
+
if (r.aborted) return;
|
|
28
|
+
let s = n[i++];
|
|
29
|
+
if (!s) {
|
|
30
|
+
e.complete();
|
|
31
|
+
return;
|
|
136
32
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
error(t) {
|
|
144
|
-
a = !0, e.error?.(t);
|
|
145
|
-
for (let e of i) e();
|
|
146
|
-
},
|
|
147
|
-
next(e) {
|
|
148
|
-
n[s].push(e), o();
|
|
149
|
-
}
|
|
150
|
-
}));
|
|
151
|
-
}), () => {
|
|
152
|
-
for (let e of i) e();
|
|
33
|
+
let c = t(s, {
|
|
34
|
+
complete: o,
|
|
35
|
+
error: e.error,
|
|
36
|
+
next: e.next
|
|
37
|
+
}, r);
|
|
38
|
+
a = c.closed ? void 0 : c;
|
|
153
39
|
};
|
|
40
|
+
return o(), () => a?.unsubscribe();
|
|
154
41
|
});
|
|
155
42
|
}
|
|
156
|
-
function
|
|
157
|
-
return e((e) => {
|
|
158
|
-
if (
|
|
159
|
-
e.complete
|
|
43
|
+
function i(...n) {
|
|
44
|
+
return e((e, r) => {
|
|
45
|
+
if (n.length === 0) {
|
|
46
|
+
e.complete();
|
|
160
47
|
return;
|
|
161
48
|
}
|
|
162
|
-
let
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
49
|
+
let i = Array(n.length), a = Array(n.length).fill(!1), o = [], s = 0;
|
|
50
|
+
for (let [c, l] of n.entries()) {
|
|
51
|
+
if (r.aborted) break;
|
|
52
|
+
let u = t(l, {
|
|
166
53
|
complete() {
|
|
167
|
-
if (
|
|
168
|
-
e.complete
|
|
169
|
-
for (let e of i) e();
|
|
54
|
+
if (!a[c]) {
|
|
55
|
+
e.complete();
|
|
170
56
|
return;
|
|
171
57
|
}
|
|
172
|
-
|
|
58
|
+
s++, s === n.length && e.complete();
|
|
173
59
|
},
|
|
174
60
|
error: e.error,
|
|
175
|
-
next(
|
|
176
|
-
|
|
61
|
+
next(t) {
|
|
62
|
+
i[c] = t, a[c] = !0, a.every(Boolean) && e.next([...i]);
|
|
177
63
|
}
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
64
|
+
}, r);
|
|
65
|
+
o.push(u);
|
|
66
|
+
}
|
|
67
|
+
return () => o.forEach((e) => e.unsubscribe());
|
|
182
68
|
});
|
|
183
69
|
}
|
|
184
70
|
//#endregion
|
|
185
|
-
export {
|
|
71
|
+
export { i as combineLatest, r as concat, n as merge };
|
|
186
72
|
|
|
187
73
|
//# sourceMappingURL=combination.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combination.js","names":[],"sources":["../../src/operators/combination.ts"],"sourcesContent":["import type { Flux, Operator, Unsubscribe } from '../types';\n\nimport { flux } from '../core';\n\n/**\n * Merge multiple `Flux` streams into one, emitting values as they arrive.\n *\n * @example\n * merge(clicks$, keydowns$).subscribe(console.log);\n */\nexport function merge<T>(...sources: Flux<T>[]): Flux<T> {\n return flux<T>((observer) => {\n if (sources.length === 0) {\n observer.complete?.();\n\n return;\n }\n\n let completedCount = 0;\n const unsubs: Unsubscribe[] = [];\n\n for (const source of sources) {\n unsubs.push(\n source.subscribe({\n complete() {\n completedCount++;\n\n if (completedCount === sources.length) observer.complete?.();\n },\n error: observer.error,\n next: observer.next,\n }),\n );\n }\n\n return () => {\n for (const u of unsubs) u();\n };\n });\n}\n\n/**\n * Subscribe to each source sequentially — the next source only starts after\n * the previous one completes.\n *\n * @example\n * concat(of(1, 2), of(3, 4)); // emits 1, 2, 3, 4\n */\nexport function concat<T>(...sources: Flux<T>[]): Flux<T> {\n return flux<T>((observer) => {\n let index = 0;\n let currentUnsub: Unsubscribe | undefined;\n\n function subscribeNext(): void {\n if (index >= sources.length) {\n observer.complete?.();\n\n return;\n }\n\n currentUnsub = sources[index++]!.subscribe({\n complete() {\n currentUnsub = undefined;\n subscribeNext();\n },\n error: observer.error,\n next: observer.next,\n });\n }\n\n subscribeNext();\n\n return () => currentUnsub?.();\n });\n}\n\n/**\n * Combine the latest values from all sources into a tuple whenever any source emits.\n * Waits until all sources have emitted at least once before emitting.\n *\n * @example\n * combineLatest(a$, b$).subscribe(([a, b]) => console.log(a, b));\n */\nexport function combineLatest<T extends Flux<unknown>[]>(\n ...sources: T\n): Flux<{ [K in keyof T]: T[K] extends Flux<infer V> ? V : never }> {\n type Out = { [K in keyof T]: T[K] extends Flux<infer V> ? V : never };\n\n return flux<Out>((observer) => {\n if (sources.length === 0) {\n observer.complete?.();\n\n return;\n }\n\n const latests = new Array(sources.length) as Out;\n const hasValue = new Array<boolean>(sources.length).fill(false);\n let completedCount = 0;\n const unsubs: Unsubscribe[] = [];\n\n sources.forEach((source, i) => {\n unsubs.push(\n source.subscribe({\n complete() {\n completedCount++;\n\n if (completedCount === sources.length) observer.complete?.();\n },\n error: observer.error,\n next(v) {\n latests[i] = v as Out[typeof i];\n hasValue[i] = true;\n\n if (hasValue.every(Boolean)) observer.next([...latests] as Out);\n },\n }),\n );\n });\n\n return () => {\n for (const u of unsubs) u();\n };\n });\n}\n\n/**\n * Emit from `source` combined with the latest values from `others` as a tuple.\n * Does not wait for others to emit — emits whenever `source` emits (if others have a value).\n *\n * @example\n * a$.pipe(withLatestFrom(b$)).subscribe(([a, b]) => console.log(a, b));\n */\nexport function withLatestFrom<T, U extends Flux<unknown>[]>(\n ...others: U\n): Operator<T, [T, ...{ [K in keyof U]: U[K] extends Flux<infer V> ? V : never }]> {\n type Rest = { [K in keyof U]: U[K] extends Flux<infer V> ? V : never };\n type Out = [T, ...Rest];\n\n return (source) =>\n flux<Out>((observer) => {\n const latests = new Array(others.length) as Rest;\n const hasValue = new Array<boolean>(others.length).fill(false);\n const otherUnsubs: Unsubscribe[] = [];\n\n others.forEach((other, i) => {\n otherUnsubs.push(\n other.subscribe({\n error: observer.error,\n next(v) {\n latests[i] = v as Rest[typeof i];\n hasValue[i] = true;\n },\n }),\n );\n });\n\n const sourceUnsub = source.subscribe({\n complete: observer.complete,\n error: observer.error,\n next(v) {\n if (hasValue.every(Boolean)) {\n observer.next([v, ...latests] as Out);\n }\n },\n });\n\n return () => {\n sourceUnsub();\n\n for (const u of otherUnsubs) u();\n };\n });\n}\n\n/**\n * Subscribe to all sources; emit the first value from whichever source emits first,\n * then unsubscribe from all others.\n *\n * @example\n * race(timedOut$, userClicked$).subscribe(console.log);\n */\nexport function race<T>(...sources: Flux<T>[]): Flux<T> {\n return flux<T>((observer) => {\n if (sources.length === 0) {\n observer.complete?.();\n\n return;\n }\n\n let winner = false;\n const unsubs: Unsubscribe[] = [];\n\n for (const source of sources) {\n unsubs.push(\n source.subscribe({\n complete() {\n if (!winner) {\n winner = true;\n observer.complete?.();\n\n for (const u of unsubs) u();\n }\n },\n error(err) {\n if (!winner) {\n winner = true;\n observer.error?.(err);\n\n for (const u of unsubs) u();\n }\n },\n next(v) {\n if (!winner) {\n winner = true;\n observer.next(v);\n\n for (const u of unsubs) u();\n }\n },\n }),\n );\n }\n\n return () => {\n for (const u of unsubs) u();\n };\n });\n}\n\n/**\n * Pair emissions by index across all sources. Emits a tuple when all sources\n * have each emitted their N-th value. Completes when any source completes.\n *\n * @example\n * zip(of(1, 2), of('a', 'b')); // emits [1,'a'], [2,'b']\n */\nexport function zip<T extends Flux<unknown>[]>(\n ...sources: T\n): Flux<{ [K in keyof T]: T[K] extends Flux<infer V> ? V : never }> {\n type Out = { [K in keyof T]: T[K] extends Flux<infer V> ? V : never };\n\n return flux<Out>((observer) => {\n if (sources.length === 0) {\n observer.complete?.();\n\n return;\n }\n\n const buffers = sources.map(() => [] as unknown[]);\n const completed = new Array<boolean>(sources.length).fill(false);\n const unsubs: Unsubscribe[] = [];\n let done = false;\n\n function checkAndEmit(): void {\n if (done) return;\n\n while (buffers.every((b) => b.length > 0)) {\n const tuple = buffers.map((b) => b.shift()) as Out;\n\n observer.next(tuple);\n }\n\n if (buffers.some((b, i) => completed[i] && b.length === 0)) {\n done = true;\n observer.complete?.();\n\n for (const u of unsubs) u();\n }\n }\n\n sources.forEach((source, i) => {\n unsubs.push(\n source.subscribe({\n complete() {\n completed[i] = true;\n checkAndEmit();\n },\n error(err) {\n done = true;\n observer.error?.(err);\n\n for (const u of unsubs) u();\n },\n next(v) {\n buffers[i]!.push(v);\n checkAndEmit();\n },\n }),\n );\n });\n\n return () => {\n for (const u of unsubs) u();\n };\n });\n}\n\n/**\n * Wait for all sources to complete, then emit a single tuple of last values.\n * Similar to `Promise.all`.\n *\n * @example\n * forkJoin(fetch1$, fetch2$).subscribe(([r1, r2]) => console.log(r1, r2));\n */\nexport function forkJoin<T extends Flux<unknown>[]>(\n ...sources: T\n): Flux<{ [K in keyof T]: T[K] extends Flux<infer V> ? V : never }> {\n type Out = { [K in keyof T]: T[K] extends Flux<infer V> ? V : never };\n\n return flux<Out>((observer) => {\n if (sources.length === 0) {\n observer.complete?.();\n\n return;\n }\n\n const results = new Array(sources.length) as Out;\n const completed = new Array<boolean>(sources.length).fill(false);\n const unsubs: Unsubscribe[] = [];\n\n sources.forEach((source, i) => {\n let lastValue: unknown;\n let hasValue = false;\n\n unsubs.push(\n source.subscribe({\n complete() {\n completed[i] = true;\n\n if (!hasValue) {\n observer.complete?.();\n\n for (const u of unsubs) u();\n\n return;\n }\n\n results[i] = lastValue as Out[typeof i];\n\n if (completed.every(Boolean)) {\n observer.next([...results] as Out);\n observer.complete?.();\n }\n },\n error: observer.error,\n next(v) {\n lastValue = v;\n hasValue = true;\n },\n }),\n );\n });\n\n return () => {\n for (const u of unsubs) u();\n };\n });\n}\n"],"mappings":";;AAUA,SAAgB,EAAS,GAAG,GAA6B;CACvD,OAAO,GAAS,MAAa;EAC3B,IAAI,EAAQ,WAAW,GAAG;GACxB,EAAS,WAAW;GAEpB;EACF;EAEA,IAAI,IAAiB,GACf,IAAwB,CAAC;EAE/B,KAAK,IAAM,KAAU,GACnB,EAAO,KACL,EAAO,UAAU;GACf,WAAW;IAGT,AAFA,KAEI,MAAmB,EAAQ,UAAQ,EAAS,WAAW;GAC7D;GACA,OAAO,EAAS;GAChB,MAAM,EAAS;EACjB,CAAC,CACH;EAGF,aAAa;GACX,KAAK,IAAM,KAAK,GAAQ,EAAE;EAC5B;CACF,CAAC;AACH;AASA,SAAgB,EAAU,GAAG,GAA6B;CACxD,OAAO,GAAS,MAAa;EAC3B,IAAI,IAAQ,GACR;EAEJ,SAAS,IAAsB;GAC7B,IAAI,KAAS,EAAQ,QAAQ;IAC3B,EAAS,WAAW;IAEpB;GACF;GAEA,IAAe,EAAQ,IAAQ,CAAE,UAAU;IACzC,WAAW;KAET,AADA,IAAe,KAAA,GACf,EAAc;IAChB;IACA,OAAO,EAAS;IAChB,MAAM,EAAS;GACjB,CAAC;EACH;EAIA,OAFA,EAAc,SAED,IAAe;CAC9B,CAAC;AACH;AASA,SAAgB,EACd,GAAG,GAC+D;CAGlE,OAAO,GAAW,MAAa;EAC7B,IAAI,EAAQ,WAAW,GAAG;GACxB,EAAS,WAAW;GAEpB;EACF;EAEA,IAAM,IAAc,MAAM,EAAQ,M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AAM,GAAK;KAET,AADA,IAAO,IACP,EAAS,QAAQ,CAAG;KAEpB,KAAK,IAAM,KAAK,GAAQ,EAAE;IAC5B;IACA,KAAK,GAAG;KAEN,AADA,EAAQ,EAAE,CAAE,KAAK,CAAC,GAClB,EAAa;IACf;GACF,CAAC,CACH;EACF,CAAC,SAEY;GACX,KAAK,IAAM,KAAK,GAAQ,EAAE;EAC5B;CACF,CAAC;AACH;AASA,SAAgB,EACd,GAAG,GAC+D;CAGlE,OAAO,GAAW,MAAa;EAC7B,IAAI,EAAQ,WAAW,GAAG;GACxB,EAAS,WAAW;GAEpB;EACF;EAEA,IAAM,IAAc,MAAM,EAAQ,MAAM,GAClC,IAAgB,MAAe,EAAQ,MAAM,CAAC,CAAC,KAAK,EAAK,GACzD,IAAwB,CAAC;EAmC/B,OAjCA,EAAQ,SAAS,GAAQ,MAAM;GAC7B,IAAI,GACA,IAAW;GAEf,EAAO,KACL,EAAO,UAAU;IACf,WAAW;KAGT,IAFA,EAAU,KAAK,IAEX,CAAC,GAAU;MACb,EAAS,WAAW;MAEpB,KAAK,IAAM,KAAK,GAAQ,EAAE;MAE1B;KACF;KAIA,AAFA,EAAQ,KAAK,GAET,EAAU,MAAM,OAAO,MACzB,EAAS,KAAK,CAAC,GAAG,CAAO,CAAQ,GACjC,EAAS,WAAW;IAExB;IACA,OAAO,EAAS;IAChB,KAAK,GAAG;KAEN,AADA,IAAY,GACZ,IAAW;IACb;GACF,CAAC,CACH;EACF,CAAC,SAEY;GACX,KAAK,IAAM,KAAK,GAAQ,EAAE;EAC5B;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"combination.js","names":[],"sources":["../../src/operators/combination.ts"],"sourcesContent":["import type { Stream, Subscription } from '../types';\n\nimport { link } from '../_link';\nimport { stream } from '../core';\n\ntype StreamValue<T> = T extends Stream<infer Value> ? Value : never;\ntype StreamValues<T extends readonly Stream<unknown>[]> = { [Key in keyof T]: StreamValue<T[Key]> };\n\nexport function merge<T>(...sources: Stream<T>[]): Stream<T> {\n return stream((sink, signal) => {\n if (sources.length === 0) {\n sink.complete();\n\n return;\n }\n\n let completed = 0;\n const subscriptions: Subscription[] = [];\n\n for (const source of sources) {\n const subscription = link(\n source,\n {\n complete() {\n completed++;\n\n if (completed === sources.length) sink.complete();\n },\n error: sink.error,\n next: sink.next,\n },\n signal,\n );\n\n subscriptions.push(subscription);\n\n if (signal.aborted) break;\n }\n\n return () => subscriptions.forEach((subscription) => subscription.unsubscribe());\n });\n}\n\nexport function concat<T>(...sources: Stream<T>[]): Stream<T> {\n return stream((sink, signal) => {\n let index = 0;\n let current: Subscription | undefined;\n\n const subscribeNext = (): void => {\n if (signal.aborted) return;\n\n const source = sources[index++];\n\n if (!source) {\n sink.complete();\n\n return;\n }\n\n const subscription = link(\n source,\n {\n complete: subscribeNext,\n error: sink.error,\n next: sink.next,\n },\n signal,\n );\n\n current = subscription.closed ? undefined : subscription;\n };\n\n subscribeNext();\n\n return () => current?.unsubscribe();\n });\n}\n\nexport function combineLatest<T extends readonly Stream<unknown>[]>(...sources: T): Stream<StreamValues<T>> {\n return stream((sink, signal) => {\n if (sources.length === 0) {\n sink.complete();\n\n return;\n }\n\n const values = new Array<unknown>(sources.length);\n const ready = new Array<boolean>(sources.length).fill(false);\n const subscriptions: Subscription[] = [];\n let completed = 0;\n\n for (const [index, source] of sources.entries()) {\n if (signal.aborted) break;\n\n const subscription = link(\n source,\n {\n complete() {\n if (!ready[index]) {\n sink.complete();\n\n return;\n }\n\n completed++;\n\n if (completed === sources.length) sink.complete();\n },\n error: sink.error,\n next(value) {\n values[index] = value;\n ready[index] = true;\n\n if (ready.every(Boolean)) sink.next([...values] as StreamValues<T>);\n },\n },\n signal,\n );\n\n subscriptions.push(subscription);\n }\n\n return () => subscriptions.forEach((subscription) => subscription.unsubscribe());\n });\n}\n"],"mappings":";;;AAQA,SAAgB,EAAS,GAAG,GAAiC;CAC3D,OAAO,GAAQ,GAAM,MAAW;EAC9B,IAAI,EAAQ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AQ,UAAQ,EAAK,SAAS;IAClD;IACA,OAAO,EAAK;IACZ,KAAK,GAAO;KAIV,AAHA,EAAO,KAAS,GAChB,EAAM,KAAS,IAEX,EAAM,MAAM,OAAO,KAAG,EAAK,KAAK,CAAC,GAAG,CAAM,CAAoB;IACpE;GACF,GACA,CACF;GAEA,EAAc,KAAK,CAAY;EACjC;EAEA,aAAa,EAAc,SAAS,MAAiB,EAAa,YAAY,CAAC;CACjF,CAAC;AACH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../core.cjs"),t=require("../_scheduler.cjs");function n(
|
|
1
|
+
const e=require("../core.cjs"),t=require("../_scheduler.cjs");function n(e,t){if(!Number.isFinite(e)||e<0)throw RangeError(`${t} must be a finite number greater than or equal to zero`)}function r(...t){return e.stream(e=>{for(let n of t)e.next(n);e.complete()})}function i(t){return Symbol.asyncIterator in Object(t)?e.stream((e,n)=>{let r=t[Symbol.asyncIterator]();return(async()=>{try{for(;!n.aborted;){let t=await r.next();if(t.done){e.complete();return}e.next(t.value)}}catch(t){n.aborted||e.error(t)}})(),()=>{r.return?.()}}):typeof t.then==`function`?e.stream((e,n)=>{t.then(t=>{n.aborted||(e.next(t),e.complete())},t=>{n.aborted||e.error(t)})}):e.stream((e,n)=>{let r=t[Symbol.iterator]();try{for(;!n.aborted;){let t=r.next();if(t.done){e.complete();return}e.next(t.value)}}catch(t){e.error(t)}return()=>{r.return?.()}})}function a(t,n){return e.stream(e=>{let r=t=>e.next(t);return t.addEventListener(n,r),()=>t.removeEventListener(n,r)})}function o(r){return n(r.every,`Interval duration`),e.stream(e=>{let n=0;return t.defaultScheduler.repeat(()=>e.next(n++),r.every)})}function s(r){return n(r.delay,`Timer delay`),r.interval!==void 0&&n(r.interval,`Timer interval`),e.stream(e=>{let n=0,i,a=t.defaultScheduler.delay(()=>{if(e.next(n++),r.interval===void 0){e.complete();return}i=t.defaultScheduler.repeat(()=>e.next(n++),r.interval)},r.delay);return()=>{a(),i?.()}})}exports.from=i,exports.fromEvent=a,exports.interval=o,exports.of=r,exports.timer=s;
|
|
2
2
|
//# sourceMappingURL=creation.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"creation.cjs","names":[],"sources":["../../src/operators/creation.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"creation.cjs","names":[],"sources":["../../src/operators/creation.ts"],"sourcesContent":["import type { Stream } from '../types';\n\nimport { defaultScheduler } from '../_scheduler';\nimport { stream } from '../core';\n\nexport type IntervalOptions = {\n every: number;\n};\n\nexport type TimerOptions = {\n delay: number;\n interval?: number;\n};\n\nfunction assertDuration(milliseconds: number, name: string): void {\n if (!Number.isFinite(milliseconds) || milliseconds < 0) {\n throw new RangeError(`${name} must be a finite number greater than or equal to zero`);\n }\n}\n\nexport function of<T>(...values: T[]): Stream<T> {\n return stream((sink) => {\n for (const value of values) sink.next(value);\n sink.complete();\n });\n}\n\nexport function from<T>(source: AsyncIterable<T> | Iterable<T> | Promise<T>): Stream<T> {\n if (Symbol.asyncIterator in Object(source)) {\n return stream((sink, signal) => {\n const iterator = (source as AsyncIterable<T>)[Symbol.asyncIterator]();\n\n void (async () => {\n try {\n while (!signal.aborted) {\n const result = await iterator.next();\n\n if (result.done) {\n sink.complete();\n\n return;\n }\n\n sink.next(result.value);\n }\n } catch (reason) {\n if (!signal.aborted) sink.error(reason);\n }\n })();\n\n return () => {\n void iterator.return?.();\n };\n });\n }\n\n if (typeof (source as Promise<T>).then === 'function') {\n return stream((sink, signal) => {\n void (source as Promise<T>).then(\n (value) => {\n if (!signal.aborted) {\n sink.next(value);\n sink.complete();\n }\n },\n (reason: unknown) => {\n if (!signal.aborted) sink.error(reason);\n },\n );\n });\n }\n\n return stream((sink, signal) => {\n const iterator = (source as Iterable<T>)[Symbol.iterator]();\n\n try {\n while (!signal.aborted) {\n const result = iterator.next();\n\n if (result.done) {\n sink.complete();\n\n return;\n }\n\n sink.next(result.value);\n }\n } catch (reason) {\n sink.error(reason);\n }\n\n return () => {\n iterator.return?.();\n };\n });\n}\n\nexport function fromEvent<T = Event>(\n target: {\n addEventListener(type: string, listener: (event: T) => void): void;\n removeEventListener(type: string, listener: (event: T) => void): void;\n },\n type: string,\n): Stream<T> {\n return stream((sink) => {\n const listener = (event: T): void => sink.next(event);\n\n target.addEventListener(type, listener);\n\n return () => target.removeEventListener(type, listener);\n });\n}\n\nexport function interval(options: IntervalOptions): Stream<number> {\n assertDuration(options.every, 'Interval duration');\n\n return stream((sink) => {\n let index = 0;\n\n return defaultScheduler.repeat(() => sink.next(index++), options.every);\n });\n}\n\nexport function timer(options: TimerOptions): Stream<number> {\n assertDuration(options.delay, 'Timer delay');\n\n if (options.interval !== undefined) assertDuration(options.interval, 'Timer interval');\n\n return stream((sink) => {\n let index = 0;\n let cancelInterval: (() => void) | undefined;\n const cancelDelay = defaultScheduler.delay(() => {\n sink.next(index++);\n\n if (options.interval === undefined) {\n sink.complete();\n\n return;\n }\n\n cancelInterval = defaultScheduler.repeat(() => sink.next(index++), options.interval);\n }, options.delay);\n\n return () => {\n cancelDelay();\n cancelInterval?.();\n };\n });\n}\n"],"mappings":"8DAcA,SAAS,EAAe,EAAsB,EAAoB,CAChE,GAAI,CAAC,OAAO,SAAS,CAAY,GAAK,EAAe,EACnD,MAAU,WAAW,GAAG,EAAK,uDAAuD,CAExF,CAEA,SAAgB,EAAM,GAAG,EAAwB,CAC/C,OAAO,EAAA,OAAQ,GAAS,CACtB,IAAK,IAAM,KAAS,EAAQ,EAAK,KAAK,CAAK,EAC3C,EAAK,SAAS,CAChB,CAAC,CACH,CAEA,SAAgB,EAAQ,EAAgE,CA6CtF,OA5CI,OAAO,iBAAiB,OAAO,CAAM,EAChC,EAAA,QAAQ,EAAM,IAAW,CAC9B,IAAM,EAAY,EAA4B,OAAO,cAAc,CAAC,EAoBpE,OAlBM,SAAY,CAChB,GAAI,CACF,KAAO,CAAC,EAAO,SAAS,CACtB,IAAM,EAAS,MAAM,EAAS,KAAK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IAAA,IAAW,EAAe,EAAQ,SAAU,gBAAgB,EAE9E,EAAA,OAAQ,GAAS,CACtB,IAAI,EAAQ,EACR,EACE,EAAc,EAAA,iBAAiB,UAAY,CAG/C,GAFA,EAAK,KAAK,GAAO,EAEb,EAAQ,WAAa,IAAA,GAAW,CAClC,EAAK,SAAS,EAEd,MACF,CAEA,EAAiB,EAAA,iBAAiB,WAAa,EAAK,KAAK,GAAO,EAAG,EAAQ,QAAQ,CACrF,EAAG,EAAQ,KAAK,EAEhB,UAAa,CACX,EAAY,EACZ,IAAiB,CACnB,CACF,CAAC,CACH"}
|
|
@@ -1,50 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* from([1, 2, 3]).subscribe(console.log);
|
|
14
|
-
* from(fetch('/api/data').then((r) => r.json())).subscribe(console.log);
|
|
15
|
-
*/
|
|
16
|
-
export declare function from<T>(source: AsyncIterable<T> | Iterable<T> | Promise<T>): Flux<T>;
|
|
17
|
-
/**
|
|
18
|
-
* Emits an incrementing integer (starting at 0) every `ms` milliseconds.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const ticks = interval(1000); // 0, 1, 2, ... every second
|
|
22
|
-
*/
|
|
23
|
-
export declare function interval(ms: number, scheduler?: Scheduler): Flux<number>;
|
|
24
|
-
/**
|
|
25
|
-
* After an initial `delay` ms, emits `0`, then (if `intervalMs` is provided)
|
|
26
|
-
* emits incrementing values every `intervalMs` ms.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* timer(1000).subscribe(console.log); // emits 0 after 1s, then completes
|
|
30
|
-
* timer(1000, 500).subscribe(console.log); // emits 0 after 1s, then 1, 2, 3... every 500ms
|
|
31
|
-
*/
|
|
32
|
-
export declare function timer(delay: number, intervalMs?: number, scheduler?: Scheduler): Flux<number>;
|
|
33
|
-
/** A `Flux` that completes immediately without emitting any values. */
|
|
34
|
-
export declare function empty<T = never>(): Flux<T>;
|
|
35
|
-
/** A `Flux` that never emits, errors, or completes. */
|
|
36
|
-
export declare function never<T = never>(): Flux<T>;
|
|
37
|
-
/** A `Flux` that immediately errors with the given value. */
|
|
38
|
-
export declare function throwError<T = never>(errorFactory: (() => unknown) | unknown): Flux<T>;
|
|
39
|
-
/**
|
|
40
|
-
* Creates a `Flux` from a DOM `EventTarget` or Node.js `EventEmitter`-like
|
|
41
|
-
* object, emitting each time the named event fires.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* fromEvent(document, 'click').subscribe((e) => console.log(e));
|
|
45
|
-
*/
|
|
1
|
+
import type { Stream } from '../types';
|
|
2
|
+
export type IntervalOptions = {
|
|
3
|
+
every: number;
|
|
4
|
+
};
|
|
5
|
+
export type TimerOptions = {
|
|
6
|
+
delay: number;
|
|
7
|
+
interval?: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function of<T>(...values: T[]): Stream<T>;
|
|
10
|
+
export declare function from<T>(source: AsyncIterable<T> | Iterable<T> | Promise<T>): Stream<T>;
|
|
46
11
|
export declare function fromEvent<T = Event>(target: {
|
|
47
12
|
addEventListener(type: string, listener: (event: T) => void): void;
|
|
48
13
|
removeEventListener(type: string, listener: (event: T) => void): void;
|
|
49
|
-
},
|
|
14
|
+
}, type: string): Stream<T>;
|
|
15
|
+
export declare function interval(options: IntervalOptions): Stream<number>;
|
|
16
|
+
export declare function timer(options: TimerOptions): Stream<number>;
|
|
50
17
|
//# sourceMappingURL=creation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"creation.d.ts","sourceRoot":"","sources":["../../src/operators/creation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"creation.d.ts","sourceRoot":"","sources":["../../src/operators/creation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKvC,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAQF,wBAAgB,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAK/C;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAoEtF;AAED,wBAAgB,SAAS,CAAC,CAAC,GAAG,KAAK,EACjC,MAAM,EAAE;IACN,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC;IACnE,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC;CACvE,EACD,IAAI,EAAE,MAAM,GACX,MAAM,CAAC,CAAC,CAAC,CAQX;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,CAQjE;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAyB3D"}
|