@jscutlery/operators 2.0.1 → 2.1.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 +9 -0
- package/index.cjs +14 -9
- package/index.js +14 -9
- package/package.json +1 -1
- package/src/lib/suspensify.d.ts +7 -0
- package/src/lib/testing/observer.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
# [2.1.0](https://github.com/jscutlery/devkit/compare/operators-2.0.1...operators-2.1.0) (2023-04-27)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **operators:** ✨ expose pending state constant ([caaea8e](https://github.com/jscutlery/devkit/commit/caaea8e3144aca71ecf75830777bcadd2ba23c37))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
5
14
|
## [2.0.1](https://github.com/jscutlery/devkit/compare/operators-2.0.0...operators-2.0.1) (2023-04-27)
|
|
6
15
|
|
|
7
16
|
|
package/index.cjs
CHANGED
|
@@ -1089,7 +1089,18 @@ function suspensify({
|
|
|
1089
1089
|
);
|
|
1090
1090
|
};
|
|
1091
1091
|
}
|
|
1092
|
-
|
|
1092
|
+
/**
|
|
1093
|
+
* This is the initial state of the Suspense.
|
|
1094
|
+
* It is exposed for convenience and edge cases where the initial state must be set initially.
|
|
1095
|
+
* e.g. when using {@link suspensify} on inner observables.
|
|
1096
|
+
* @example toSignal(source$.pipe(switchMap(() => fetchData().pipe(suspensify()))), {initialValue: pending});
|
|
1097
|
+
*/
|
|
1098
|
+
const pending = {
|
|
1099
|
+
finalized: false,
|
|
1100
|
+
hasError: false,
|
|
1101
|
+
hasValue: false,
|
|
1102
|
+
pending: true
|
|
1103
|
+
};
|
|
1093
1104
|
function _coalesceFirstEmittedValue() {
|
|
1094
1105
|
return source$ => {
|
|
1095
1106
|
return new rxjs.Observable(observer => {
|
|
@@ -1108,13 +1119,7 @@ const TRUE = true;
|
|
|
1108
1119
|
const FALSE = false;
|
|
1109
1120
|
function _suspensify() {
|
|
1110
1121
|
return source$ => {
|
|
1111
|
-
|
|
1112
|
-
finalized: false,
|
|
1113
|
-
hasError: false,
|
|
1114
|
-
hasValue: false,
|
|
1115
|
-
pending: true
|
|
1116
|
-
};
|
|
1117
|
-
return source$.pipe(operators.materialize(), operators.scan((state = initialState, notification) => {
|
|
1122
|
+
return source$.pipe(operators.materialize(), operators.scan((state, notification) => {
|
|
1118
1123
|
switch (notification.kind) {
|
|
1119
1124
|
/* Value. */
|
|
1120
1125
|
case 'N':
|
|
@@ -1141,7 +1146,7 @@ function _suspensify() {
|
|
|
1141
1146
|
pending: FALSE
|
|
1142
1147
|
});
|
|
1143
1148
|
}
|
|
1144
|
-
},
|
|
1149
|
+
}, pending), operators.startWith(pending));
|
|
1145
1150
|
};
|
|
1146
1151
|
}
|
|
1147
1152
|
|
package/index.js
CHANGED
|
@@ -1085,7 +1085,18 @@ function suspensify({
|
|
|
1085
1085
|
);
|
|
1086
1086
|
};
|
|
1087
1087
|
}
|
|
1088
|
-
|
|
1088
|
+
/**
|
|
1089
|
+
* This is the initial state of the Suspense.
|
|
1090
|
+
* It is exposed for convenience and edge cases where the initial state must be set initially.
|
|
1091
|
+
* e.g. when using {@link suspensify} on inner observables.
|
|
1092
|
+
* @example toSignal(source$.pipe(switchMap(() => fetchData().pipe(suspensify()))), {initialValue: pending});
|
|
1093
|
+
*/
|
|
1094
|
+
const pending = {
|
|
1095
|
+
finalized: false,
|
|
1096
|
+
hasError: false,
|
|
1097
|
+
hasValue: false,
|
|
1098
|
+
pending: true
|
|
1099
|
+
};
|
|
1089
1100
|
function _coalesceFirstEmittedValue() {
|
|
1090
1101
|
return source$ => {
|
|
1091
1102
|
return new Observable(observer => {
|
|
@@ -1104,13 +1115,7 @@ const TRUE = true;
|
|
|
1104
1115
|
const FALSE = false;
|
|
1105
1116
|
function _suspensify() {
|
|
1106
1117
|
return source$ => {
|
|
1107
|
-
|
|
1108
|
-
finalized: false,
|
|
1109
|
-
hasError: false,
|
|
1110
|
-
hasValue: false,
|
|
1111
|
-
pending: true
|
|
1112
|
-
};
|
|
1113
|
-
return source$.pipe(materialize(), scan((state = initialState, notification) => {
|
|
1118
|
+
return source$.pipe(materialize(), scan((state, notification) => {
|
|
1114
1119
|
switch (notification.kind) {
|
|
1115
1120
|
/* Value. */
|
|
1116
1121
|
case 'N':
|
|
@@ -1137,7 +1142,7 @@ function _suspensify() {
|
|
|
1137
1142
|
pending: FALSE
|
|
1138
1143
|
});
|
|
1139
1144
|
}
|
|
1140
|
-
},
|
|
1145
|
+
}, pending), startWith(pending));
|
|
1141
1146
|
};
|
|
1142
1147
|
}
|
|
1143
1148
|
|
package/package.json
CHANGED
package/src/lib/suspensify.d.ts
CHANGED
|
@@ -50,3 +50,10 @@ export declare function suspensify<T>(options: {
|
|
|
50
50
|
export declare function suspensify<T>(options?: {
|
|
51
51
|
strict: true;
|
|
52
52
|
}): OperatorFunction<T, Suspense<T>>;
|
|
53
|
+
/**
|
|
54
|
+
* This is the initial state of the Suspense.
|
|
55
|
+
* It is exposed for convenience and edge cases where the initial state must be set initially.
|
|
56
|
+
* e.g. when using {@link suspensify} on inner observables.
|
|
57
|
+
* @example toSignal(source$.pipe(switchMap(() => fetchData().pipe(suspensify()))), {initialValue: pending});
|
|
58
|
+
*/
|
|
59
|
+
export declare const pending: SuspensePending;
|