synstate 0.1.0 → 0.1.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/LICENSE +201 -0
- package/README.md +124 -350
- package/assets/synstate-icon.png +0 -0
- package/dist/core/combine/combine.d.mts +32 -2
- package/dist/core/combine/combine.d.mts.map +1 -1
- package/dist/core/combine/combine.mjs +32 -2
- package/dist/core/combine/combine.mjs.map +1 -1
- package/dist/core/combine/merge.d.mts +30 -4
- package/dist/core/combine/merge.d.mts.map +1 -1
- package/dist/core/combine/merge.mjs +30 -4
- package/dist/core/combine/merge.mjs.map +1 -1
- package/dist/core/combine/zip.d.mts +28 -3
- package/dist/core/combine/zip.d.mts.map +1 -1
- package/dist/core/combine/zip.mjs +28 -3
- package/dist/core/combine/zip.mjs.map +1 -1
- package/dist/core/create/from-array.d.mts +21 -3
- package/dist/core/create/from-array.d.mts.map +1 -1
- package/dist/core/create/from-array.mjs +21 -3
- package/dist/core/create/from-array.mjs.map +1 -1
- package/dist/core/create/from-promise.d.mts +29 -7
- package/dist/core/create/from-promise.d.mts.map +1 -1
- package/dist/core/create/from-promise.mjs +29 -7
- package/dist/core/create/from-promise.mjs.map +1 -1
- package/dist/core/create/from-subscribable.d.mts +58 -0
- package/dist/core/create/from-subscribable.d.mts.map +1 -1
- package/dist/core/create/from-subscribable.mjs +58 -0
- package/dist/core/create/from-subscribable.mjs.map +1 -1
- package/dist/core/create/interval.d.mts +29 -4
- package/dist/core/create/interval.d.mts.map +1 -1
- package/dist/core/create/interval.mjs +29 -4
- package/dist/core/create/interval.mjs.map +1 -1
- package/dist/core/create/of.d.mts +22 -3
- package/dist/core/create/of.d.mts.map +1 -1
- package/dist/core/create/of.mjs +22 -3
- package/dist/core/create/of.mjs.map +1 -1
- package/dist/core/create/source.d.mts +20 -1
- package/dist/core/create/source.d.mts.map +1 -1
- package/dist/core/create/source.mjs.map +1 -1
- package/dist/core/create/timer.d.mts +23 -4
- package/dist/core/create/timer.d.mts.map +1 -1
- package/dist/core/create/timer.mjs +23 -4
- package/dist/core/create/timer.mjs.map +1 -1
- package/dist/core/operators/audit-time.d.mts +59 -0
- package/dist/core/operators/audit-time.d.mts.map +1 -1
- package/dist/core/operators/audit-time.mjs +59 -0
- package/dist/core/operators/audit-time.mjs.map +1 -1
- package/dist/core/operators/debounce-time.d.mts +22 -2
- package/dist/core/operators/debounce-time.d.mts.map +1 -1
- package/dist/core/operators/debounce-time.mjs +22 -2
- package/dist/core/operators/debounce-time.mjs.map +1 -1
- package/dist/core/operators/filter.d.mts +26 -1
- package/dist/core/operators/filter.d.mts.map +1 -1
- package/dist/core/operators/filter.mjs.map +1 -1
- package/dist/core/operators/map-with-index.d.mts +19 -4
- package/dist/core/operators/map-with-index.d.mts.map +1 -1
- package/dist/core/operators/map-with-index.mjs +19 -4
- package/dist/core/operators/map-with-index.mjs.map +1 -1
- package/dist/core/operators/merge-map.d.mts +47 -5
- package/dist/core/operators/merge-map.d.mts.map +1 -1
- package/dist/core/operators/merge-map.mjs +47 -5
- package/dist/core/operators/merge-map.mjs.map +1 -1
- package/dist/core/operators/pairwise.d.mts +30 -1
- package/dist/core/operators/pairwise.d.mts.map +1 -1
- package/dist/core/operators/pairwise.mjs +30 -1
- package/dist/core/operators/pairwise.mjs.map +1 -1
- package/dist/core/operators/scan.d.mts +23 -1
- package/dist/core/operators/scan.d.mts.map +1 -1
- package/dist/core/operators/scan.mjs +23 -1
- package/dist/core/operators/scan.mjs.map +1 -1
- package/dist/core/operators/skip-if-no-change.d.mts +25 -1
- package/dist/core/operators/skip-if-no-change.d.mts.map +1 -1
- package/dist/core/operators/skip-if-no-change.mjs +25 -1
- package/dist/core/operators/skip-if-no-change.mjs.map +1 -1
- package/dist/core/operators/skip-until.d.mts +50 -0
- package/dist/core/operators/skip-until.d.mts.map +1 -1
- package/dist/core/operators/skip-until.mjs +50 -0
- package/dist/core/operators/skip-until.mjs.map +1 -1
- package/dist/core/operators/skip-while.d.mts +48 -0
- package/dist/core/operators/skip-while.d.mts.map +1 -1
- package/dist/core/operators/skip-while.mjs +48 -0
- package/dist/core/operators/skip-while.mjs.map +1 -1
- package/dist/core/operators/switch-map.d.mts +39 -5
- package/dist/core/operators/switch-map.d.mts.map +1 -1
- package/dist/core/operators/switch-map.mjs +39 -5
- package/dist/core/operators/switch-map.mjs.map +1 -1
- package/dist/core/operators/take-until.d.mts +20 -1
- package/dist/core/operators/take-until.d.mts.map +1 -1
- package/dist/core/operators/take-until.mjs +20 -1
- package/dist/core/operators/take-until.mjs.map +1 -1
- package/dist/core/operators/take-while.d.mts +47 -0
- package/dist/core/operators/take-while.d.mts.map +1 -1
- package/dist/core/operators/take-while.mjs +47 -0
- package/dist/core/operators/take-while.mjs.map +1 -1
- package/dist/core/operators/throttle-time.d.mts +44 -5
- package/dist/core/operators/throttle-time.d.mts.map +1 -1
- package/dist/core/operators/throttle-time.mjs +44 -5
- package/dist/core/operators/throttle-time.mjs.map +1 -1
- package/dist/core/operators/with-buffered-from.d.mts +53 -0
- package/dist/core/operators/with-buffered-from.d.mts.map +1 -1
- package/dist/core/operators/with-buffered-from.mjs +53 -0
- package/dist/core/operators/with-buffered-from.mjs.map +1 -1
- package/dist/core/operators/with-current-value-from.d.mts +55 -0
- package/dist/core/operators/with-current-value-from.d.mts.map +1 -1
- package/dist/core/operators/with-current-value-from.mjs +55 -0
- package/dist/core/operators/with-current-value-from.mjs.map +1 -1
- package/dist/core/operators/with-initial-value.d.mts +24 -2
- package/dist/core/operators/with-initial-value.d.mts.map +1 -1
- package/dist/core/operators/with-initial-value.mjs +24 -2
- package/dist/core/operators/with-initial-value.mjs.map +1 -1
- package/dist/core/types/observable-family.d.mts +7 -7
- package/dist/utils/create-event-emitter.d.mts +20 -2
- package/dist/utils/create-event-emitter.d.mts.map +1 -1
- package/dist/utils/create-event-emitter.mjs +20 -2
- package/dist/utils/create-event-emitter.mjs.map +1 -1
- package/dist/utils/create-reducer.d.mts +13 -1
- package/dist/utils/create-reducer.d.mts.map +1 -1
- package/dist/utils/create-reducer.mjs +13 -1
- package/dist/utils/create-reducer.mjs.map +1 -1
- package/dist/utils/create-state.d.mts +24 -4
- package/dist/utils/create-state.d.mts.map +1 -1
- package/dist/utils/create-state.mjs +24 -4
- package/dist/utils/create-state.mjs.map +1 -1
- package/package.json +13 -12
- package/src/core/combine/combine.mts +32 -2
- package/src/core/combine/merge.mts +30 -4
- package/src/core/combine/zip.mts +28 -3
- package/src/core/create/from-array.mts +21 -3
- package/src/core/create/from-promise.mts +29 -7
- package/src/core/create/from-subscribable.mts +58 -0
- package/src/core/create/interval.mts +29 -4
- package/src/core/create/of.mts +22 -3
- package/src/core/create/source.mts +20 -1
- package/src/core/create/timer.mts +23 -4
- package/src/core/operators/audit-time.mts +59 -0
- package/src/core/operators/debounce-time.mts +22 -2
- package/src/core/operators/filter.mts +26 -1
- package/src/core/operators/map-with-index.mts +19 -4
- package/src/core/operators/merge-map.mts +47 -5
- package/src/core/operators/pairwise.mts +30 -1
- package/src/core/operators/scan.mts +23 -1
- package/src/core/operators/skip-if-no-change.mts +25 -1
- package/src/core/operators/skip-until.mts +50 -0
- package/src/core/operators/skip-while.mts +48 -0
- package/src/core/operators/switch-map.mts +39 -5
- package/src/core/operators/take-until.mts +20 -1
- package/src/core/operators/take-while.mts +47 -0
- package/src/core/operators/throttle-time.mts +44 -5
- package/src/core/operators/with-buffered-from.mts +53 -0
- package/src/core/operators/with-current-value-from.mts +55 -0
- package/src/core/operators/with-initial-value.mts +24 -2
- package/src/core/types/observable-family.mts +7 -7
- package/src/utils/create-event-emitter.mts +20 -2
- package/src/utils/create-reducer.mts +13 -1
- package/src/utils/create-state.mts +24 -4
|
@@ -1,4 +1,57 @@
|
|
|
1
1
|
import { type KeepInitialValueOperator, type Observable } from '../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Buffers values from the source observable and emits them along with the parent value
|
|
4
|
+
* when the parent emits. The buffer is cleared after each emission.
|
|
5
|
+
*
|
|
6
|
+
* @template A - The type of values from the parent observable
|
|
7
|
+
* @template B - The type of values from the source observable
|
|
8
|
+
* @param observable - The observable whose values will be buffered
|
|
9
|
+
* @returns An operator that emits tuples of [parentValue, bufferedValues]
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Timeline:
|
|
14
|
+
* //
|
|
15
|
+
* // data$ d1 d2 d3 d4 d5 d6 d7 d8
|
|
16
|
+
* // trigger$ T1 T2 T3
|
|
17
|
+
* // result$ [T1,[d1,d2,d3]] [T2,[d4,d5,d6]] [T3,[d7,d8]]
|
|
18
|
+
* //
|
|
19
|
+
* // Explanation:
|
|
20
|
+
* // - withBufferedFrom collects values from the source observable
|
|
21
|
+
* // - When the trigger emits, it emits a tuple of [triggerValue, bufferedValues]
|
|
22
|
+
* // - Buffer is cleared after each emission
|
|
23
|
+
* // - Useful for batching data collection triggered by events
|
|
24
|
+
*
|
|
25
|
+
* const data$ = source<string>();
|
|
26
|
+
*
|
|
27
|
+
* const trigger$ = source<number>();
|
|
28
|
+
*
|
|
29
|
+
* const result$ = trigger$.pipe(withBufferedFrom(data$));
|
|
30
|
+
*
|
|
31
|
+
* const mut_history: (readonly [number, readonly string[]])[] = [];
|
|
32
|
+
*
|
|
33
|
+
* result$.subscribe(([triggerValue, bufferedData]) => {
|
|
34
|
+
* mut_history.push([triggerValue, bufferedData]);
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* data$.next('a');
|
|
38
|
+
*
|
|
39
|
+
* data$.next('b');
|
|
40
|
+
*
|
|
41
|
+
* trigger$.next(1);
|
|
42
|
+
*
|
|
43
|
+
* assert.deepStrictEqual(mut_history, [[1, ['a', 'b']]]);
|
|
44
|
+
*
|
|
45
|
+
* data$.next('c');
|
|
46
|
+
*
|
|
47
|
+
* trigger$.next(2);
|
|
48
|
+
*
|
|
49
|
+
* assert.deepStrictEqual(mut_history, [
|
|
50
|
+
* [1, ['a', 'b']],
|
|
51
|
+
* [2, ['c']],
|
|
52
|
+
* ]);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
2
55
|
export declare const withBufferedFrom: <A, B>(observable: Observable<B>) => KeepInitialValueOperator<A, readonly [A, readonly B[]]>;
|
|
3
56
|
export declare const withBuffered: <A, B>(observable: Observable<B>) => KeepInitialValueOperator<A, readonly [A, readonly B[]]>;
|
|
4
57
|
//# sourceMappingURL=with-buffered-from.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-buffered-from.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-buffered-from.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,CAAC,EACnC,YAAY,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,CAMQ,CAAC;AAElE,eAAO,MAAM,YAAY,GAVQ,CAAC,EAAE,CAAC,cACvB,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,CAQb,CAAC"}
|
|
1
|
+
{"version":3,"file":"with-buffered-from.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-buffered-from.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,CAAC,EACnC,YAAY,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,CAMQ,CAAC;AAElE,eAAO,MAAM,YAAY,GAVQ,CAAC,EAAE,CAAC,cACvB,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,CAQb,CAAC"}
|
|
@@ -3,6 +3,59 @@ import { SyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
|
3
3
|
import '../utils/id-maker.mjs';
|
|
4
4
|
import { maxDepth } from '../utils/max-depth.mjs';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Buffers values from the source observable and emits them along with the parent value
|
|
8
|
+
* when the parent emits. The buffer is cleared after each emission.
|
|
9
|
+
*
|
|
10
|
+
* @template A - The type of values from the parent observable
|
|
11
|
+
* @template B - The type of values from the source observable
|
|
12
|
+
* @param observable - The observable whose values will be buffered
|
|
13
|
+
* @returns An operator that emits tuples of [parentValue, bufferedValues]
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Timeline:
|
|
18
|
+
* //
|
|
19
|
+
* // data$ d1 d2 d3 d4 d5 d6 d7 d8
|
|
20
|
+
* // trigger$ T1 T2 T3
|
|
21
|
+
* // result$ [T1,[d1,d2,d3]] [T2,[d4,d5,d6]] [T3,[d7,d8]]
|
|
22
|
+
* //
|
|
23
|
+
* // Explanation:
|
|
24
|
+
* // - withBufferedFrom collects values from the source observable
|
|
25
|
+
* // - When the trigger emits, it emits a tuple of [triggerValue, bufferedValues]
|
|
26
|
+
* // - Buffer is cleared after each emission
|
|
27
|
+
* // - Useful for batching data collection triggered by events
|
|
28
|
+
*
|
|
29
|
+
* const data$ = source<string>();
|
|
30
|
+
*
|
|
31
|
+
* const trigger$ = source<number>();
|
|
32
|
+
*
|
|
33
|
+
* const result$ = trigger$.pipe(withBufferedFrom(data$));
|
|
34
|
+
*
|
|
35
|
+
* const mut_history: (readonly [number, readonly string[]])[] = [];
|
|
36
|
+
*
|
|
37
|
+
* result$.subscribe(([triggerValue, bufferedData]) => {
|
|
38
|
+
* mut_history.push([triggerValue, bufferedData]);
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* data$.next('a');
|
|
42
|
+
*
|
|
43
|
+
* data$.next('b');
|
|
44
|
+
*
|
|
45
|
+
* trigger$.next(1);
|
|
46
|
+
*
|
|
47
|
+
* assert.deepStrictEqual(mut_history, [[1, ['a', 'b']]]);
|
|
48
|
+
*
|
|
49
|
+
* data$.next('c');
|
|
50
|
+
*
|
|
51
|
+
* trigger$.next(2);
|
|
52
|
+
*
|
|
53
|
+
* assert.deepStrictEqual(mut_history, [
|
|
54
|
+
* [1, ['a', 'b']],
|
|
55
|
+
* [2, ['c']],
|
|
56
|
+
* ]);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
6
59
|
const withBufferedFrom = (observable) =>
|
|
7
60
|
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
8
61
|
((parentObservable) => new WithBufferedFromObservableClass(parentObservable, observable));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-buffered-from.mjs","sources":["../../../src/core/operators/with-buffered-from.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"with-buffered-from.mjs","sources":["../../../src/core/operators/with-buffered-from.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDG;AACI,MAAM,gBAAgB,GAAG,CAC9B,UAAyB;AAEzB;AACA,CAAC,CAAC,gBAAgB,KAChB,IAAI,+BAA+B,CACjC,gBAAgB,EAChB,UAAU,CACX;AAEE,MAAM,YAAY,GAAG,iBAAiB;AAE7C,MAAM,+BACJ,SAAQ,wBAAkE,CAAA;IAG1E,mBAAmB,GAAiB,EAAE;IAEtC,WAAA,CAAY,gBAA+B,EAAE,UAAyB,EAAA;AACpE,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;YACnD,YAAY,EAAE,IAAI,CAAC;AACjB,gBAAA,GAAG,EAAE,gBAAgB,CAAC,WAAW,EAAE;AACnC,gBAAA,EAAE,EAAE,UAAU,CAAC,WAAW,EAAE;AAC7B,aAAA,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,KACjB,QAAQ,CAAC,MAAM,CAAC,GAAG;kBACf,QAAQ,CAAC;AACX,kBAAE,QAAQ,CAAC,IAAI,CAAC;AACZ,oBAAA,GAAG,CAAC,KAAK;AACT,oBAAA,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC;iBAC7B,CAAC,CAChB,CAAC,KAAK;AACR,SAAA,CAAC;AAEF,QAAA,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,KAAI;AAC7B,YAAA,IAAI,CAAC,mBAAmB,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC;AAC1E,QAAA,CAAC,CAAC;IACJ;AAES,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;QACT;AAEA,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,mBAAmB,CAAC,EAAE,aAAa,CAAC;QAEjE,IAAI,CAAC,YAAY,EAAE;IACrB;IAEA,YAAY,GAAA;AACV,QAAA,IAAI,CAAC,mBAAmB,GAAG,EAAE;IAC/B;AACD;;;;"}
|
|
@@ -1,4 +1,59 @@
|
|
|
1
1
|
import { type DropInitialValueOperator, type Observable } from '../types/index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Samples the current value from another observable each time the source emits.
|
|
4
|
+
* Emits a tuple of [sourceValue, sampledValue].
|
|
5
|
+
*
|
|
6
|
+
* @template A - The type of values from the source observable
|
|
7
|
+
* @template B - The type of values from the sampled observable
|
|
8
|
+
* @param observable - The observable to sample from
|
|
9
|
+
* @returns An operator that emits tuples of source and sampled values
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Timeline:
|
|
14
|
+
* //
|
|
15
|
+
* // name$ "Alice" "Bob" "Charlie"
|
|
16
|
+
* // age$ 25 30 35 40
|
|
17
|
+
* // result$ ["Alice",25] ["Bob",30] ["Bob",35] ["Charlie",40]
|
|
18
|
+
* //
|
|
19
|
+
* // Explanation:
|
|
20
|
+
* // - withCurrentValueFrom samples the current value from another observable
|
|
21
|
+
* // - Emits a tuple [sourceValue, sampledValue] each time the source emits
|
|
22
|
+
* // - Does not emit until both observables have emitted at least once
|
|
23
|
+
* // - Similar to combine, but only emits when the source (not the sampled) emits
|
|
24
|
+
*
|
|
25
|
+
* const name$ = source<string>();
|
|
26
|
+
*
|
|
27
|
+
* const age$ = source<number>();
|
|
28
|
+
*
|
|
29
|
+
* const result$ = name$.pipe(withCurrentValueFrom(age$));
|
|
30
|
+
*
|
|
31
|
+
* const mut_history: (readonly [string, number])[] = [];
|
|
32
|
+
*
|
|
33
|
+
* result$.subscribe(([name_, currentAge]) => {
|
|
34
|
+
* mut_history.push([name_, currentAge]);
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* name$.next('Alice'); // nothing logged (age$ hasn't emitted)
|
|
38
|
+
*
|
|
39
|
+
* assert.deepStrictEqual(mut_history, []);
|
|
40
|
+
*
|
|
41
|
+
* age$.next(25);
|
|
42
|
+
*
|
|
43
|
+
* name$.next('Bob'); // logs: Bob is 25 years old
|
|
44
|
+
*
|
|
45
|
+
* assert.deepStrictEqual(mut_history, [['Bob', 25]]);
|
|
46
|
+
*
|
|
47
|
+
* age$.next(30);
|
|
48
|
+
*
|
|
49
|
+
* name$.next('Charlie'); // logs: Charlie is 30 years old
|
|
50
|
+
*
|
|
51
|
+
* assert.deepStrictEqual(mut_history, [
|
|
52
|
+
* ['Bob', 25],
|
|
53
|
+
* ['Charlie', 30],
|
|
54
|
+
* ]);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
2
57
|
export declare const withCurrentValueFrom: <A, B>(observable: Observable<B>) => DropInitialValueOperator<A, readonly [A, B]>;
|
|
3
58
|
export declare const withLatestFrom: <A, B>(observable: Observable<B>) => DropInitialValueOperator<A, readonly [A, B]>;
|
|
4
59
|
//# sourceMappingURL=with-current-value-from.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-current-value-from.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-current-value-from.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,oBAAoB,GAC9B,CAAC,EAAE,CAAC,EACH,YAAY,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAEyB,CAAC;AAE1E,eAAO,MAAM,cAAc,GANxB,CAAC,EAAE,CAAC,cACS,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAIE,CAAC"}
|
|
1
|
+
{"version":3,"file":"with-current-value-from.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-current-value-from.mts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EAGhB,MAAM,oBAAoB,CAAC;AAG5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,oBAAoB,GAC9B,CAAC,EAAE,CAAC,EACH,YAAY,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAEyB,CAAC;AAE1E,eAAO,MAAM,cAAc,GANxB,CAAC,EAAE,CAAC,cACS,UAAU,CAAC,CAAC,CAAC,KACxB,wBAAwB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAIE,CAAC"}
|
|
@@ -3,6 +3,61 @@ import { SyncChildObservableClass } from '../class/child-observable-class.mjs';
|
|
|
3
3
|
import '../utils/id-maker.mjs';
|
|
4
4
|
import { maxDepth } from '../utils/max-depth.mjs';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Samples the current value from another observable each time the source emits.
|
|
8
|
+
* Emits a tuple of [sourceValue, sampledValue].
|
|
9
|
+
*
|
|
10
|
+
* @template A - The type of values from the source observable
|
|
11
|
+
* @template B - The type of values from the sampled observable
|
|
12
|
+
* @param observable - The observable to sample from
|
|
13
|
+
* @returns An operator that emits tuples of source and sampled values
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Timeline:
|
|
18
|
+
* //
|
|
19
|
+
* // name$ "Alice" "Bob" "Charlie"
|
|
20
|
+
* // age$ 25 30 35 40
|
|
21
|
+
* // result$ ["Alice",25] ["Bob",30] ["Bob",35] ["Charlie",40]
|
|
22
|
+
* //
|
|
23
|
+
* // Explanation:
|
|
24
|
+
* // - withCurrentValueFrom samples the current value from another observable
|
|
25
|
+
* // - Emits a tuple [sourceValue, sampledValue] each time the source emits
|
|
26
|
+
* // - Does not emit until both observables have emitted at least once
|
|
27
|
+
* // - Similar to combine, but only emits when the source (not the sampled) emits
|
|
28
|
+
*
|
|
29
|
+
* const name$ = source<string>();
|
|
30
|
+
*
|
|
31
|
+
* const age$ = source<number>();
|
|
32
|
+
*
|
|
33
|
+
* const result$ = name$.pipe(withCurrentValueFrom(age$));
|
|
34
|
+
*
|
|
35
|
+
* const mut_history: (readonly [string, number])[] = [];
|
|
36
|
+
*
|
|
37
|
+
* result$.subscribe(([name_, currentAge]) => {
|
|
38
|
+
* mut_history.push([name_, currentAge]);
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* name$.next('Alice'); // nothing logged (age$ hasn't emitted)
|
|
42
|
+
*
|
|
43
|
+
* assert.deepStrictEqual(mut_history, []);
|
|
44
|
+
*
|
|
45
|
+
* age$.next(25);
|
|
46
|
+
*
|
|
47
|
+
* name$.next('Bob'); // logs: Bob is 25 years old
|
|
48
|
+
*
|
|
49
|
+
* assert.deepStrictEqual(mut_history, [['Bob', 25]]);
|
|
50
|
+
*
|
|
51
|
+
* age$.next(30);
|
|
52
|
+
*
|
|
53
|
+
* name$.next('Charlie'); // logs: Charlie is 30 years old
|
|
54
|
+
*
|
|
55
|
+
* assert.deepStrictEqual(mut_history, [
|
|
56
|
+
* ['Bob', 25],
|
|
57
|
+
* ['Charlie', 30],
|
|
58
|
+
* ]);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
6
61
|
const withCurrentValueFrom = (observable) => (parentObservable) => new WithCurrentValueFromObservableClass(parentObservable, observable);
|
|
7
62
|
const withLatestFrom = withCurrentValueFrom; // alias
|
|
8
63
|
class WithCurrentValueFromObservableClass extends SyncChildObservableClass {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-current-value-from.mjs","sources":["../../../src/core/operators/with-current-value-from.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"with-current-value-from.mjs","sources":["../../../src/core/operators/with-current-value-from.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDG;MACU,oBAAoB,GAC/B,CACE,UAAyB,KAE3B,CAAC,gBAAgB,KACf,IAAI,mCAAmC,CAAC,gBAAgB,EAAE,UAAU;AAEjE,MAAM,cAAc,GAAG,qBAAqB;AAEnD,MAAM,mCACJ,SAAQ,wBAAuD,CAAA;AAGtD,IAAA,WAAW;IAEpB,WAAA,CAAY,gBAA+B,EAAE,UAAyB,EAAA;AACpE,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;YAC3B,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;YACnD,YAAY,EAAE,IAAI,CAAC;AACjB,gBAAA,GAAG,EAAE,gBAAgB,CAAC,WAAW,EAAE;AACnC,gBAAA,EAAE,EAAE,UAAU,CAAC,WAAW,EAAE;aAC7B,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,KACjB,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE;kBACtC,QAAQ,CAAC;AACX,kBAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAU,CAAC,CAClD,CAAC,KAAK;AACR,SAAA,CAAC;AAEF,QAAA,IAAI,CAAC,WAAW,GAAG,UAAU;IAC/B;AAES,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;QACT;QAEA,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE;AAE3C,QAAA,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;AAAE,YAAA,OAAO;AAElC,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IACrD;AACD;;;;"}
|
|
@@ -11,15 +11,37 @@ import { type WithInitialValueOperator } from '../types/index.mjs';
|
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
14
|
+
* // Timeline:
|
|
15
|
+
* //
|
|
16
|
+
* // num$ 1 2 3
|
|
17
|
+
* // withInitial$ 0 1 2 3
|
|
18
|
+
* // ^
|
|
19
|
+
* // initial value
|
|
20
|
+
* //
|
|
21
|
+
* // Explanation:
|
|
22
|
+
* // - withInitialValue provides an initial value before the source emits
|
|
23
|
+
* // - Converts an uninitialized observable to an initialized one
|
|
24
|
+
* // - Useful when you need a default value immediately
|
|
25
|
+
*
|
|
14
26
|
* const num$ = source<number>();
|
|
15
27
|
*
|
|
16
28
|
* const initialized$ = num$.pipe(withInitialValue(0));
|
|
17
29
|
*
|
|
30
|
+
* const mut_history: number[] = [];
|
|
31
|
+
*
|
|
18
32
|
* initialized$.subscribe((x) => {
|
|
19
|
-
*
|
|
20
|
-
* });
|
|
33
|
+
* mut_history.push(x);
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* assert.deepStrictEqual(mut_history, [0]);
|
|
21
37
|
*
|
|
22
38
|
* num$.next(1); // logs: 1
|
|
39
|
+
*
|
|
40
|
+
* assert.deepStrictEqual(mut_history, [0, 1]);
|
|
41
|
+
*
|
|
42
|
+
* num$.next(2); // logs: 2
|
|
43
|
+
*
|
|
44
|
+
* assert.deepStrictEqual(mut_history, [0, 1, 2]);
|
|
23
45
|
* ```
|
|
24
46
|
*/
|
|
25
47
|
export declare const withInitialValue: <A, I = A>(initialValue: I) => WithInitialValueOperator<A, A | I>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-initial-value.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-initial-value.mts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,wBAAwB,EAE9B,MAAM,oBAAoB,CAAC;AAE5B
|
|
1
|
+
{"version":3,"file":"with-initial-value.d.mts","sourceRoot":"","sources":["../../../src/core/operators/with-initial-value.mts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,wBAAwB,EAE9B,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,gBAAgB,GAC1B,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC,KAAG,wBAAwB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAEO,CAAC"}
|
|
@@ -14,15 +14,37 @@ import '../utils/id-maker.mjs';
|
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
|
+
* // Timeline:
|
|
18
|
+
* //
|
|
19
|
+
* // num$ 1 2 3
|
|
20
|
+
* // withInitial$ 0 1 2 3
|
|
21
|
+
* // ^
|
|
22
|
+
* // initial value
|
|
23
|
+
* //
|
|
24
|
+
* // Explanation:
|
|
25
|
+
* // - withInitialValue provides an initial value before the source emits
|
|
26
|
+
* // - Converts an uninitialized observable to an initialized one
|
|
27
|
+
* // - Useful when you need a default value immediately
|
|
28
|
+
*
|
|
17
29
|
* const num$ = source<number>();
|
|
18
30
|
*
|
|
19
31
|
* const initialized$ = num$.pipe(withInitialValue(0));
|
|
20
32
|
*
|
|
33
|
+
* const mut_history: number[] = [];
|
|
34
|
+
*
|
|
21
35
|
* initialized$.subscribe((x) => {
|
|
22
|
-
*
|
|
23
|
-
* });
|
|
36
|
+
* mut_history.push(x);
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* assert.deepStrictEqual(mut_history, [0]);
|
|
24
40
|
*
|
|
25
41
|
* num$.next(1); // logs: 1
|
|
42
|
+
*
|
|
43
|
+
* assert.deepStrictEqual(mut_history, [0, 1]);
|
|
44
|
+
*
|
|
45
|
+
* num$.next(2); // logs: 2
|
|
46
|
+
*
|
|
47
|
+
* assert.deepStrictEqual(mut_history, [0, 1, 2]);
|
|
26
48
|
* ```
|
|
27
49
|
*/
|
|
28
50
|
const withInitialValue = (initialValue) => (parentObservable) => new WithInitialValueObservableClass(parentObservable, initialValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-initial-value.mjs","sources":["../../../src/core/operators/with-initial-value.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAWA
|
|
1
|
+
{"version":3,"file":"with-initial-value.mjs","sources":["../../../src/core/operators/with-initial-value.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CG;AACI,MAAM,gBAAgB,GAC3B,CAAW,YAAe,KAC1B,CAAC,gBAAgB,KACf,IAAI,+BAA+B,CAAC,gBAAgB,EAAE,YAAY;AAEtE,MAAM,+BACJ,SAAQ,mCAAwD,CAAA;IAGhE,WAAA,CAAY,gBAA+B,EAAE,YAAe,EAAA;AAC1D,QAAA,KAAK,CAAC;YACJ,OAAO,EAAE,CAAC,gBAAgB,CAAC;AAC3B,YAAA,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC;AAC1C,SAAA,CAAC;;AAGK,IAAA,SAAS,CAAC,aAA4B,EAAA;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAE3B,QAAA,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,EAAE;AAE5B,QAAA,IAAI,GAAG,CAAC,aAAa,KAAK,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;AAC9D,YAAA,OAAO;;QAGT,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC;;AAExC;;;;"}
|
|
@@ -22,7 +22,7 @@ export type TimerObservable = Readonly<{
|
|
|
22
22
|
}> & RootObservable<0>;
|
|
23
23
|
export type WithInitialValueOperatorObservable<A, I = A> = InitializedSyncChildObservable<A | I, readonly [A]>;
|
|
24
24
|
export type ScanOperatorObservable<A, B> = InitializedSyncChildObservable<B, readonly [A]>;
|
|
25
|
-
declare namespace
|
|
25
|
+
declare namespace SynStateInternals {
|
|
26
26
|
type Cast<A> = A extends NonEmptyUnknownList ? A : never;
|
|
27
27
|
type EveryInitialized<OS extends NonEmptyArray<Observable<unknown>>> = OS extends NonEmptyArray<InitializedObservable<unknown>> ? true : false;
|
|
28
28
|
type IsInitialized<O> = readonly [O] extends readonly [
|
|
@@ -43,12 +43,12 @@ declare namespace SyncFlowInternals {
|
|
|
43
43
|
export type MergeObservableRefinedImpl<OS extends NonEmptyArray<Observable<unknown>>> = SomeInitialized<OS> extends true ? InitializedMergeObservableImpl<Cast<Unwrap<OS>>> : MergeObservableImpl<Unwrap<OS>>;
|
|
44
44
|
export {};
|
|
45
45
|
}
|
|
46
|
-
export type CombineObservable<A extends NonEmptyUnknownList> =
|
|
47
|
-
export type CombineObservableRefined<OS extends NonEmptyArray<Observable<unknown>>> =
|
|
48
|
-
export type ZipObservable<A extends NonEmptyUnknownList> =
|
|
49
|
-
export type ZipObservableRefined<OS extends NonEmptyArray<Observable<unknown>>> =
|
|
50
|
-
export type MergeObservable<A extends NonEmptyUnknownList> =
|
|
51
|
-
export type MergeObservableRefined<OS extends NonEmptyArray<Observable<unknown>>> =
|
|
46
|
+
export type CombineObservable<A extends NonEmptyUnknownList> = SynStateInternals.CombineObservableImpl<A>;
|
|
47
|
+
export type CombineObservableRefined<OS extends NonEmptyArray<Observable<unknown>>> = SynStateInternals.CombineObservableRefinedImpl<OS>;
|
|
48
|
+
export type ZipObservable<A extends NonEmptyUnknownList> = SynStateInternals.ZipObservableImpl<A>;
|
|
49
|
+
export type ZipObservableRefined<OS extends NonEmptyArray<Observable<unknown>>> = SynStateInternals.ZipObservableRefinedImpl<OS>;
|
|
50
|
+
export type MergeObservable<A extends NonEmptyUnknownList> = SynStateInternals.MergeObservableImpl<A>;
|
|
51
|
+
export type MergeObservableRefined<OS extends NonEmptyArray<Observable<unknown>>> = SynStateInternals.MergeObservableRefinedImpl<OS>;
|
|
52
52
|
export type MapWithIndexOperatorObservable<A, B> = SyncChildObservable<B, readonly [A]>;
|
|
53
53
|
export type PairwiseOperatorObservable<A> = SyncChildObservable<readonly [A, A], readonly [A]>;
|
|
54
54
|
export type TakeWhileOperatorObservable<A> = SyncChildObservable<A, readonly [A]>;
|
|
@@ -9,11 +9,21 @@ import { type Observable } from '../core/index.mjs';
|
|
|
9
9
|
* ```ts
|
|
10
10
|
* const [click$, emitClick] = createEventEmitter();
|
|
11
11
|
*
|
|
12
|
+
* const mut_clickCount = { value: 0 };
|
|
13
|
+
*
|
|
12
14
|
* click$.subscribe(() => {
|
|
13
|
-
*
|
|
15
|
+
* mut_clickCount.value += 1;
|
|
14
16
|
* });
|
|
15
17
|
*
|
|
16
18
|
* emitClick(); // logs: Clicked!
|
|
19
|
+
*
|
|
20
|
+
* assert.deepStrictEqual(mut_clickCount.value, 1);
|
|
21
|
+
*
|
|
22
|
+
* emitClick();
|
|
23
|
+
*
|
|
24
|
+
* emitClick();
|
|
25
|
+
*
|
|
26
|
+
* assert.deepStrictEqual(mut_clickCount.value, 3);
|
|
17
27
|
* ```
|
|
18
28
|
*/
|
|
19
29
|
export declare const createEventEmitter: () => readonly [Observable<void>, () => void];
|
|
@@ -28,11 +38,19 @@ export declare const createEventEmitter: () => readonly [Observable<void>, () =>
|
|
|
28
38
|
* ```ts
|
|
29
39
|
* const [message$, emitMessage] = createValueEmitter<string>();
|
|
30
40
|
*
|
|
41
|
+
* const mut_history: string[] = [];
|
|
42
|
+
*
|
|
31
43
|
* message$.subscribe((msg) => {
|
|
32
|
-
*
|
|
44
|
+
* mut_history.push(msg);
|
|
33
45
|
* });
|
|
34
46
|
*
|
|
35
47
|
* emitMessage('Hello'); // logs: Hello
|
|
48
|
+
*
|
|
49
|
+
* assert.deepStrictEqual(mut_history, ['Hello']);
|
|
50
|
+
*
|
|
51
|
+
* emitMessage('World');
|
|
52
|
+
*
|
|
53
|
+
* assert.deepStrictEqual(mut_history, ['Hello', 'World']);
|
|
36
54
|
* ```
|
|
37
55
|
*/
|
|
38
56
|
export declare const createValueEmitter: <A>() => readonly [Observable<A>, (value: A) => void];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-event-emitter.d.mts","sourceRoot":"","sources":["../../src/utils/create-event-emitter.mts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE5D
|
|
1
|
+
{"version":3,"file":"create-event-emitter.d.mts","sourceRoot":"","sources":["../../src/utils/create-event-emitter.mts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,kBAAkB,QAAO,SAAS,CAC7C,UAAU,CAAC,IAAI,CAAC,EAChB,MAAM,IAAI,CASX,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,OAAM,SAAS,CACjD,UAAU,CAAC,CAAC,CAAC,EACb,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CASnB,CAAC"}
|
|
@@ -13,11 +13,21 @@ import { source } from '../core/create/source.mjs';
|
|
|
13
13
|
* ```ts
|
|
14
14
|
* const [click$, emitClick] = createEventEmitter();
|
|
15
15
|
*
|
|
16
|
+
* const mut_clickCount = { value: 0 };
|
|
17
|
+
*
|
|
16
18
|
* click$.subscribe(() => {
|
|
17
|
-
*
|
|
19
|
+
* mut_clickCount.value += 1;
|
|
18
20
|
* });
|
|
19
21
|
*
|
|
20
22
|
* emitClick(); // logs: Clicked!
|
|
23
|
+
*
|
|
24
|
+
* assert.deepStrictEqual(mut_clickCount.value, 1);
|
|
25
|
+
*
|
|
26
|
+
* emitClick();
|
|
27
|
+
*
|
|
28
|
+
* emitClick();
|
|
29
|
+
*
|
|
30
|
+
* assert.deepStrictEqual(mut_clickCount.value, 3);
|
|
21
31
|
* ```
|
|
22
32
|
*/
|
|
23
33
|
const createEventEmitter = () => {
|
|
@@ -38,11 +48,19 @@ const createEventEmitter = () => {
|
|
|
38
48
|
* ```ts
|
|
39
49
|
* const [message$, emitMessage] = createValueEmitter<string>();
|
|
40
50
|
*
|
|
51
|
+
* const mut_history: string[] = [];
|
|
52
|
+
*
|
|
41
53
|
* message$.subscribe((msg) => {
|
|
42
|
-
*
|
|
54
|
+
* mut_history.push(msg);
|
|
43
55
|
* });
|
|
44
56
|
*
|
|
45
57
|
* emitMessage('Hello'); // logs: Hello
|
|
58
|
+
*
|
|
59
|
+
* assert.deepStrictEqual(mut_history, ['Hello']);
|
|
60
|
+
*
|
|
61
|
+
* emitMessage('World');
|
|
62
|
+
*
|
|
63
|
+
* assert.deepStrictEqual(mut_history, ['Hello', 'World']);
|
|
46
64
|
* ```
|
|
47
65
|
*/
|
|
48
66
|
const createValueEmitter = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-event-emitter.mjs","sources":["../../src/utils/create-event-emitter.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAEA
|
|
1
|
+
{"version":3,"file":"create-event-emitter.mjs","sources":["../../src/utils/create-event-emitter.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;AACI,MAAM,kBAAkB,GAAG,MAG9B;AACF,IAAA,MAAM,IAAI,GAAG,MAAM,EAAa;IAEhC,MAAM,OAAO,GAAG,MAAW;AACzB,QAAA,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;AACtB,IAAA,CAAC;AAED,IAAA,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;AACxB;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;AACI,MAAM,kBAAkB,GAAG,MAG9B;AACF,IAAA,MAAM,IAAI,GAAG,MAAM,EAAK;AAExB,IAAA,MAAM,OAAO,GAAG,CAAC,KAAQ,KAAU;AACjC,QAAA,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;AAClB,IAAA,CAAC;AAED,IAAA,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;AACxB;;;;"}
|
|
@@ -23,11 +23,23 @@ import { type InitializedObservable } from '../core/index.mjs';
|
|
|
23
23
|
* 0,
|
|
24
24
|
* );
|
|
25
25
|
*
|
|
26
|
+
* const mut_history: number[] = [];
|
|
27
|
+
*
|
|
26
28
|
* state.subscribe((value: number) => {
|
|
27
|
-
*
|
|
29
|
+
* mut_history.push(value);
|
|
28
30
|
* });
|
|
29
31
|
*
|
|
32
|
+
* assert.deepStrictEqual(mut_history, [0]);
|
|
33
|
+
*
|
|
30
34
|
* dispatch({ type: 'increment' }); // logs: 1
|
|
35
|
+
*
|
|
36
|
+
* assert.deepStrictEqual(mut_history, [0, 1]);
|
|
37
|
+
*
|
|
38
|
+
* dispatch({ type: 'increment' });
|
|
39
|
+
*
|
|
40
|
+
* dispatch({ type: 'decrement' });
|
|
41
|
+
*
|
|
42
|
+
* assert.deepStrictEqual(mut_history, [0, 1, 2, 1]);
|
|
31
43
|
* ```
|
|
32
44
|
*/
|
|
33
45
|
export declare const createReducer: <S, A>(reducer: Reducer<S, A>, initialState: S) => readonly [state: InitializedObservable<S>, dispatch: (action: A) => S, getSnapshot: () => S];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-reducer.d.mts","sourceRoot":"","sources":["../../src/utils/create-reducer.mts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAEvE
|
|
1
|
+
{"version":3,"file":"create-reducer.d.mts","sourceRoot":"","sources":["../../src/utils/create-reducer.mts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,CAAC,EAChC,SAAS,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EACtB,cAAc,CAAC,KACd,SAAS,CACV,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAC/B,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,EAC1B,WAAW,EAAE,MAAM,CAAC,CAerB,CAAC"}
|
|
@@ -27,11 +27,23 @@ import { source } from '../core/create/source.mjs';
|
|
|
27
27
|
* 0,
|
|
28
28
|
* );
|
|
29
29
|
*
|
|
30
|
+
* const mut_history: number[] = [];
|
|
31
|
+
*
|
|
30
32
|
* state.subscribe((value: number) => {
|
|
31
|
-
*
|
|
33
|
+
* mut_history.push(value);
|
|
32
34
|
* });
|
|
33
35
|
*
|
|
36
|
+
* assert.deepStrictEqual(mut_history, [0]);
|
|
37
|
+
*
|
|
34
38
|
* dispatch({ type: 'increment' }); // logs: 1
|
|
39
|
+
*
|
|
40
|
+
* assert.deepStrictEqual(mut_history, [0, 1]);
|
|
41
|
+
*
|
|
42
|
+
* dispatch({ type: 'increment' });
|
|
43
|
+
*
|
|
44
|
+
* dispatch({ type: 'decrement' });
|
|
45
|
+
*
|
|
46
|
+
* assert.deepStrictEqual(mut_history, [0, 1, 2, 1]);
|
|
35
47
|
* ```
|
|
36
48
|
*/
|
|
37
49
|
const createReducer = (reducer, initialState) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-reducer.mjs","sources":["../../src/utils/create-reducer.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAEA
|
|
1
|
+
{"version":3,"file":"create-reducer.mjs","sources":["../../src/utils/create-reducer.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CG;MACU,aAAa,GAAG,CAC3B,OAAsB,EACtB,YAAe,KAKb;AACF,IAAA,MAAM,KAAK,GAAG,MAAM,CAAI,YAAY,CAAC;AAErC,IAAA,MAAM,QAAQ,GAAG,CAAC,MAAS,KAAO;AAChC,QAAA,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;AAE5D,QAAA,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;AAErB,QAAA,OAAO,SAAS;AAClB,IAAA,CAAC;IAED,MAAM,WAAW,GAAG,MAAS,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK;AAEtD,IAAA,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAU;AAChD;;;;"}
|
|
@@ -11,15 +11,25 @@ import { type InitializedObservable } from '../core/index.mjs';
|
|
|
11
11
|
* ```ts
|
|
12
12
|
* const [state, setState, { updateState, resetState }] = createState(0);
|
|
13
13
|
*
|
|
14
|
+
* const mut_history: number[] = [];
|
|
15
|
+
*
|
|
14
16
|
* state.subscribe((value: number) => {
|
|
15
|
-
*
|
|
16
|
-
* });
|
|
17
|
+
* mut_history.push(value);
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* assert.deepStrictEqual(mut_history, [0]);
|
|
17
21
|
*
|
|
18
22
|
* setState(10); // logs: 10
|
|
19
23
|
*
|
|
24
|
+
* assert.deepStrictEqual(mut_history, [0, 10]);
|
|
25
|
+
*
|
|
20
26
|
* updateState((prev: number) => prev + 1); // logs: 11
|
|
21
27
|
*
|
|
28
|
+
* assert.deepStrictEqual(mut_history, [0, 10, 11]);
|
|
29
|
+
*
|
|
22
30
|
* resetState(); // logs: 0
|
|
31
|
+
*
|
|
32
|
+
* assert.deepStrictEqual(mut_history, [0, 10, 11, 0]);
|
|
23
33
|
* ```
|
|
24
34
|
*/
|
|
25
35
|
export declare const createState: <S>(initialState: S) => readonly [state: InitializedObservable<S>, setState: (v: S) => S, Readonly<{
|
|
@@ -38,15 +48,25 @@ export declare const createState: <S>(initialState: S) => readonly [state: Initi
|
|
|
38
48
|
* ```ts
|
|
39
49
|
* const [state, { setTrue, toggle }] = createBooleanState(false);
|
|
40
50
|
*
|
|
51
|
+
* const mut_history: boolean[] = [];
|
|
52
|
+
*
|
|
41
53
|
* state.subscribe((value: boolean) => {
|
|
42
|
-
*
|
|
43
|
-
* });
|
|
54
|
+
* mut_history.push(value);
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* assert.deepStrictEqual(mut_history, [false]);
|
|
44
58
|
*
|
|
45
59
|
* setTrue(); // logs: true
|
|
46
60
|
*
|
|
61
|
+
* assert.deepStrictEqual(mut_history, [false, true]);
|
|
62
|
+
*
|
|
47
63
|
* toggle(); // logs: false
|
|
48
64
|
*
|
|
65
|
+
* assert.deepStrictEqual(mut_history, [false, true, false]);
|
|
66
|
+
*
|
|
49
67
|
* toggle(); // logs: true
|
|
68
|
+
*
|
|
69
|
+
* assert.deepStrictEqual(mut_history, [false, true, false, true]);
|
|
50
70
|
* ```
|
|
51
71
|
*/
|
|
52
72
|
export declare const createBooleanState: (initialState: boolean) => readonly [state: InitializedObservable<boolean>, Readonly<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-state.d.mts","sourceRoot":"","sources":["../../src/utils/create-state.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAwB/D
|
|
1
|
+
{"version":3,"file":"create-state.d.mts","sourceRoot":"","sources":["../../src/utils/create-state.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAwB/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAC3B,cAAc,CAAC,KACd,SAAS,CACV,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAC/B,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EACrB,QAAQ,CAAC;IACP,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7C,UAAU,EAAE,MAAM,CAAC,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,CAAC;CACtB,CAAC,CAwBH,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,kBAAkB,GAC7B,cAAc,OAAO,KACpB,SAAS,CACV,KAAK,EAAE,qBAAqB,CAAC,OAAO,CAAC,EACrC,QAAQ,CAAC;IACP,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;IACrC,MAAM,EAAE,MAAM,OAAO,CAAC;IACtB,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,KAAK,OAAO,CAAC;IAC/D,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B,WAAW,EAAE,MAAM,OAAO,CAAC;CAC5B,CAAC,CAqBH,CAAC"}
|