@helpers4/observable 2.0.0-alpha.2 → 2.0.0-alpha.6
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 +2 -0
- package/api.json +48 -0
- package/examples.json +30 -0
- package/lib/index.d.ts +40 -4
- package/lib/index.js +67 -1402
- package/lib/index.js.map +1 -0
- package/package.json +14 -5
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 */\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 * @return {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 */\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":";;;;;;;;;;;;;;;;;;;;;;AAqCA,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/package.json
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/observable",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.6",
|
|
4
4
|
"description": "A set of helpers in TS/JS, compatible with tree-shaking, for observable.",
|
|
5
5
|
"author": "baxyz <baxy@etik.com>",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "LGPL-3.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/helpers4/
|
|
9
|
+
"url": "git+https://github.com/helpers4/typescript.git"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
12
13
|
"main": "lib/index.js",
|
|
13
14
|
"types": "lib/index.d.ts",
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"types": "./lib/index.d.ts",
|
|
17
18
|
"import": "./lib/index.js"
|
|
18
|
-
}
|
|
19
|
+
},
|
|
20
|
+
"./examples.json": "./examples.json",
|
|
21
|
+
"./api.json": "./api.json",
|
|
22
|
+
"./package.json": "./package.json"
|
|
19
23
|
},
|
|
20
24
|
"keywords": [
|
|
21
25
|
"helpers",
|
|
@@ -27,11 +31,16 @@
|
|
|
27
31
|
"lib/index.js",
|
|
28
32
|
"lib/index.d.ts",
|
|
29
33
|
"lib/index.js.map",
|
|
34
|
+
"examples.json",
|
|
35
|
+
"api.json",
|
|
30
36
|
"LICENSE.md",
|
|
31
37
|
"package.json",
|
|
32
38
|
"README.md"
|
|
33
39
|
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=18.0.0"
|
|
42
|
+
},
|
|
34
43
|
"peerDependencies": {
|
|
35
44
|
"rxjs": "^7.8.2"
|
|
36
45
|
}
|
|
37
|
-
}
|
|
46
|
+
}
|