@@ -3,14 +3,12 @@ import { SUSPENSE } from "../SUSPENSE"
33import connectFactoryObservable from "./connectFactoryObservable"
44import connectObservable from "./connectObservable"
55import { EMPTY_VALUE } from "../internal/empty-value"
6- import { StateObservable } from "@josepot/rxjs-state"
6+ import { StateObservable , DefaultedStateObservable } from "@josepot/rxjs-state"
77
88/**
99 * Binds an observable to React
1010 *
1111 * @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.
1412 * @returns [1, 2]
1513 * 1. A React Hook that yields the latest emitted value of the observable
1614 * 2. A `sharedLatest` version of the observable. It can be used for composing
@@ -23,16 +21,30 @@ import { StateObservable } from "@josepot/rxjs-state"
2321 */
2422export function bind < T > (
2523 observable : Observable < T > ,
26- defaultValue ?: T ,
2724) : [ ( ) => Exclude < T , typeof SUSPENSE > , StateObservable < T > ]
2825
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+
2943/**
3044 * Binds a factory observable to React
3145 *
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
3347 * 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.
3648 * @returns [1, 2]
3749 * 1. A React Hook function with the same parameters as the factory function.
3850 * This hook will yield the latest update from the observable returned from
@@ -48,13 +60,36 @@ export function bind<T>(
4860 */
4961export function bind < A extends unknown [ ] , O > (
5062 getObservable : ( ...args : A ) => Observable < O > ,
51- defaultValue ?: O | ( ( ...args : A ) => O ) ,
5263) : [
5364 ( ...args : A ) => Exclude < O , typeof SUSPENSE > ,
5465 ( ...args : A ) => StateObservable < O > ,
5566]
5667
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 ) {
5893 return (
5994 typeof observable === "function"
6095 ? ( connectFactoryObservable as any )
0 commit comments