@jscutlery/operators 0.2.2 → 1.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/CHANGELOG.md +11 -1
- package/index.cjs +11 -5
- package/index.js +12 -6
- package/package.json +5 -3
- package/src/lib/suspensify.d.ts +1 -3
- package/src/lib/testing/observer.d.ts +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# [1.0.0](https://github.com/jscutlery/devkit/compare/operators-0.2.1...operators-1.0.0) (2023-04-18)
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
### Bug Fixes
|
|
@@ -10,6 +10,16 @@ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/s
|
|
|
10
10
|
* **operators:** 🏷️ fix typing errors ([91c084c](https://github.com/jscutlery/devkit/commit/91c084c29c6ad760376c10bc17004a2bfcd3a306))
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **operators:** ✨ drop support for suspensify's projector ([f4bf6dc](https://github.com/jscutlery/devkit/commit/f4bf6dc413e866b5c047578162c1c1cbcb3c73f9)), closes [#236](https://github.com/jscutlery/devkit/issues/236)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### BREAKING CHANGES
|
|
19
|
+
|
|
20
|
+
* **operators:** suspensify's operator "projector" function is not supported anymore
|
|
21
|
+
|
|
22
|
+
|
|
13
23
|
|
|
14
24
|
## [0.2.1](https://github.com/jscutlery/devkit/compare/operators-0.2.0...operators-0.2.1) (2022-12-26)
|
|
15
25
|
|
package/index.cjs
CHANGED
|
@@ -1076,9 +1076,16 @@ $({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign },
|
|
|
1076
1076
|
assign: assign
|
|
1077
1077
|
});
|
|
1078
1078
|
|
|
1079
|
-
|
|
1079
|
+
/**
|
|
1080
|
+
* @description creates a derivated state from the source observable.
|
|
1081
|
+
*
|
|
1082
|
+
* @example source$.pipe(suspensify())
|
|
1083
|
+
*
|
|
1084
|
+
* @returns Observable<Suspense<T>>
|
|
1085
|
+
*/
|
|
1086
|
+
function suspensify() {
|
|
1080
1087
|
return source$ => {
|
|
1081
|
-
return source$.pipe(_suspensify(
|
|
1088
|
+
return source$.pipe(_suspensify(), _coalesceFirstEmittedValue());
|
|
1082
1089
|
};
|
|
1083
1090
|
}
|
|
1084
1091
|
function _coalesceFirstEmittedValue() {
|
|
@@ -1094,7 +1101,7 @@ function _coalesceFirstEmittedValue() {
|
|
|
1094
1101
|
});
|
|
1095
1102
|
};
|
|
1096
1103
|
}
|
|
1097
|
-
function _suspensify(
|
|
1104
|
+
function _suspensify() {
|
|
1098
1105
|
return source$ => {
|
|
1099
1106
|
const initialState = {
|
|
1100
1107
|
value: undefined,
|
|
@@ -1102,7 +1109,7 @@ function _suspensify(projector) {
|
|
|
1102
1109
|
finalized: false,
|
|
1103
1110
|
pending: true
|
|
1104
1111
|
};
|
|
1105
|
-
|
|
1112
|
+
return source$.pipe(operators.materialize(), operators.scan((state = initialState, notification) => {
|
|
1106
1113
|
/* On complete, merge `finalized: true & pending: false`
|
|
1107
1114
|
* with the current state. */
|
|
1108
1115
|
if (notification.kind === 'C') {
|
|
@@ -1120,7 +1127,6 @@ function _suspensify(projector) {
|
|
|
1120
1127
|
pending: false
|
|
1121
1128
|
};
|
|
1122
1129
|
}, initialState), operators.startWith(initialState));
|
|
1123
|
-
return projector != null ? result$.pipe(operators.map(projector)) : result$;
|
|
1124
1130
|
};
|
|
1125
1131
|
}
|
|
1126
1132
|
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable, ReplaySubject } from 'rxjs';
|
|
2
|
-
import { debounce, materialize, scan, startWith
|
|
2
|
+
import { debounce, materialize, scan, startWith } from 'rxjs/operators';
|
|
3
3
|
|
|
4
4
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
5
5
|
|
|
@@ -1072,9 +1072,16 @@ $({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign },
|
|
|
1072
1072
|
assign: assign
|
|
1073
1073
|
});
|
|
1074
1074
|
|
|
1075
|
-
|
|
1075
|
+
/**
|
|
1076
|
+
* @description creates a derivated state from the source observable.
|
|
1077
|
+
*
|
|
1078
|
+
* @example source$.pipe(suspensify())
|
|
1079
|
+
*
|
|
1080
|
+
* @returns Observable<Suspense<T>>
|
|
1081
|
+
*/
|
|
1082
|
+
function suspensify() {
|
|
1076
1083
|
return source$ => {
|
|
1077
|
-
return source$.pipe(_suspensify(
|
|
1084
|
+
return source$.pipe(_suspensify(), _coalesceFirstEmittedValue());
|
|
1078
1085
|
};
|
|
1079
1086
|
}
|
|
1080
1087
|
function _coalesceFirstEmittedValue() {
|
|
@@ -1090,7 +1097,7 @@ function _coalesceFirstEmittedValue() {
|
|
|
1090
1097
|
});
|
|
1091
1098
|
};
|
|
1092
1099
|
}
|
|
1093
|
-
function _suspensify(
|
|
1100
|
+
function _suspensify() {
|
|
1094
1101
|
return source$ => {
|
|
1095
1102
|
const initialState = {
|
|
1096
1103
|
value: undefined,
|
|
@@ -1098,7 +1105,7 @@ function _suspensify(projector) {
|
|
|
1098
1105
|
finalized: false,
|
|
1099
1106
|
pending: true
|
|
1100
1107
|
};
|
|
1101
|
-
|
|
1108
|
+
return source$.pipe(materialize(), scan((state = initialState, notification) => {
|
|
1102
1109
|
/* On complete, merge `finalized: true & pending: false`
|
|
1103
1110
|
* with the current state. */
|
|
1104
1111
|
if (notification.kind === 'C') {
|
|
@@ -1116,7 +1123,6 @@ function _suspensify(projector) {
|
|
|
1116
1123
|
pending: false
|
|
1117
1124
|
};
|
|
1118
1125
|
}, initialState), startWith(initialState));
|
|
1119
|
-
return projector != null ? result$.pipe(map(projector)) : result$;
|
|
1120
1126
|
};
|
|
1121
1127
|
}
|
|
1122
1128
|
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscutlery/operators",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "https://github.com/jscutlery/devkit"
|
|
6
6
|
},
|
|
7
7
|
"peerDependencies": {
|
|
8
|
-
"rxjs": ">=6.0.0"
|
|
8
|
+
"rxjs": ">=6.0.0",
|
|
9
|
+
"@jest/globals": "28.1.3"
|
|
9
10
|
},
|
|
10
11
|
"module": "./index.js",
|
|
11
12
|
"main": "./index.cjs",
|
|
12
13
|
"type": "module",
|
|
13
|
-
"types": "./src/index.d.ts"
|
|
14
|
+
"types": "./src/index.d.ts",
|
|
15
|
+
"dependencies": {}
|
|
14
16
|
}
|
package/src/lib/suspensify.d.ts
CHANGED
|
@@ -12,6 +12,4 @@ export interface Suspense<T> {
|
|
|
12
12
|
*
|
|
13
13
|
* @returns Observable<Suspense<T>>
|
|
14
14
|
*/
|
|
15
|
-
export declare function suspensify<T
|
|
16
|
-
export declare function suspensify<T, R>(projector: (data: Suspense<T>) => R): OperatorFunction<T, R>;
|
|
17
|
-
export declare function suspensify<T, R = Suspense<T>>(projector?: (data: Suspense<T>) => R): OperatorFunction<T, R | Suspense<T>>;
|
|
15
|
+
export declare function suspensify<T>(): OperatorFunction<T, Suspense<T>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
export declare function createObserver(): {
|
|
4
|
+
observe<T>(observable: Observable<T>): {
|
|
5
|
+
mockClear(): void;
|
|
6
|
+
mockReset(): void;
|
|
7
|
+
next: jest.MockInstance<void, [value: T]> & ((value: T) => void);
|
|
8
|
+
error: jest.MockInstance<void, [err: any]> & ((err: any) => void);
|
|
9
|
+
complete: jest.MockInstance<void, []> & (() => void);
|
|
10
|
+
};
|
|
11
|
+
};
|