@jscutlery/operators 0.1.7 → 0.2.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.
@@ -1,16 +1,16 @@
1
- import { OperatorFunction } from 'rxjs';
2
- export interface Suspense<T> {
3
- value: undefined | T;
4
- error: undefined | any;
5
- finalized: boolean;
6
- pending: boolean;
7
- }
8
- /**
9
- * @description creates a derivated state from the source observable.
10
- *
11
- * @example source$.pipe(suspensify())
12
- *
13
- * @returns Observable<Suspense<T>>
14
- */
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>;
1
+ import { OperatorFunction } from 'rxjs';
2
+ export interface Suspense<T> {
3
+ value: undefined | T;
4
+ error: undefined | any;
5
+ finalized: boolean;
6
+ pending: boolean;
7
+ }
8
+ /**
9
+ * @description creates a derivated state from the source observable.
10
+ *
11
+ * @example source$.pipe(suspensify())
12
+ *
13
+ * @returns Observable<Suspense<T>>
14
+ */
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>;
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@jscutlery/operators",
3
- "version": "0.1.7",
3
+ "version": "0.2.0",
4
4
  "repository": {
5
5
  "url": "https://github.com/jscutlery/devkit"
6
6
  },
7
7
  "peerDependencies": {
8
- "rxjs": ">=6.0.0",
9
- "tslib": "2.4.0"
8
+ "rxjs": ">=6.0.0"
10
9
  },
11
- "main": "./src/index.js",
12
- "typings": "./src/index.d.ts",
13
- "dependencies": {}
10
+ "module": "./index.js",
11
+ "main": "./index.cjs",
12
+ "type": "module",
13
+ "types": "./index.d.ts"
14
14
  }
package/src/index.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.suspensify = void 0;
4
- var suspensify_1 = require("./lib/suspensify");
5
- Object.defineProperty(exports, "suspensify", { enumerable: true, get: function () { return suspensify_1.suspensify; } });
6
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/operators/src/index.ts"],"names":[],"mappings":";;;AAAA,+CAAwD;AAA/C,wGAAA,UAAU,OAAA"}
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.suspensify = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- function suspensify(projector) {
7
- return (source$) => {
8
- return source$.pipe(_suspensify(projector), _coalesceFirstEmittedValue());
9
- };
10
- }
11
- exports.suspensify = suspensify;
12
- function _coalesceFirstEmittedValue() {
13
- return (source$) => {
14
- return new rxjs_1.Observable((observer) => {
15
- const isReadySubject = new rxjs_1.ReplaySubject(1);
16
- const subscription = source$
17
- .pipe(
18
- /* Wait for all synchronous processing to be done. */
19
- (0, operators_1.debounce)(() => isReadySubject))
20
- .subscribe(observer);
21
- /* Sync emitted values have been processed now.
22
- * Mark source as ready and emit last computed state. */
23
- isReadySubject.next(undefined);
24
- return () => subscription.unsubscribe();
25
- });
26
- };
27
- }
28
- function _suspensify(projector) {
29
- return (source$) => {
30
- const initialState = {
31
- value: undefined,
32
- error: undefined,
33
- finalized: false,
34
- pending: true,
35
- };
36
- const result$ = source$.pipe((0, operators_1.materialize)(), (0, operators_1.scan)((state = initialState, notification) => {
37
- /* On complete, merge `finalized: true & pending: false`
38
- * with the current state. */
39
- if (notification.kind === 'C') {
40
- return {
41
- ...state,
42
- finalized: true,
43
- pending: false,
44
- };
45
- }
46
- /* Mark as finalized on error as complete is only triggered on success. */
47
- const finalized = notification.kind === 'E';
48
- return {
49
- value: notification.value,
50
- error: notification.error,
51
- finalized,
52
- pending: false,
53
- };
54
- }, undefined), (0, operators_1.startWith)(initialState));
55
- return projector != null ? result$.pipe((0, operators_1.map)(projector)) : result$;
56
- };
57
- }
58
- //# sourceMappingURL=suspensify.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"suspensify.js","sourceRoot":"","sources":["../../../../../packages/operators/src/lib/suspensify.ts"],"names":[],"mappings":";;;AAAA,+BAKc;AACd,8CAA6E;AAqB7E,SAAgB,UAAU,CACxB,SAAoC;IAEpC,OAAO,CAAC,OAAsB,EAA+B,EAAE;QAC7D,OAAO,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,0BAA0B,EAAE,CAAC,CAAC;IAC5E,CAAC,CAAC;AACJ,CAAC;AAND,gCAMC;AAED,SAAS,0BAA0B;IACjC,OAAO,CAAC,OAAsB,EAAiB,EAAE;QAC/C,OAAO,IAAI,iBAAU,CAAI,CAAC,QAAQ,EAAE,EAAE;YACpC,MAAM,cAAc,GAAG,IAAI,oBAAa,CAAU,CAAC,CAAC,CAAC;YAErD,MAAM,YAAY,GAAG,OAAO;iBACzB,IAAI;YACH,qDAAqD;YACrD,IAAA,oBAAQ,EAAC,GAAG,EAAE,CAAC,cAAc,CAAC,CAC/B;iBACA,SAAS,CAAC,QAAQ,CAAC,CAAC;YAEvB;oEACwD;YACxD,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAE/B,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAMD,SAAS,WAAW,CAClB,SAAoC;IAEpC,OAAO,CAAC,OAAsB,EAA+B,EAAE;QAC7D,MAAM,YAAY,GAAG;YACnB,KAAK,EAAE,SAAS;YAChB,KAAK,EAAE,SAAS;YAChB,SAAS,EAAE,KAAK;YAChB,OAAO,EAAE,IAAI;SACd,CAAC;QAEF,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAC1B,IAAA,uBAAW,GAAE,EACb,IAAA,gBAA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