@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,90 +1,86 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { stream as e } from "../core.js";
|
|
2
|
+
import { defaultScheduler as t } from "../_scheduler.js";
|
|
3
3
|
//#region src/operators/creation.ts
|
|
4
|
-
function n(
|
|
4
|
+
function n(e, t) {
|
|
5
|
+
if (!Number.isFinite(e) || e < 0) throw RangeError(`${t} must be a finite number greater than or equal to zero`);
|
|
6
|
+
}
|
|
7
|
+
function r(...t) {
|
|
5
8
|
return e((e) => {
|
|
6
9
|
for (let n of t) e.next(n);
|
|
7
|
-
e.complete
|
|
10
|
+
e.complete();
|
|
8
11
|
});
|
|
9
12
|
}
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
if (Symbol.asyncIterator in t) {
|
|
22
|
-
let n = t;
|
|
23
|
-
return e((e) => {
|
|
24
|
-
let t = !1, r = n[Symbol.asyncIterator]();
|
|
25
|
-
return (async () => {
|
|
26
|
-
try {
|
|
27
|
-
for (;;) {
|
|
28
|
-
let { done: n, value: i } = await r.next();
|
|
29
|
-
if (t || n) break;
|
|
30
|
-
e.next(i);
|
|
13
|
+
function i(t) {
|
|
14
|
+
return Symbol.asyncIterator in Object(t) ? e((e, n) => {
|
|
15
|
+
let r = t[Symbol.asyncIterator]();
|
|
16
|
+
return (async () => {
|
|
17
|
+
try {
|
|
18
|
+
for (; !n.aborted;) {
|
|
19
|
+
let t = await r.next();
|
|
20
|
+
if (t.done) {
|
|
21
|
+
e.complete();
|
|
22
|
+
return;
|
|
31
23
|
}
|
|
32
|
-
|
|
33
|
-
} catch (n) {
|
|
34
|
-
t || e.error?.(n);
|
|
24
|
+
e.next(t.value);
|
|
35
25
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}
|
|
26
|
+
} catch (t) {
|
|
27
|
+
n.aborted || e.error(t);
|
|
28
|
+
}
|
|
29
|
+
})(), () => {
|
|
30
|
+
r.return?.();
|
|
31
|
+
};
|
|
32
|
+
}) : typeof t.then == "function" ? e((e, n) => {
|
|
33
|
+
t.then((t) => {
|
|
34
|
+
n.aborted || (e.next(t), e.complete());
|
|
35
|
+
}, (t) => {
|
|
36
|
+
n.aborted || e.error(t);
|
|
39
37
|
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return e((e) => {
|
|
38
|
+
}) : e((e, n) => {
|
|
39
|
+
let r = t[Symbol.iterator]();
|
|
43
40
|
try {
|
|
44
|
-
for (
|
|
45
|
-
|
|
41
|
+
for (; !n.aborted;) {
|
|
42
|
+
let t = r.next();
|
|
43
|
+
if (t.done) {
|
|
44
|
+
e.complete();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
e.next(t.value);
|
|
48
|
+
}
|
|
46
49
|
} catch (t) {
|
|
47
|
-
e.error
|
|
50
|
+
e.error(t);
|
|
48
51
|
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function i(n, r = t) {
|
|
52
|
-
return e((e) => {
|
|
53
|
-
let t = 0;
|
|
54
|
-
return r.repeat(() => e.next(t++), n);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
function a(n, r, i = t) {
|
|
58
|
-
return e((e) => {
|
|
59
|
-
let t = 0, a, o = i.delay(() => {
|
|
60
|
-
e.next(t++), r === void 0 ? e.complete?.() : a = i.repeat(() => e.next(t++), r);
|
|
61
|
-
}, n);
|
|
62
52
|
return () => {
|
|
63
|
-
|
|
53
|
+
r.return?.();
|
|
64
54
|
};
|
|
65
55
|
});
|
|
66
56
|
}
|
|
67
|
-
function
|
|
57
|
+
function a(t, n) {
|
|
68
58
|
return e((e) => {
|
|
69
|
-
e.
|
|
59
|
+
let r = (t) => e.next(t);
|
|
60
|
+
return t.addEventListener(n, r), () => t.removeEventListener(n, r);
|
|
70
61
|
});
|
|
71
62
|
}
|
|
72
|
-
function
|
|
73
|
-
return e(() => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return e((e) => {
|
|
77
|
-
let n = typeof t == "function" ? t() : t;
|
|
78
|
-
e.error?.(n);
|
|
63
|
+
function o(r) {
|
|
64
|
+
return n(r.every, "Interval duration"), e((e) => {
|
|
65
|
+
let n = 0;
|
|
66
|
+
return t.repeat(() => e.next(n++), r.every);
|
|
79
67
|
});
|
|
80
68
|
}
|
|
81
|
-
function
|
|
82
|
-
return e((e) => {
|
|
83
|
-
let
|
|
84
|
-
|
|
69
|
+
function s(r) {
|
|
70
|
+
return n(r.delay, "Timer delay"), r.interval !== void 0 && n(r.interval, "Timer interval"), e((e) => {
|
|
71
|
+
let n = 0, i, a = t.delay(() => {
|
|
72
|
+
if (e.next(n++), r.interval === void 0) {
|
|
73
|
+
e.complete();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
i = t.repeat(() => e.next(n++), r.interval);
|
|
77
|
+
}, r.delay);
|
|
78
|
+
return () => {
|
|
79
|
+
a(), i?.();
|
|
80
|
+
};
|
|
85
81
|
});
|
|
86
82
|
}
|
|
87
83
|
//#endregion
|
|
88
|
-
export {
|
|
84
|
+
export { i as from, a as fromEvent, o as interval, r as of, s as timer };
|
|
89
85
|
|
|
90
86
|
//# sourceMappingURL=creation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"creation.js","names":[],"sources":["../../src/operators/creation.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"creation.js","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":";;;AAcA,SAAS,EAAe,GAAsB,GAAoB;CAChE,IAAI,CAAC,OAAO,SAAS,CAAY,KAAK,IAAe,GACnD,MAAU,WAAW,GAAG,EAAK,uDAAuD;AAExF;AAEA,SAAgB,EAAM,GAAG,GAAwB;CAC/C,OAAO,GAAQ,MAAS;EACtB,KAAK,IAAM,KAAS,GAAQ,EAAK,KAAK,CAAK;EAC3C,EAAK,SAAS;CAChB,CAAC;AACH;AAEA,SAAgB,EAAQ,GAAgE;CA6CtF,OA5CI,OAAO,iBAAiB,OAAO,CAAM,IAChC,GAAQ,GAAM,MAAW;EAC9B,IAAM,IAAY,EAA4B,OAAO,cAAc,CAAC;EAoBpE,QAlBM,YAAY;GAChB,IAAI;IACF,OAAO,CAAC,EAAO,UAAS;KACtB,IAAM,IAAS,MAAM,EAAS,KAAK;KAEnC,IAAI,EAAO,MAAM;MACf,EAAK,SAAS;MAEd;KACF;KAEA,EAAK,KAAK,EAAO,KAAK;IACxB;GACF,SAAS,GAAQ;IACf,AAAK,EAAO,WAAS,EAAK,MAAM,CAAM;GACxC;EACF,EAAA,CAA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SAAS;IAEd;GACF;GAEA,IAAiB,EAAiB,aAAa,EAAK,KAAK,GAAO,GAAG,EAAQ,QAAQ;EACrF,GAAG,EAAQ,KAAK;EAEhB,aAAa;GAEX,AADA,EAAY,GACZ,IAAiB;EACnB;CACF,CAAC;AACH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../core.cjs"),t=require("../
|
|
1
|
+
const e=require("../core.cjs"),t=require("../_link.cjs"),n=require("../errors.cjs"),r=require("../_scheduler.cjs");function i(e,t){if(!Number.isFinite(e)||e<0)throw RangeError(`${t} must be a finite number greater than or equal to zero`)}function a(n){if(!Number.isInteger(n)||n<0)throw RangeError(`take count must be a non-negative integer`);return r=>e.stream((e,i)=>{if(n===0){e.complete();return}let a=0,o={};return o.current=t.link(r,{complete:e.complete,error:e.error,next(t){e.next(t),a++,a===n&&(e.complete(),o.current?.unsubscribe())}},i),()=>o.current?.unsubscribe()})}function o(n){return r=>e.stream((e,i)=>{let a,o,s=()=>{},c=()=>{a?.unsubscribe(),o?.unsubscribe(),e.complete()};if(n instanceof AbortSignal){if(n.aborted){e.complete();return}n.addEventListener(`abort`,c,{once:!0}),s=()=>n.removeEventListener(`abort`,c)}else o=t.link(n,{error:e.error,next:c},i);return i.aborted||(a=t.link(r,{complete:e.complete,error:e.error,next:e.next},i)),()=>{s(),a?.unsubscribe(),o?.unsubscribe()}})}function s(n){return i(n.for,`Debounce duration`),i=>e.stream((e,a)=>{let o,s,c=!1,l=()=>{o=void 0,c&&(c=!1,e.next(s))},u=t.link(i,{complete(){o?.(),l(),e.complete()},error:e.error,next(e){s=e,c=!0,o?.(),o=r.defaultScheduler.delay(l,n.for)}},a);return()=>{o?.(),u.unsubscribe()}})}function c(a){return i(a.after,`Timeout duration`),i=>e.stream((e,o)=>{let s,c=()=>{s=r.defaultScheduler.delay(()=>e.error(new n.FluxTimeoutError(a.after)),a.after)};c();let l=t.link(i,{complete(){s(),e.complete()},error(t){s(),e.error(t)},next(t){s(),c(),e.next(t)}},o);return()=>{s(),l.unsubscribe()}})}exports.debounce=s,exports.take=a,exports.takeUntil=o,exports.timeout=c;
|
|
2
2
|
//# sourceMappingURL=filtering.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.cjs","names":[],"sources":["../../src/operators/filtering.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"filtering.cjs","names":[],"sources":["../../src/operators/filtering.ts"],"sourcesContent":["import type { Operator, Stream, Subscription } from '../types';\n\nimport { link } from '../_link';\nimport { defaultScheduler } from '../_scheduler';\nimport { stream } from '../core';\nimport { FluxTimeoutError } from '../errors';\n\nexport type DebounceOptions = {\n for: number;\n};\n\nexport type TimeoutOptions = {\n after: 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 take<T>(count: number): Operator<T, T> {\n if (!Number.isInteger(count) || count < 0) {\n throw new RangeError('take count must be a non-negative integer');\n }\n\n return (source) =>\n stream((sink, signal) => {\n if (count === 0) {\n sink.complete();\n\n return;\n }\n\n let seen = 0;\n const subscriptionRef: { current?: Subscription } = {};\n\n subscriptionRef.current = link(\n source,\n {\n complete: sink.complete,\n error: sink.error,\n next(value) {\n sink.next(value);\n seen++;\n\n if (seen === count) {\n sink.complete();\n subscriptionRef.current?.unsubscribe();\n }\n },\n },\n signal,\n );\n\n return () => subscriptionRef.current?.unsubscribe();\n });\n}\n\nexport function takeUntil<T>(notifier: AbortSignal | Stream<unknown>): Operator<T, T> {\n return (source) =>\n stream((sink, signal) => {\n let sourceSubscription: Subscription | undefined;\n let notifierSubscription: Subscription | undefined;\n let removeNotifier = (): void => {};\n\n const complete = (): void => {\n sourceSubscription?.unsubscribe();\n notifierSubscription?.unsubscribe();\n sink.complete();\n };\n\n if (notifier instanceof AbortSignal) {\n if (notifier.aborted) {\n sink.complete();\n\n return;\n }\n\n notifier.addEventListener('abort', complete, { once: true });\n removeNotifier = (): void => notifier.removeEventListener('abort', complete);\n } else {\n notifierSubscription = link(notifier, { error: sink.error, next: complete }, signal);\n }\n\n if (!signal.aborted) {\n sourceSubscription = link(\n source,\n {\n complete: sink.complete,\n error: sink.error,\n next: sink.next,\n },\n signal,\n );\n }\n\n return () => {\n removeNotifier();\n sourceSubscription?.unsubscribe();\n notifierSubscription?.unsubscribe();\n };\n });\n}\n\nexport function debounce<T>(options: DebounceOptions): Operator<T, T> {\n assertDuration(options.for, 'Debounce duration');\n\n return (source) =>\n stream((sink, signal) => {\n let cancel: (() => void) | undefined;\n let pending: T | undefined;\n let hasPending = false;\n\n const flush = (): void => {\n cancel = undefined;\n\n if (!hasPending) return;\n\n hasPending = false;\n sink.next(pending as T);\n };\n\n const subscription = link(\n source,\n {\n complete() {\n cancel?.();\n flush();\n sink.complete();\n },\n error: sink.error,\n next(value) {\n pending = value;\n hasPending = true;\n cancel?.();\n cancel = defaultScheduler.delay(flush, options.for);\n },\n },\n signal,\n );\n\n return () => {\n cancel?.();\n subscription.unsubscribe();\n };\n });\n}\n\nexport function timeout<T>(options: TimeoutOptions): Operator<T, T> {\n assertDuration(options.after, 'Timeout duration');\n\n return (source) =>\n stream((sink, signal) => {\n let cancel: () => void;\n\n const start = (): void => {\n cancel = defaultScheduler.delay(() => sink.error(new FluxTimeoutError(options.after)), options.after);\n };\n\n start();\n\n const subscription = link(\n source,\n {\n complete() {\n cancel();\n sink.complete();\n },\n error(reason) {\n cancel();\n sink.error(reason);\n },\n next(value) {\n cancel();\n start();\n sink.next(value);\n },\n },\n signal,\n );\n\n return () => {\n cancel();\n subscription.unsubscribe();\n };\n });\n}\n"],"mappings":"mHAeA,SAAS,EAAe,EAAsB,EAAoB,CAChE,GAAI,CAAC,OAAO,SAAS,CAAY,GAAK,EAAe,EACnD,MAAU,WAAW,GAAG,EAAK,uDAAuD,CAExF,CAEA,SAAgB,EAAQ,EAA+B,CACrD,GAAI,CAAC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AEJ,IAEL,EAAa,GACb,EAAK,KAAK,CAAY,EACxB,EAEM,EAAe,EAAA,KACnB,EACA,CACE,UAAW,CACT,IAAS,EACT,EAAM,EACN,EAAK,SAAS,CAChB,EACA,MAAO,EAAK,MACZ,KAAK,EAAO,CACV,EAAU,EACV,EAAa,GACb,IAAS,EACT,EAAS,EAAA,iBAAiB,MAAM,EAAO,EAAQ,GAAG,CACpD,CACF,EACA,CACF,EAEA,UAAa,CACX,IAAS,EACT,EAAa,YAAY,CAC3B,CACF,CAAC,CACL,CAEA,SAAgB,EAAW,EAAyC,CAGlE,OAFA,EAAe,EAAQ,MAAO,kBAAkB,EAExC,GACN,EAAA,QAAQ,EAAM,IAAW,CACvB,IAAI,EAEE,MAAoB,CACxB,EAAS,EAAA,iBAAiB,UAAY,EAAK,MAAM,IAAI,EAAA,iBAAiB,EAAQ,KAAK,CAAC,EAAG,EAAQ,KAAK,CACtG,EAEA,EAAM,EAEN,IAAM,EAAe,EAAA,KACnB,EACA,CACE,UAAW,CACT,EAAO,EACP,EAAK,SAAS,CAChB,EACA,MAAM,EAAQ,CACZ,EAAO,EACP,EAAK,MAAM,CAAM,CACnB,EACA,KAAK,EAAO,CACV,EAAO,EACP,EAAM,EACN,EAAK,KAAK,CAAK,CACjB,CACF,EACA,CACF,EAEA,UAAa,CACX,EAAO,EACP,EAAa,YAAY,CAC3B,CACF,CAAC,CACL"}
|
|
@@ -1,62 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { Operator, Stream } from '../types';
|
|
2
|
+
export type DebounceOptions = {
|
|
3
|
+
for: number;
|
|
4
|
+
};
|
|
5
|
+
export type TimeoutOptions = {
|
|
6
|
+
after: number;
|
|
7
|
+
};
|
|
8
8
|
export declare function take<T>(count: number): Operator<T, T>;
|
|
9
|
-
|
|
10
|
-
export declare function
|
|
11
|
-
|
|
12
|
-
* Complete when either `notifier` emits its first value or an `AbortSignal` aborts.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* source$.pipe(takeUntil(stop$));
|
|
16
|
-
* source$.pipe(takeUntil(abortController.signal));
|
|
17
|
-
*/
|
|
18
|
-
export declare function takeUntil<T>(notifier: AbortSignal | Flux<unknown>): Operator<T, T>;
|
|
19
|
-
/**
|
|
20
|
-
* Emit values while `predicate` is truthy. Complete when it returns `false`.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* of(1, 2, 3, 4).pipe(takeWhile((n) => n < 3)); // emits 1, 2
|
|
24
|
-
*/
|
|
25
|
-
export declare function takeWhile<T>(predicate: (value: T) => boolean): Operator<T, T>;
|
|
26
|
-
/**
|
|
27
|
-
* Emit the last value after `ms` milliseconds of silence.
|
|
28
|
-
* Resets the timer on every source emission.
|
|
29
|
-
*
|
|
30
|
-
* **Note:** if the source completes while a value is pending (timer not yet fired),
|
|
31
|
-
* the pending value is dropped. Only the completion signal is forwarded.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* fromEvent(input, 'input').pipe(debounce(300)); // wait 300ms after last keystroke
|
|
35
|
-
*/
|
|
36
|
-
export declare function debounce<T>(ms: number, scheduler?: Scheduler): Operator<T, T>;
|
|
37
|
-
/**
|
|
38
|
-
* Emit at most once per `ms` milliseconds. Leading edge by default.
|
|
39
|
-
* Pass a custom `clock` function (default: `Date.now`) to control time in tests.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* fromEvent(window, 'scroll').pipe(throttle(100));
|
|
43
|
-
*/
|
|
44
|
-
export declare function throttle<T>(ms: number, clock?: () => number): Operator<T, T>;
|
|
45
|
-
/**
|
|
46
|
-
* When `notifier` emits, emit the latest value from `source` (if any).
|
|
47
|
-
* Useful for polling-like patterns.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* source$.pipe(sample(interval(1000))); // emit latest value every 1s
|
|
51
|
-
*/
|
|
52
|
-
export declare function sample<T>(notifier: Flux<unknown>): Operator<T, T>;
|
|
53
|
-
/** Emit only the first value, then complete. Equivalent to `take(1)`. */
|
|
54
|
-
export declare function first<T>(): Operator<T, T>;
|
|
55
|
-
/**
|
|
56
|
-
* Emit only the last value, collected when source completes.
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* of(1, 2, 3).pipe(last()); // emits 3
|
|
60
|
-
*/
|
|
61
|
-
export declare function last<T>(): Operator<T, T>;
|
|
9
|
+
export declare function takeUntil<T>(notifier: AbortSignal | Stream<unknown>): Operator<T, T>;
|
|
10
|
+
export declare function debounce<T>(options: DebounceOptions): Operator<T, T>;
|
|
11
|
+
export declare function timeout<T>(options: TimeoutOptions): Operator<T, T>;
|
|
62
12
|
//# sourceMappingURL=filtering.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../src/operators/filtering.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../../src/operators/filtering.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAgB,MAAM,UAAU,CAAC;AAO/D,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAQF,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAoCrD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CA4CpF;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CA0CpE;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAsClE"}
|
|
@@ -1,140 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { stream as e } from "../core.js";
|
|
2
|
+
import { link as t } from "../_link.js";
|
|
3
|
+
import { FluxTimeoutError as n } from "../errors.js";
|
|
4
|
+
import { defaultScheduler as r } from "../_scheduler.js";
|
|
4
5
|
//#region src/operators/filtering.ts
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
function i(e, t) {
|
|
7
|
+
if (!Number.isFinite(e) || e < 0) throw RangeError(`${t} must be a finite number greater than or equal to zero`);
|
|
8
|
+
}
|
|
9
|
+
function a(n) {
|
|
10
|
+
if (!Number.isInteger(n) || n < 0) throw RangeError("take count must be a non-negative integer");
|
|
11
|
+
return (r) => e((e, i) => {
|
|
12
|
+
if (n === 0) {
|
|
13
|
+
e.complete();
|
|
9
14
|
return;
|
|
10
15
|
}
|
|
11
|
-
let
|
|
12
|
-
return
|
|
13
|
-
complete: e.complete,
|
|
14
|
-
error: e.error,
|
|
15
|
-
next(n) {
|
|
16
|
-
e.next(n), r++, r >= t && (e.complete?.(), i());
|
|
17
|
-
}
|
|
18
|
-
}), i;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
function i(t) {
|
|
22
|
-
return (n) => e((e) => {
|
|
23
|
-
let r = 0;
|
|
24
|
-
return n.subscribe({
|
|
16
|
+
let a = 0, o = {};
|
|
17
|
+
return o.current = t(r, {
|
|
25
18
|
complete: e.complete,
|
|
26
19
|
error: e.error,
|
|
27
|
-
next(
|
|
28
|
-
|
|
20
|
+
next(t) {
|
|
21
|
+
e.next(t), a++, a === n && (e.complete(), o.current?.unsubscribe());
|
|
29
22
|
}
|
|
30
|
-
});
|
|
23
|
+
}, i), () => o.current?.unsubscribe();
|
|
31
24
|
});
|
|
32
25
|
}
|
|
33
|
-
function
|
|
34
|
-
return (
|
|
35
|
-
let
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
if (
|
|
39
|
-
if (
|
|
40
|
-
e.complete
|
|
26
|
+
function o(n) {
|
|
27
|
+
return (r) => e((e, i) => {
|
|
28
|
+
let a, o, s = () => {}, c = () => {
|
|
29
|
+
a?.unsubscribe(), o?.unsubscribe(), e.complete();
|
|
30
|
+
};
|
|
31
|
+
if (n instanceof AbortSignal) {
|
|
32
|
+
if (n.aborted) {
|
|
33
|
+
e.complete();
|
|
41
34
|
return;
|
|
42
35
|
}
|
|
43
|
-
|
|
44
|
-
} else
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
error(t) {
|
|
50
|
-
r = !0, a(), e.error?.(t);
|
|
51
|
-
},
|
|
52
|
-
next: e.next
|
|
53
|
-
});
|
|
54
|
-
return () => {
|
|
55
|
-
a(), o();
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function o(t) {
|
|
60
|
-
return (r) => e((e) => {
|
|
61
|
-
let i = () => {};
|
|
62
|
-
return i = r.subscribe({
|
|
36
|
+
n.addEventListener("abort", c, { once: !0 }), s = () => n.removeEventListener("abort", c);
|
|
37
|
+
} else o = t(n, {
|
|
38
|
+
error: e.error,
|
|
39
|
+
next: c
|
|
40
|
+
}, i);
|
|
41
|
+
return i.aborted || (a = t(r, {
|
|
63
42
|
complete: e.complete,
|
|
64
43
|
error: e.error,
|
|
65
|
-
next
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
}), i;
|
|
44
|
+
next: e.next
|
|
45
|
+
}, i)), () => {
|
|
46
|
+
s(), a?.unsubscribe(), o?.unsubscribe();
|
|
47
|
+
};
|
|
71
48
|
});
|
|
72
49
|
}
|
|
73
|
-
function s(n
|
|
74
|
-
return (
|
|
75
|
-
let
|
|
50
|
+
function s(n) {
|
|
51
|
+
return i(n.for, "Debounce duration"), (i) => e((e, a) => {
|
|
52
|
+
let o, s, c = !1, l = () => {
|
|
53
|
+
o = void 0, c && (c = !1, e.next(s));
|
|
54
|
+
}, u = t(i, {
|
|
76
55
|
complete() {
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
error(t) {
|
|
80
|
-
i?.(), e.error?.(t);
|
|
56
|
+
o?.(), l(), e.complete();
|
|
81
57
|
},
|
|
82
|
-
next(t) {
|
|
83
|
-
i?.(), i = r.delay(() => e.next(t), n);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
return () => {
|
|
87
|
-
i?.(), a();
|
|
88
|
-
};
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
function c(t, n = Date.now) {
|
|
92
|
-
return (r) => e((e) => {
|
|
93
|
-
let i = -Infinity;
|
|
94
|
-
return r.subscribe({
|
|
95
|
-
complete: e.complete,
|
|
96
|
-
error: e.error,
|
|
97
|
-
next(r) {
|
|
98
|
-
let a = n();
|
|
99
|
-
a - i >= t && (i = a, e.next(r));
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
function l(t) {
|
|
105
|
-
return (n) => e((e) => {
|
|
106
|
-
let r, i = !1, a = n.subscribe({
|
|
107
|
-
complete: e.complete,
|
|
108
58
|
error: e.error,
|
|
109
59
|
next(e) {
|
|
110
|
-
|
|
60
|
+
s = e, c = !0, o?.(), o = r.delay(l, n.for);
|
|
111
61
|
}
|
|
112
|
-
}
|
|
113
|
-
i && e.next(r);
|
|
114
|
-
} });
|
|
62
|
+
}, a);
|
|
115
63
|
return () => {
|
|
116
|
-
|
|
64
|
+
o?.(), u.unsubscribe();
|
|
117
65
|
};
|
|
118
66
|
});
|
|
119
67
|
}
|
|
120
|
-
function
|
|
121
|
-
return
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
68
|
+
function c(a) {
|
|
69
|
+
return i(a.after, "Timeout duration"), (i) => e((e, o) => {
|
|
70
|
+
let s, c = () => {
|
|
71
|
+
s = r.delay(() => e.error(new n(a.after)), a.after);
|
|
72
|
+
};
|
|
73
|
+
c();
|
|
74
|
+
let l = t(i, {
|
|
127
75
|
complete() {
|
|
128
|
-
|
|
76
|
+
s(), e.complete();
|
|
129
77
|
},
|
|
130
|
-
error
|
|
131
|
-
|
|
132
|
-
|
|
78
|
+
error(t) {
|
|
79
|
+
s(), e.error(t);
|
|
80
|
+
},
|
|
81
|
+
next(t) {
|
|
82
|
+
s(), c(), e.next(t);
|
|
133
83
|
}
|
|
134
|
-
});
|
|
84
|
+
}, o);
|
|
85
|
+
return () => {
|
|
86
|
+
s(), l.unsubscribe();
|
|
87
|
+
};
|
|
135
88
|
});
|
|
136
89
|
}
|
|
137
90
|
//#endregion
|
|
138
|
-
export { s as debounce,
|
|
91
|
+
export { s as debounce, a as take, o as takeUntil, c as timeout };
|
|
139
92
|
|
|
140
93
|
//# sourceMappingURL=filtering.js.map
|