@helpers4/observable 1.0.1 → 2.0.0-alpha.10
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/LICENSE.md +150 -650
- package/README.md +53 -5
- package/lib/index.d.ts +41 -0
- package/lib/index.js +69 -0
- package/lib/index.js.map +1 -0
- package/meta/api.json +127 -0
- package/meta/examples.json +30 -0
- package/meta/licenses.json +11 -0
- package/package.json +36 -102
- package/CHANGELOG.md +0 -11
- package/build/main/helper/observable.d.ts +0 -21
- package/build/main/helper/observable.js +0 -33
- package/build/main/helper/observable.spec.d.ts +0 -1
- package/build/main/helper/observable.spec.js +0 -23
- package/build/main/index.d.ts +0 -1
- package/build/main/index.js +0 -18
- package/build/module/helper/observable.d.ts +0 -21
- package/build/module/helper/observable.js +0 -29
- package/build/module/helper/observable.spec.d.ts +0 -1
- package/build/module/helper/observable.spec.js +0 -18
- package/build/module/index.d.ts +0 -1
- package/build/module/index.js +0 -2
package/README.md
CHANGED
|
@@ -5,14 +5,62 @@ Every helper is a standalone module and supports tree-shaking, so you can use on
|
|
|
5
5
|
|
|
6
6
|
## @helpers4/observable
|
|
7
7
|
|
|
8
|
-
A set of helpers for working with
|
|
8
|
+
A set of helpers for working with URLs.
|
|
9
9
|
|
|
10
10
|
## Documentation
|
|
11
11
|
|
|
12
|
-
[https://helpers4.
|
|
12
|
+
[https://helpers4.dev/typescript/categories/observable/](https://helpers4.dev/typescript/categories/observable/)
|
|
13
|
+
|
|
14
|
+
<!-- AUTOMATIC-METHODS -->
|
|
15
|
+
- combine
|
|
16
|
+
- combineLatest
|
|
17
|
+
<!-- /AUTOMATIC-METHODS -->
|
|
13
18
|
|
|
14
19
|
## See
|
|
15
20
|
|
|
16
|
-
-
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
21
|
+
<!-- AUTOMATIC-SIBLINGS -->
|
|
22
|
+
- [array](../array)
|
|
23
|
+
- [date](../date)
|
|
24
|
+
- [function](../function)
|
|
25
|
+
- [math](../math)
|
|
26
|
+
- [number](../number)
|
|
27
|
+
- [object](../object)
|
|
28
|
+
- [promise](../promise)
|
|
29
|
+
- [string](../string)
|
|
30
|
+
- [type](../type)
|
|
31
|
+
- [url](../url)
|
|
32
|
+
- [version](../version)
|
|
33
|
+
<!-- /AUTOMATIC-SIBLINGS -->
|
|
34
|
+
|
|
35
|
+
## All Available Packages
|
|
36
|
+
|
|
37
|
+
<!-- AUTOMATIC-CATEGORIES-TABLE -->
|
|
38
|
+
| Name | Package | Source Code | Description |
|
|
39
|
+
|------|---------|-------------|-------------|
|
|
40
|
+
| array | [@helpers4/array](https://www.npmjs.com/package/@helpers4/array) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/array) | Array manipulation utilities |
|
|
41
|
+
| date | [@helpers4/date](https://www.npmjs.com/package/@helpers4/date) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/date) | date utilities |
|
|
42
|
+
| function | [@helpers4/function](https://www.npmjs.com/package/@helpers4/function) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/function) | Function utilities and type guards |
|
|
43
|
+
| math | [@helpers4/math](https://www.npmjs.com/package/@helpers4/math) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/math) | math utilities |
|
|
44
|
+
| number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) | number utilities |
|
|
45
|
+
| object | [@helpers4/object](https://www.npmjs.com/package/@helpers4/object) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/object) | Object manipulation utilities |
|
|
46
|
+
| observable | [@helpers4/observable](https://www.npmjs.com/package/@helpers4/observable) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/observable) | Observable utilities and combinators |
|
|
47
|
+
| promise | [@helpers4/promise](https://www.npmjs.com/package/@helpers4/promise) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/promise) | Promise utilities and error handling |
|
|
48
|
+
| string | [@helpers4/string](https://www.npmjs.com/package/@helpers4/string) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/string) | String manipulation and formatting utilities |
|
|
49
|
+
| type | [@helpers4/type](https://www.npmjs.com/package/@helpers4/type) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/type) | type utilities |
|
|
50
|
+
| url | [@helpers4/url](https://www.npmjs.com/package/@helpers4/url) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/url) | URL parsing and manipulation utilities |
|
|
51
|
+
| version | [@helpers4/version](https://www.npmjs.com/package/@helpers4/version) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/version) | Version string manipulation utilities |
|
|
52
|
+
<!-- /AUTOMATIC-CATEGORIES-TABLE -->
|
|
53
|
+
|
|
54
|
+
## Contributors
|
|
55
|
+
|
|
56
|
+
<table>
|
|
57
|
+
<tr>
|
|
58
|
+
<td align="center" style="word-wrap: break-word; width: 150.0; height: 150.0">
|
|
59
|
+
<a href=https://github.com/baxyz>
|
|
60
|
+
<img src=https://avatars.githubusercontent.com/u/7852177?v=4 width="100;" alt=baxyz/>
|
|
61
|
+
<br />
|
|
62
|
+
<sub style="font-size:14px"><b>baxyz</b></sub>
|
|
63
|
+
</a>
|
|
64
|
+
</td>
|
|
65
|
+
</tr>
|
|
66
|
+
</table>
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Observable, OperatorFunction, ObservableInputTuple, ObservableInput, ObservedValueOf } from 'rxjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of helpers4.
|
|
5
|
+
* Copyright (C) 2025 baxyz
|
|
6
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
type combineOptions<T, U> = {
|
|
10
|
+
readonly preTreatment?: OperatorFunction<readonly [T, U], readonly [T, U]>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Combine two observables with a map function and an optional pre-treatment.
|
|
14
|
+
*
|
|
15
|
+
* Note: you can use the pre-treatment to add a filter, a distinctUntilChanged,
|
|
16
|
+
* any other operator that can be used in a pipe, or even an `UntilDestroy`
|
|
17
|
+
* operator.
|
|
18
|
+
*
|
|
19
|
+
* @param source1 first source of data
|
|
20
|
+
* @param source2 second source of data
|
|
21
|
+
* @param map way to combine data
|
|
22
|
+
* @param options options for the combineLatest operator
|
|
23
|
+
* @returns an observable that emits the result of the map function
|
|
24
|
+
* @see combineLatestOperator
|
|
25
|
+
* @see mapOperator
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
*/
|
|
28
|
+
declare function combine<T, U, R>(source1: Observable<T>, source2: Observable<U>, map: (c: readonly [T, U]) => R, options?: combineOptions<T, U>): Observable<R>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* This file is part of helpers4.
|
|
32
|
+
* Copyright (C) 2025 baxyz
|
|
33
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
declare function combineLatest<A extends readonly unknown[]>(sources: readonly [...ObservableInputTuple<A>]): Observable<A>;
|
|
37
|
+
declare function combineLatest<T extends Record<string, ObservableInput<any>>>(sourcesObject: T): Observable<{
|
|
38
|
+
[K in keyof T]: ObservedValueOf<T[K]>;
|
|
39
|
+
}>;
|
|
40
|
+
|
|
41
|
+
export { combine, combineLatest };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { combineLatest as combineLatest$1, map, of } from "rxjs";
|
|
2
|
+
//#region helpers/observable/combine.ts
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of helpers4.
|
|
5
|
+
* Copyright (C) 2025 baxyz
|
|
6
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Combine two observables with a map function and an optional pre-treatment.
|
|
10
|
+
*
|
|
11
|
+
* Note: you can use the pre-treatment to add a filter, a distinctUntilChanged,
|
|
12
|
+
* any other operator that can be used in a pipe, or even an `UntilDestroy`
|
|
13
|
+
* operator.
|
|
14
|
+
*
|
|
15
|
+
* @param source1 first source of data
|
|
16
|
+
* @param source2 second source of data
|
|
17
|
+
* @param map way to combine data
|
|
18
|
+
* @param options options for the combineLatest operator
|
|
19
|
+
* @returns an observable that emits the result of the map function
|
|
20
|
+
* @see combineLatestOperator
|
|
21
|
+
* @see mapOperator
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
*/
|
|
24
|
+
function combine(source1, source2, map$1, options) {
|
|
25
|
+
if (options?.preTreatment) return combineLatest$1([source1, source2]).pipe(options.preTreatment, map(map$1));
|
|
26
|
+
else return combineLatest$1([source1, source2]).pipe(map(map$1));
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region helpers/observable/combineLatest.ts
|
|
30
|
+
/**
|
|
31
|
+
* This file is part of helpers4.
|
|
32
|
+
* Copyright (C) 2025 baxyz
|
|
33
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Combines multiple Observables to create an Observable whose values are
|
|
37
|
+
* calculated from the latest values of each of its input Observables.
|
|
38
|
+
*
|
|
39
|
+
* This method relies on {@link combineLatestOperator} of rxjs.
|
|
40
|
+
*
|
|
41
|
+
* The main difference with {@link combineLatestOperator} is in case of empty parameters.
|
|
42
|
+
* If the parameter is empty (empty array or empty object), the result will be
|
|
43
|
+
* also empty.
|
|
44
|
+
*
|
|
45
|
+
* ATTENTION: this version doesn't support `scheduler` nor `mapper` as last
|
|
46
|
+
* argument like in {@link combineLatestOperator}.
|
|
47
|
+
*
|
|
48
|
+
* @see {@link combineLatestOperator}
|
|
49
|
+
* @see {@link combineLatestAll}
|
|
50
|
+
* @see {@link merge}
|
|
51
|
+
* @see {@link withLatestFrom}
|
|
52
|
+
*
|
|
53
|
+
* @param {ObservableInput} [observables] An array of input Observables to combine with each other.
|
|
54
|
+
* An array of Observables must be given as the first argument.
|
|
55
|
+
* @returns {Observable} An Observable of projected values from the most recent
|
|
56
|
+
* values from each input Observable, or an array of the most recent values from
|
|
57
|
+
* each input Observable.
|
|
58
|
+
* @since 1.0.0
|
|
59
|
+
*/
|
|
60
|
+
function combineLatest(input) {
|
|
61
|
+
if (Array.isArray(input)) {
|
|
62
|
+
input = input.filter((a) => !!a);
|
|
63
|
+
return input.length ? combineLatest$1(...input) : of([]);
|
|
64
|
+
} else return Object.entries(input).filter(([_, v]) => !!v).length ? combineLatest$1(input) : of({});
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { combine, combineLatest };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/observable/combine.ts","../../../helpers/observable/combineLatest.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/*\n * This program is under the terms of the GNU Lesser General Public License version 3\n * The full license information can be found in LICENSE in the root directory of this project.\n */\nimport {\n Observable,\n OperatorFunction,\n combineLatest as combineLatestOperator,\n map as mapOperator,\n} from \"rxjs\";\n\n\ntype combineOptions<T, U> = {\n readonly preTreatment?: OperatorFunction<readonly [T, U], readonly [T, U]>;\n};\n\n/**\n * Combine two observables with a map function and an optional pre-treatment.\n *\n * Note: you can use the pre-treatment to add a filter, a distinctUntilChanged,\n * any other operator that can be used in a pipe, or even an `UntilDestroy`\n * operator.\n *\n * @param source1 first source of data\n * @param source2 second source of data\n * @param map way to combine data\n * @param options options for the combineLatest operator\n * @returns an observable that emits the result of the map function\n * @see combineLatestOperator\n * @see mapOperator\n * @since 1.0.0\n */\nexport function combine<T, U, R>(\n source1: Observable<T>,\n source2: Observable<U>,\n map: (c: readonly [T, U]) => R,\n options?: combineOptions<T, U>\n): Observable<R> {\n if (options?.preTreatment) {\n return combineLatestOperator([source1, source2]).pipe(\n options.preTreatment,\n mapOperator(map)\n );\n } else {\n return combineLatestOperator([source1, source2]).pipe(mapOperator(map));\n }\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/*\n * This program is under the terms of the GNU Lesser General Public License version 3\n * The full license information can be found in LICENSE in the root directory of this project.\n */\nimport {\n Observable,\n ObservableInput,\n ObservableInputTuple,\n ObservedValueOf,\n combineLatest as combineLatestOperator,\n of,\n} from \"rxjs\";\n\n// combineLatest([a, b, c])\nexport function combineLatest<A extends readonly unknown[]>(\n sources: readonly [...ObservableInputTuple<A>]\n): Observable<A>;\n\n// combineLatest({a, b, c})\nexport function combineLatest<T extends Record<string, ObservableInput<any>>>(\n sourcesObject: T\n): Observable<{ [K in keyof T]: ObservedValueOf<T[K]> }>;\n\n/**\n * Combines multiple Observables to create an Observable whose values are\n * calculated from the latest values of each of its input Observables.\n *\n * This method relies on {@link combineLatestOperator} of rxjs.\n *\n * The main difference with {@link combineLatestOperator} is in case of empty parameters.\n * If the parameter is empty (empty array or empty object), the result will be\n * also empty.\n *\n * ATTENTION: this version doesn't support `scheduler` nor `mapper` as last\n * argument like in {@link combineLatestOperator}.\n *\n * @see {@link combineLatestOperator}\n * @see {@link combineLatestAll}\n * @see {@link merge}\n * @see {@link withLatestFrom}\n *\n * @param {ObservableInput} [observables] An array of input Observables to combine with each other.\n * An array of Observables must be given as the first argument.\n * @returns {Observable} An Observable of projected values from the most recent\n * values from each input Observable, or an array of the most recent values from\n * each input Observable.\n * @since 1.0.0\n */\nexport function combineLatest(input: any): any {\n if (Array.isArray(input)) {\n input = input.filter((a) => !!a);\n return input.length ? combineLatestOperator(...input) : of([]);\n } else {\n return Object.entries(input).filter(([_, v]) => !!v).length\n ? combineLatestOperator(input)\n : of({});\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,QACd,SACA,SACA,OACA,SACe;AACf,KAAI,SAAS,aACX,QAAO,gBAAsB,CAAC,SAAS,QAAQ,CAAC,CAAC,KAC/C,QAAQ,cACR,IAAY,MAAI,CACjB;KAED,QAAO,gBAAsB,CAAC,SAAS,QAAQ,CAAC,CAAC,KAAK,IAAY,MAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACI3E,SAAgB,cAAc,OAAiB;AAC7C,KAAI,MAAM,QAAQ,MAAM,EAAE;AACxB,UAAQ,MAAM,QAAQ,MAAM,CAAC,CAAC,EAAE;AAChC,SAAO,MAAM,SAAS,gBAAsB,GAAG,MAAM,GAAG,GAAG,EAAE,CAAC;OAE9D,QAAO,OAAO,QAAQ,MAAM,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,SACjD,gBAAsB,MAAM,GAC5B,GAAG,EAAE,CAAC"}
|
package/meta/api.json
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "observable",
|
|
3
|
+
"version": "2.0.0-alpha.10",
|
|
4
|
+
"functions": [
|
|
5
|
+
{
|
|
6
|
+
"name": "combine",
|
|
7
|
+
"kind": "function",
|
|
8
|
+
"description": "Combine two observables with a map function and an optional pre-treatment.\n\nNote: you can use the pre-treatment to add a filter, a distinctUntilChanged,\nany other operator that can be used in a pipe, or even an `UntilDestroy`\noperator.",
|
|
9
|
+
"since": "1.0.0",
|
|
10
|
+
"signatures": [
|
|
11
|
+
{
|
|
12
|
+
"signature": "combine<T, U, R>(source1: Observable<T>, source2: Observable<U>, map: function, options?: combineOptions<T, U>): Observable<R>",
|
|
13
|
+
"description": "Combine two observables with a map function and an optional pre-treatment.\n\nNote: you can use the pre-treatment to add a filter, a distinctUntilChanged,\nany other operator that can be used in a pipe, or even an `UntilDestroy`\noperator.",
|
|
14
|
+
"params": [
|
|
15
|
+
{
|
|
16
|
+
"name": "source1",
|
|
17
|
+
"type": "Observable<T>",
|
|
18
|
+
"description": "first source of data"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "source2",
|
|
22
|
+
"type": "Observable<U>",
|
|
23
|
+
"description": "second source of data"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "map",
|
|
27
|
+
"type": "function",
|
|
28
|
+
"description": "way to combine data"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "options",
|
|
32
|
+
"type": "combineOptions<T, U>",
|
|
33
|
+
"description": "options for the combineLatest operator",
|
|
34
|
+
"optional": true
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"returns": {
|
|
38
|
+
"type": "Observable<R>",
|
|
39
|
+
"description": "an observable that emits the result of the map function"
|
|
40
|
+
},
|
|
41
|
+
"typeParameters": [
|
|
42
|
+
{
|
|
43
|
+
"name": "T"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "U"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"name": "R"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"examples": [
|
|
55
|
+
{
|
|
56
|
+
"title": "Combine two observables with a map",
|
|
57
|
+
"description": "Combines the latest values of two observables using a mapping function.",
|
|
58
|
+
"code": "combine(of(1), of(2), ([a, b]) => a + b)\n// emits 3"
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"sourceFile": "combine.ts"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"name": "combineLatest",
|
|
65
|
+
"kind": "function",
|
|
66
|
+
"description": "Combines multiple Observables to create an Observable whose values are\ncalculated from the latest values of each of its input Observables.\n\nThis method relies on combineLatestOperator of rxjs.\n\nThe main difference with combineLatestOperator is in case of empty parameters.\nIf the parameter is empty (empty array or empty object), the result will be\nalso empty.\n\nATTENTION: this version doesn't support `scheduler` nor `mapper` as last\nargument like in combineLatestOperator.",
|
|
67
|
+
"since": "1.0.0",
|
|
68
|
+
"signatures": [
|
|
69
|
+
{
|
|
70
|
+
"signature": "combineLatest<A extends readonly unknown[]>(sources: readonly [ObservableInputTuple<A>]): Observable<A>",
|
|
71
|
+
"description": "",
|
|
72
|
+
"params": [
|
|
73
|
+
{
|
|
74
|
+
"name": "sources",
|
|
75
|
+
"type": "readonly [ObservableInputTuple<A>]",
|
|
76
|
+
"description": ""
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
"returns": {
|
|
80
|
+
"type": "Observable<A>",
|
|
81
|
+
"description": ""
|
|
82
|
+
},
|
|
83
|
+
"typeParameters": [
|
|
84
|
+
{
|
|
85
|
+
"name": "A",
|
|
86
|
+
"constraint": "readonly unknown[]"
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"signature": "combineLatest<T extends Record<string, ObservableInput<any>>>(sourcesObject: T): Observable<mapped>",
|
|
92
|
+
"description": "",
|
|
93
|
+
"params": [
|
|
94
|
+
{
|
|
95
|
+
"name": "sourcesObject",
|
|
96
|
+
"type": "T",
|
|
97
|
+
"description": ""
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
"returns": {
|
|
101
|
+
"type": "Observable<mapped>",
|
|
102
|
+
"description": ""
|
|
103
|
+
},
|
|
104
|
+
"typeParameters": [
|
|
105
|
+
{
|
|
106
|
+
"name": "T",
|
|
107
|
+
"constraint": "Record<string, ObservableInput<any>>"
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"examples": [
|
|
113
|
+
{
|
|
114
|
+
"title": "Combine array of observables",
|
|
115
|
+
"description": "Combines an array of observables into one that emits arrays of their latest values.",
|
|
116
|
+
"code": "combineLatest([of(1), of(2), of(3)])\n// emits [1, 2, 3]"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"title": "Handle empty array",
|
|
120
|
+
"description": "Returns an observable that emits an empty array when given no sources.",
|
|
121
|
+
"code": "combineLatest([])\n// emits []"
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
"sourceFile": "combineLatest.ts"
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "observable",
|
|
3
|
+
"functions": [
|
|
4
|
+
{
|
|
5
|
+
"name": "combine",
|
|
6
|
+
"examples": [
|
|
7
|
+
{
|
|
8
|
+
"title": "Combine two observables with a map",
|
|
9
|
+
"description": "Combines the latest values of two observables using a mapping function.",
|
|
10
|
+
"code": "combine(of(1), of(2), ([a, b]) => a + b)\n// emits 3"
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "combineLatest",
|
|
16
|
+
"examples": [
|
|
17
|
+
{
|
|
18
|
+
"title": "Combine array of observables",
|
|
19
|
+
"description": "Combines an array of observables into one that emits arrays of their latest values.",
|
|
20
|
+
"code": "combineLatest([of(1), of(2), of(3)])\n// emits [1, 2, 3]"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"title": "Handle empty array",
|
|
24
|
+
"description": "Returns an observable that emits an empty array when given no sources.",
|
|
25
|
+
"code": "combineLatest([])\n// emits []"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,113 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/observable",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A set of helpers in TS/JS, compatible with tree-shaking,
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"repository":
|
|
9
|
-
|
|
3
|
+
"version": "2.0.0-alpha.10",
|
|
4
|
+
"description": "A set of helpers in TS/JS, compatible with tree-shaking, for observable.",
|
|
5
|
+
"author": "baxyz <baxy@etik.com>",
|
|
6
|
+
"license": "LGPL-3.0",
|
|
7
|
+
"homepage": "https://helpers4.dev/typescript/categories/observable/",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/helpers4/typescript.git"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/index.d.ts",
|
|
19
|
+
"import": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./meta/api.json": "./meta/api.json",
|
|
22
|
+
"./meta/examples.json": "./meta/examples.json",
|
|
23
|
+
"./meta/licenses.json": "./meta/licenses.json",
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
10
26
|
"keywords": [
|
|
11
|
-
"
|
|
12
|
-
"string",
|
|
27
|
+
"helpers",
|
|
13
28
|
"observable",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"combine"
|
|
29
|
+
"combine",
|
|
30
|
+
"combineLatest"
|
|
17
31
|
],
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build": "run-p build:*",
|
|
20
|
-
"build:main": "tsc -p tsconfig.json",
|
|
21
|
-
"build:module": "tsc -p tsconfig.module.json",
|
|
22
|
-
"fix": "run-s fix:*",
|
|
23
|
-
"fix:prettier": "prettier \"src/**/*.ts\" --write",
|
|
24
|
-
"fix:lint": "eslint src --ext .ts --fix",
|
|
25
|
-
"test": "run-s build test:*",
|
|
26
|
-
"test:lint": "eslint src --ext .ts",
|
|
27
|
-
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
|
|
28
|
-
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
|
|
29
|
-
"test:unit": "nyc --silent ava",
|
|
30
|
-
"check-cli": "run-s test diff-integration-tests check-integration-tests",
|
|
31
|
-
"check-integration-tests": "run-s check-integration-test:*",
|
|
32
|
-
"diff-integration-tests": "mkdir -p diff && rm -rf diff/test && cp -r test diff/test && rm -rf diff/test/test-*/.git && cd diff && git init --quiet && git add -A && git commit --quiet --no-verify --allow-empty -m 'WIP' && echo '\\n\\nCommitted most recent integration test output in the \"diff\" directory. Review the changes with \"cd diff && git diff HEAD\" or your preferred git diff viewer.'",
|
|
33
|
-
"watch:build": "tsc -p tsconfig.json -w",
|
|
34
|
-
"watch:test": "nyc --silent ava --watch",
|
|
35
|
-
"cov": "run-s build test:unit cov:html cov:lcov && open-cli coverage/index.html",
|
|
36
|
-
"cov:html": "nyc report --reporter=html",
|
|
37
|
-
"cov:lcov": "nyc report --reporter=lcov",
|
|
38
|
-
"cov:send": "run-s cov:lcov && codecov",
|
|
39
|
-
"cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100",
|
|
40
|
-
"doc": "run-s doc:html && open-cli build/docs/index.html",
|
|
41
|
-
"doc:html": "typedoc src/index.ts --out build/docs",
|
|
42
|
-
"doc:json": "typedoc src/index.ts --json build/docs/typedoc.json --pretty",
|
|
43
|
-
"doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs",
|
|
44
|
-
"version": "standard-version",
|
|
45
|
-
"reset-hard": "git clean -dfx && git reset --hard && npm i",
|
|
46
|
-
"prepare-release": "run-s reset-hard test cov:check doc:html version doc:publish"
|
|
47
|
-
},
|
|
48
|
-
"engines": {
|
|
49
|
-
"node": ">=10"
|
|
50
|
-
},
|
|
51
|
-
"devDependencies": {
|
|
52
|
-
"@ava/typescript": "^1.1.1",
|
|
53
|
-
"@istanbuljs/nyc-config-typescript": "^1.0.1",
|
|
54
|
-
"@typescript-eslint/eslint-plugin": "^4.0.1",
|
|
55
|
-
"@typescript-eslint/parser": "^4.0.1",
|
|
56
|
-
"ava": "^4.3.3",
|
|
57
|
-
"codecov": "^3.5.0",
|
|
58
|
-
"cspell": "^4.1.0",
|
|
59
|
-
"cz-conventional-changelog": "^3.3.0",
|
|
60
|
-
"eslint": "^7.8.0",
|
|
61
|
-
"eslint-config-prettier": "^6.11.0",
|
|
62
|
-
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
63
|
-
"eslint-plugin-functional": "^3.0.2",
|
|
64
|
-
"eslint-plugin-import": "^2.22.0",
|
|
65
|
-
"gh-pages": "^3.1.0",
|
|
66
|
-
"npm-run-all": "^4.1.5",
|
|
67
|
-
"nyc": "^15.1.0",
|
|
68
|
-
"open-cli": "^7.0.1",
|
|
69
|
-
"prettier": "^2.1.1",
|
|
70
|
-
"standard-version": "^9.0.0",
|
|
71
|
-
"ts-node": "^9.0.0",
|
|
72
|
-
"typedoc": "^0.23.13",
|
|
73
|
-
"typescript": "^4.0.2"
|
|
74
|
-
},
|
|
75
32
|
"files": [
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"CHANGELOG.md",
|
|
33
|
+
"lib/index.js",
|
|
34
|
+
"lib/index.d.ts",
|
|
35
|
+
"lib/index.js.map",
|
|
36
|
+
"meta/",
|
|
81
37
|
"LICENSE.md",
|
|
38
|
+
"package.json",
|
|
82
39
|
"README.md"
|
|
83
40
|
],
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"timeout": "60s",
|
|
87
|
-
"typescript": {
|
|
88
|
-
"rewritePaths": {
|
|
89
|
-
"src/": "build/main/"
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
"files": [
|
|
93
|
-
"!build/module/**"
|
|
94
|
-
]
|
|
95
|
-
},
|
|
96
|
-
"config": {
|
|
97
|
-
"commitizen": {
|
|
98
|
-
"path": "cz-conventional-changelog"
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
"prettier": {
|
|
102
|
-
"singleQuote": true
|
|
103
|
-
},
|
|
104
|
-
"nyc": {
|
|
105
|
-
"extends": "@istanbuljs/nyc-config-typescript",
|
|
106
|
-
"exclude": [
|
|
107
|
-
"**/*.spec.js"
|
|
108
|
-
]
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18.0.0"
|
|
109
43
|
},
|
|
110
|
-
"
|
|
111
|
-
"rxjs": "
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"rxjs": "^7.8.2"
|
|
112
46
|
}
|
|
113
|
-
}
|
|
47
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
## 1.0.1 (2022-09-04)
|
|
6
|
-
|
|
7
|
-
### Features
|
|
8
|
-
|
|
9
|
-
- :sparkles: first commit ([e711632](https://github.com/helpers4/observable/commit/e711632fbddada8e49ba9bbf589ff698d7c04570))
|
|
10
|
-
|
|
11
|
-
### 1.0.0 (2022-09-03)
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Observable, OperatorFunction } from 'rxjs';
|
|
2
|
-
declare type combineOptions<T, U> = {
|
|
3
|
-
readonly preTreatment?: OperatorFunction<readonly [T, U], readonly [T, U]>;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Combine two observables with a map function and an optional pre-treatment.
|
|
7
|
-
*
|
|
8
|
-
* Note: you can use the pre-treatment to add a filter, a distinctUntilChanged,
|
|
9
|
-
* any other operator that can be used in a pipe, or even an `UntilDestroy`
|
|
10
|
-
* operator.
|
|
11
|
-
*
|
|
12
|
-
* @param source1 first source of data
|
|
13
|
-
* @param source2 second source of data
|
|
14
|
-
* @param map way to combine data
|
|
15
|
-
* @param options options for the combineLatest operator
|
|
16
|
-
* @returns an observable that emits the result of the map function
|
|
17
|
-
* @see combineLatest
|
|
18
|
-
* @see mapOperator
|
|
19
|
-
*/
|
|
20
|
-
export declare function combine<T, U, R>(source1: Observable<T>, source2: Observable<U>, map: (c: readonly [T, U]) => R, options?: combineOptions<T, U>): Observable<R>;
|
|
21
|
-
export {};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* This program is under the terms of the GNU Affero General Public License version 3
|
|
4
|
-
* The full license information can be found in LICENSE in the root directory of this project.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.combine = void 0;
|
|
8
|
-
const rxjs_1 = require("rxjs");
|
|
9
|
-
/**
|
|
10
|
-
* Combine two observables with a map function and an optional pre-treatment.
|
|
11
|
-
*
|
|
12
|
-
* Note: you can use the pre-treatment to add a filter, a distinctUntilChanged,
|
|
13
|
-
* any other operator that can be used in a pipe, or even an `UntilDestroy`
|
|
14
|
-
* operator.
|
|
15
|
-
*
|
|
16
|
-
* @param source1 first source of data
|
|
17
|
-
* @param source2 second source of data
|
|
18
|
-
* @param map way to combine data
|
|
19
|
-
* @param options options for the combineLatest operator
|
|
20
|
-
* @returns an observable that emits the result of the map function
|
|
21
|
-
* @see combineLatest
|
|
22
|
-
* @see mapOperator
|
|
23
|
-
*/
|
|
24
|
-
function combine(source1, source2, map, options) {
|
|
25
|
-
if (options === null || options === void 0 ? void 0 : options.preTreatment) {
|
|
26
|
-
return (0, rxjs_1.combineLatest)([source1, source2]).pipe(options.preTreatment, (0, rxjs_1.map)(map));
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
return (0, rxjs_1.combineLatest)([source1, source2]).pipe((0, rxjs_1.map)(map));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.combine = combine;
|
|
33
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2JzZXJ2YWJsZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9oZWxwZXIvb2JzZXJ2YWJsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7OztHQUdHOzs7QUFFSCwrQkFLYztBQU1kOzs7Ozs7Ozs7Ozs7OztHQWNHO0FBQ0gsU0FBZ0IsT0FBTyxDQUNyQixPQUFzQixFQUN0QixPQUFzQixFQUN0QixHQUE4QixFQUM5QixPQUE4QjtJQUU5QixJQUFJLE9BQU8sYUFBUCxPQUFPLHVCQUFQLE9BQU8sQ0FBRSxZQUFZLEVBQUU7UUFDekIsT0FBTyxJQUFBLG9CQUFhLEVBQUMsQ0FBQyxPQUFPLEVBQUUsT0FBTyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQzNDLE9BQU8sQ0FBQyxZQUFZLEVBQ3BCLElBQUEsVUFBVyxFQUFDLEdBQUcsQ0FBQyxDQUNqQixDQUFDO0tBQ0g7U0FBTTtRQUNMLE9BQU8sSUFBQSxvQkFBYSxFQUFDLENBQUMsT0FBTyxFQUFFLE9BQU8sQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLElBQUEsVUFBVyxFQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUM7S0FDakU7QUFDSCxDQUFDO0FBZEQsMEJBY0MifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
/*
|
|
7
|
-
* This program is under the terms of the GNU Affero General Public License version 3
|
|
8
|
-
* The full license information can be found in LICENSE in the root directory of this project.
|
|
9
|
-
*/
|
|
10
|
-
const ava_1 = __importDefault(require("ava"));
|
|
11
|
-
const rxjs_1 = require("rxjs");
|
|
12
|
-
const observable_1 = require("./observable");
|
|
13
|
-
(0, ava_1.default)('combine', async (t) => {
|
|
14
|
-
const result = await (0, rxjs_1.firstValueFrom)((0, observable_1.combine)((0, rxjs_1.of)(1), (0, rxjs_1.of)(2), (c) => c[0] + c[1]));
|
|
15
|
-
return t.is(result, 3);
|
|
16
|
-
});
|
|
17
|
-
(0, ava_1.default)('combine with pretreatment', async (t) => {
|
|
18
|
-
const result = await (0, rxjs_1.firstValueFrom)((0, observable_1.combine)((0, rxjs_1.of)(1), (0, rxjs_1.of)(2), (c) => c[0] + c[1], {
|
|
19
|
-
preTreatment: (0, rxjs_1.map)((c) => [c[0], c[1] + 1]),
|
|
20
|
-
}));
|
|
21
|
-
return t.is(result, 4);
|
|
22
|
-
});
|
|
23
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2JzZXJ2YWJsZS5zcGVjLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2hlbHBlci9vYnNlcnZhYmxlLnNwZWMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQTs7O0dBR0c7QUFDSCw4Q0FBdUI7QUFDdkIsK0JBQStDO0FBRS9DLDZDQUF1QztBQUV2QyxJQUFBLGFBQUksRUFBQyxTQUFTLEVBQUUsS0FBSyxFQUFFLENBQUMsRUFBRSxFQUFFO0lBQzFCLE1BQU0sTUFBTSxHQUFHLE1BQU0sSUFBQSxxQkFBYyxFQUNqQyxJQUFBLG9CQUFPLEVBQUMsSUFBQSxTQUFFLEVBQUMsQ0FBQyxDQUFDLEVBQUUsSUFBQSxTQUFFLEVBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FDMUMsQ0FBQztJQUNGLE9BQU8sQ0FBQyxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxDQUFDLENBQUM7QUFDekIsQ0FBQyxDQUFDLENBQUM7QUFFSCxJQUFBLGFBQUksRUFBQywyQkFBMkIsRUFBRSxLQUFLLEVBQUUsQ0FBQyxFQUFFLEVBQUU7SUFDNUMsTUFBTSxNQUFNLEdBQUcsTUFBTSxJQUFBLHFCQUFjLEVBQ2pDLElBQUEsb0JBQU8sRUFBQyxJQUFBLFNBQUUsRUFBQyxDQUFDLENBQUMsRUFBRSxJQUFBLFNBQUUsRUFBQyxDQUFDLENBQUMsRUFBRSxDQUFDLENBQUMsRUFBRSxFQUFFLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMsRUFBRTtRQUN4QyxZQUFZLEVBQUUsSUFBQSxVQUFHLEVBQUMsQ0FBQyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUMsQ0FBQyxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQztLQUMzQyxDQUFDLENBQ0gsQ0FBQztJQUNGLE9BQU8sQ0FBQyxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxDQUFDLENBQUM7QUFDekIsQ0FBQyxDQUFDLENBQUMifQ==
|
package/build/main/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './helper/observable';
|
package/build/main/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./helper/observable"), exports);
|
|
18
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLHNEQUFvQyJ9
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Observable, OperatorFunction } from 'rxjs';
|
|
2
|
-
declare type combineOptions<T, U> = {
|
|
3
|
-
readonly preTreatment?: OperatorFunction<readonly [T, U], readonly [T, U]>;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Combine two observables with a map function and an optional pre-treatment.
|
|
7
|
-
*
|
|
8
|
-
* Note: you can use the pre-treatment to add a filter, a distinctUntilChanged,
|
|
9
|
-
* any other operator that can be used in a pipe, or even an `UntilDestroy`
|
|
10
|
-
* operator.
|
|
11
|
-
*
|
|
12
|
-
* @param source1 first source of data
|
|
13
|
-
* @param source2 second source of data
|
|
14
|
-
* @param map way to combine data
|
|
15
|
-
* @param options options for the combineLatest operator
|
|
16
|
-
* @returns an observable that emits the result of the map function
|
|
17
|
-
* @see combineLatest
|
|
18
|
-
* @see mapOperator
|
|
19
|
-
*/
|
|
20
|
-
export declare function combine<T, U, R>(source1: Observable<T>, source2: Observable<U>, map: (c: readonly [T, U]) => R, options?: combineOptions<T, U>): Observable<R>;
|
|
21
|
-
export {};
|