@jscutlery/operators 2.0.0 → 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 CHANGED
@@ -2,6 +2,24 @@
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
+
14
+ ## [2.0.1](https://github.com/jscutlery/devkit/compare/operators-2.0.0...operators-2.0.1) (2023-04-27)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **operators:** 🐞 fix suspensify type to be strict by default too ([c5d424c](https://github.com/jscutlery/devkit/commit/c5d424cea4faee0df5ab112851565a36fb575ebe))
20
+
21
+
22
+
5
23
  # [2.0.0](https://github.com/jscutlery/devkit/compare/operators-1.1.1...operators-2.0.0) (2023-04-18)
6
24
 
7
25
 
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
- const initialState = {
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
- }, initialState), operators.startWith(initialState));
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
- const initialState = {
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
- }, initialState), startWith(initialState));
1145
+ }, pending), startWith(pending));
1141
1146
  };
1142
1147
  }
1143
1148
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jscutlery/operators",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "repository": {
5
5
  "url": "https://github.com/jscutlery/devkit"
6
6
  },
@@ -44,9 +44,16 @@ export interface SuspensifyOptions {
44
44
  *
45
45
  * @returns Observable<SuspenseLax<T> | SuspenseStrict<T>>
46
46
  */
47
- export declare function suspensify<T>(options?: {
47
+ export declare function suspensify<T>(options: {
48
48
  strict: false;
49
49
  }): OperatorFunction<T, SuspenseLax<T>>;
50
- export declare function suspensify<T>(options: {
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;