@jscutlery/operators 0.2.2 → 1.0.1

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,7 +2,11 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
- ## [0.2.2](https://github.com/jscutlery/devkit/compare/operators-0.2.1...operators-0.2.2) (2023-01-16)
5
+ ## [1.0.1](https://github.com/jscutlery/devkit/compare/operators-1.0.0...operators-1.0.1) (2023-04-18)
6
+
7
+
8
+
9
+ # [1.0.0](https://github.com/jscutlery/devkit/compare/operators-0.2.1...operators-1.0.0) (2023-04-18)
6
10
 
7
11
 
8
12
  ### Bug Fixes
@@ -10,6 +14,16 @@ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/s
10
14
  * **operators:** 🏷️ fix typing errors ([91c084c](https://github.com/jscutlery/devkit/commit/91c084c29c6ad760376c10bc17004a2bfcd3a306))
11
15
 
12
16
 
17
+ ### Features
18
+
19
+ * **operators:** ✨ drop support for suspensify's projector ([f4bf6dc](https://github.com/jscutlery/devkit/commit/f4bf6dc413e866b5c047578162c1c1cbcb3c73f9)), closes [#236](https://github.com/jscutlery/devkit/issues/236)
20
+
21
+
22
+ ### BREAKING CHANGES
23
+
24
+ * **operators:** suspensify's operator "projector" function is not supported anymore
25
+
26
+
13
27
 
14
28
  ## [0.2.1](https://github.com/jscutlery/devkit/compare/operators-0.2.0...operators-0.2.1) (2022-12-26)
15
29
 
package/index.cjs CHANGED
@@ -1076,9 +1076,11 @@ $({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign },
1076
1076
  assign: assign
1077
1077
  });
1078
1078
 
1079
- function suspensify(projector) {
1079
+ function suspensify(
1080
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1081
+ options) {
1080
1082
  return source$ => {
1081
- return source$.pipe(_suspensify(projector), _coalesceFirstEmittedValue());
1083
+ return source$.pipe(_suspensify(), _coalesceFirstEmittedValue());
1082
1084
  };
1083
1085
  }
1084
1086
  function _coalesceFirstEmittedValue() {
@@ -1094,7 +1096,7 @@ function _coalesceFirstEmittedValue() {
1094
1096
  });
1095
1097
  };
1096
1098
  }
1097
- function _suspensify(projector) {
1099
+ function _suspensify() {
1098
1100
  return source$ => {
1099
1101
  const initialState = {
1100
1102
  value: undefined,
@@ -1102,7 +1104,7 @@ function _suspensify(projector) {
1102
1104
  finalized: false,
1103
1105
  pending: true
1104
1106
  };
1105
- const result$ = source$.pipe(operators.materialize(), operators.scan((state = initialState, notification) => {
1107
+ return source$.pipe(operators.materialize(), operators.scan((state = initialState, notification) => {
1106
1108
  /* On complete, merge `finalized: true & pending: false`
1107
1109
  * with the current state. */
1108
1110
  if (notification.kind === 'C') {
@@ -1120,7 +1122,6 @@ function _suspensify(projector) {
1120
1122
  pending: false
1121
1123
  };
1122
1124
  }, initialState), operators.startWith(initialState));
1123
- return projector != null ? result$.pipe(operators.map(projector)) : result$;
1124
1125
  };
1125
1126
  }
1126
1127
 
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Observable, ReplaySubject } from 'rxjs';
2
- import { debounce, materialize, scan, startWith, map } from 'rxjs/operators';
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,11 @@ $({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign },
1072
1072
  assign: assign
1073
1073
  });
1074
1074
 
1075
- function suspensify(projector) {
1075
+ function suspensify(
1076
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1077
+ options) {
1076
1078
  return source$ => {
1077
- return source$.pipe(_suspensify(projector), _coalesceFirstEmittedValue());
1079
+ return source$.pipe(_suspensify(), _coalesceFirstEmittedValue());
1078
1080
  };
1079
1081
  }
1080
1082
  function _coalesceFirstEmittedValue() {
@@ -1090,7 +1092,7 @@ function _coalesceFirstEmittedValue() {
1090
1092
  });
1091
1093
  };
1092
1094
  }
1093
- function _suspensify(projector) {
1095
+ function _suspensify() {
1094
1096
  return source$ => {
1095
1097
  const initialState = {
1096
1098
  value: undefined,
@@ -1098,7 +1100,7 @@ function _suspensify(projector) {
1098
1100
  finalized: false,
1099
1101
  pending: true
1100
1102
  };
1101
- const result$ = source$.pipe(materialize(), scan((state = initialState, notification) => {
1103
+ return source$.pipe(materialize(), scan((state = initialState, notification) => {
1102
1104
  /* On complete, merge `finalized: true & pending: false`
1103
1105
  * with the current state. */
1104
1106
  if (notification.kind === 'C') {
@@ -1116,7 +1118,6 @@ function _suspensify(projector) {
1116
1118
  pending: false
1117
1119
  };
1118
1120
  }, initialState), startWith(initialState));
1119
- return projector != null ? result$.pipe(map(projector)) : result$;
1120
1121
  };
1121
1122
  }
1122
1123
 
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@jscutlery/operators",
3
- "version": "0.2.2",
3
+ "version": "1.0.1",
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
  }
@@ -1,17 +1,51 @@
1
1
  import { OperatorFunction } from 'rxjs';
2
- export interface Suspense<T> {
2
+ export interface SuspenseLax<T> {
3
3
  value: undefined | T;
4
4
  error: undefined | any;
5
5
  finalized: boolean;
6
6
  pending: boolean;
7
7
  }
8
+ export interface SuspensePending {
9
+ finalized: false;
10
+ hasError: false;
11
+ hasValue: false;
12
+ pending: true;
13
+ }
14
+ export interface SuspenseWithValue<T> {
15
+ finalized: boolean;
16
+ hasError: false;
17
+ hasValue: true;
18
+ pending: false;
19
+ value: T;
20
+ }
21
+ export interface SuspenseWithError {
22
+ finalized: true;
23
+ hasError: true;
24
+ hasValue: false;
25
+ pending: false;
26
+ error: unknown;
27
+ }
28
+ export declare type SuspenseStrict<T> = SuspensePending | SuspenseWithValue<T> | SuspenseWithError;
29
+ /**
30
+ * @todo 3.0.0: Make `Suspense` an alias for `SuspenseStrict`.
31
+ */
32
+ export declare type Suspense<T> = SuspenseLax<T>;
33
+ export interface SuspensifyOptions {
34
+ /**
35
+ * @deprecated 🚧 Work in progress.
36
+ */
37
+ strict?: boolean;
38
+ }
8
39
  /**
9
40
  * @description creates a derivated state from the source observable.
10
41
  *
11
42
  * @example source$.pipe(suspensify())
12
43
  *
13
- * @returns Observable<Suspense<T>>
44
+ * @returns Observable<SuspenseLax<T> | SuspenseStrict<T>>
14
45
  */
15
- export declare function suspensify<T, R = Suspense<T>>(): OperatorFunction<T, R>;
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>>;
46
+ export declare function suspensify<T>(options?: {
47
+ strict: false;
48
+ }): OperatorFunction<T, SuspenseLax<T>>;
49
+ export declare function suspensify<T>(options: {
50
+ strict: true;
51
+ }): OperatorFunction<T, SuspenseStrict<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
+ };