@@ -4,11 +4,18 @@ import useConstant from 'use-constant'
4
4
5
5
import { RestrictArray } from './type'
6
6
7
- export type InputFactory < State > = ( state$ : Observable < State > ) => Observable < State > ;
8
- export type InputFactoryWithInputs < State , Inputs > = ( inputs$ : Observable < RestrictArray < Inputs > > , state$ : Observable < State > ) => Observable < State > ;
9
- export function useObservable < State > ( inputFactory : InputFactory < State > ) : State | null ;
10
- export function useObservable < State > ( inputFactory : InputFactory < State > , initialState : State ) : State ;
11
- export function useObservable < State , Inputs > ( inputFactory : InputFactoryWithInputs < State , Inputs > , initialState : State , inputs : RestrictArray < Inputs > ) : State ;
7
+ export type InputFactory < State > = ( state$ : Observable < State > ) => Observable < State >
8
+ export type InputFactoryWithInputs < State , Inputs > = (
9
+ state$ : Observable < State > ,
10
+ inputs$ : Observable < RestrictArray < Inputs > > ,
11
+ ) => Observable < State >
12
+ export function useObservable < State > ( inputFactory : InputFactory < State > ) : State | null
13
+ export function useObservable < State > ( inputFactory : InputFactory < State > , initialState : State ) : State
14
+ export function useObservable < State , Inputs > (
15
+ inputFactory : InputFactoryWithInputs < State , Inputs > ,
16
+ initialState : State ,
17
+ inputs : RestrictArray < Inputs > ,
18
+ ) : State
12
19
export function useObservable < State , Inputs extends ReadonlyArray < any > > (
13
20
inputFactory : InputFactoryWithInputs < State , Inputs > ,
14
21
initialState ?: State ,
@@ -27,11 +34,11 @@ export function useObservable<State, Inputs extends ReadonlyArray<any>>(
27
34
let output$ : BehaviorSubject < State >
28
35
if ( inputs ) {
29
36
output$ = ( inputFactory as (
30
- inputs$ : Observable < RestrictArray < Inputs > | undefined > ,
31
37
state$ : Observable < State | undefined > ,
32
- ) => Observable < State > ) ( inputs$ , state$ ) as BehaviorSubject < State >
38
+ inputs$ : Observable < RestrictArray < Inputs > | undefined > ,
39
+ ) => Observable < State > ) ( state$ , inputs$ ) as BehaviorSubject < State >
33
40
} else {
34
- output$ = ( inputFactory as unknown as ( state$ : Observable < State | undefined > ) => Observable < State > ) (
41
+ output$ = ( ( inputFactory as unknown ) as ( state$ : Observable < State | undefined > ) => Observable < State > ) (
35
42
state$ ,
36
43
) as BehaviorSubject < State >
37
44
}
0 commit comments