@@ -3,14 +3,12 @@ import { SUSPENSE } from "../SUSPENSE"
3
3
import connectFactoryObservable from "./connectFactoryObservable"
4
4
import connectObservable from "./connectObservable"
5
5
import { EMPTY_VALUE } from "../internal/empty-value"
6
- import { StateObservable } from "@josepot/rxjs-state"
6
+ import { StateObservable , DefaultedStateObservable } from "@josepot/rxjs-state"
7
7
8
8
/**
9
9
* Binds an observable to React
10
10
*
11
11
* @param {Observable<T> } observable - Source observable to be used by the hook.
12
- * @param {T } [defaultValue] - Default value that will be used if the observable
13
- * has not emitted any values.
14
12
* @returns [1, 2]
15
13
* 1. A React Hook that yields the latest emitted value of the observable
16
14
* 2. A `sharedLatest` version of the observable. It can be used for composing
@@ -23,16 +21,30 @@ import { StateObservable } from "@josepot/rxjs-state"
23
21
*/
24
22
export function bind < T > (
25
23
observable : Observable < T > ,
26
- defaultValue ?: T ,
27
24
) : [ ( ) => Exclude < T , typeof SUSPENSE > , StateObservable < T > ]
28
25
26
+ /**
27
+ * Binds an observable to React
28
+ *
29
+ * @param {Observable<T> } observable - Source observable to be used by the hook.
30
+ * @param {T } defaultValue - Default value that will be used if the observable
31
+ * has not emitted any values.
32
+ * @returns [1, 2]
33
+ * 1. A React Hook that yields the latest emitted value of the observable
34
+ * 2. A `sharedLatest` version of the observable. It can be used for composing
35
+ * other streams that depend on it. The shared subscription is closed as soon as
36
+ * there are no subscribers to that observable.
37
+ */
38
+ export function bind < T > (
39
+ observable : Observable < T > ,
40
+ defaultValue : T ,
41
+ ) : [ ( ) => Exclude < T , typeof SUSPENSE > , DefaultedStateObservable < T > ]
42
+
29
43
/**
30
44
* Binds a factory observable to React
31
45
*
32
- * @param getObservable - Factory of observables. The arguments of this function
46
+ * @param { (...args: any) => Observable<T> } getObservable - Factory of observables. The arguments of this function
33
47
* will be the ones used in the hook.
34
- * @param [defaultValue] - Function or value that will be used of the observable
35
- * has not emitted.
36
48
* @returns [1, 2]
37
49
* 1. A React Hook function with the same parameters as the factory function.
38
50
* This hook will yield the latest update from the observable returned from
@@ -48,13 +60,36 @@ export function bind<T>(
48
60
*/
49
61
export function bind < A extends unknown [ ] , O > (
50
62
getObservable : ( ...args : A ) => Observable < O > ,
51
- defaultValue ?: O | ( ( ...args : A ) => O ) ,
52
63
) : [
53
64
( ...args : A ) => Exclude < O , typeof SUSPENSE > ,
54
65
( ...args : A ) => StateObservable < O > ,
55
66
]
56
67
57
- export function bind ( observable : any , defaultValue : any ) {
68
+ /**
69
+ * Binds a factory observable to React
70
+ *
71
+ * @param {(...args: any) => Observable<T> } getObservable - Factory of observables. The arguments of this function
72
+ * will be the ones used in the hook.
73
+ * @param {T } defaultValue - Function or value that will be used of the observable
74
+ * has not emitted.
75
+ * @returns [1, 2]
76
+ * 1. A React Hook function with the same parameters as the factory function.
77
+ * This hook will yield the latest update from the observable returned from
78
+ * the factory function.
79
+ * 2. A `sharedLatest` version of the observable generated by the factory
80
+ * function that can be used for composing other streams that depend on it.
81
+ * The shared subscription is closed as soon as there are no subscribers to
82
+ * that observable.
83
+ */
84
+ export function bind < A extends unknown [ ] , O > (
85
+ getObservable : ( ...args : A ) => Observable < O > ,
86
+ defaultValue : O | ( ( ...args : A ) => O ) ,
87
+ ) : [
88
+ ( ...args : A ) => Exclude < O , typeof SUSPENSE > ,
89
+ ( ...args : A ) => DefaultedStateObservable < O > ,
90
+ ]
91
+
92
+ export function bind ( observable : any , defaultValue ?: any ) {
58
93
return (
59
94
typeof observable === "function"
60
95
? ( connectFactoryObservable as any )
0 commit comments