Skip to content

Commit c5883f3

Browse files
committed
doc: update readme.md
1 parent 0c8bb69 commit c5883f3

File tree

2 files changed

+13
-45
lines changed

2 files changed

+13
-45
lines changed

README.md

+12-45
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# React hooks for RxJS
22
[![CircleCI](https://circleci.com/gh/LeetCode-OpenSource/rxjs-hooks.svg?style=svg)](https://circleci.com/gh/LeetCode-OpenSource/rxjs-hooks)
33
[![codecov](https://codecov.io/gh/LeetCode-OpenSource/rxjs-hooks/branch/master/graph/badge.svg)](https://codecov.io/gh/LeetCode-OpenSource/rxjs-hooks)
4+
[![npm version](https://badge.fury.io/js/rxjs-hooks.svg)](https://badge.fury.io/js/rxjs-hooks)
45

56
- [Installation](#installation)
67
- [Demo](#quick-look)
78
- [Apis](#apis)
89
1. [useObservable](#useobservable)
910
2. [useEventCallback](#useeventcallback)
10-
11+
1112
## Installation
1213

1314
Using npm:
@@ -77,15 +78,16 @@ function App() {
7778
### `useObservable`
7879

7980
```tsx
80-
type RestrictArray<T> = T extends any[] ? T : []
81-
type InputFactory<State, Inputs = undefined> = Inputs extends undefined
82-
? (state$: Observable<State>) => Observable<State>
83-
: (state$: Observable<State>, inputs$: Observable<RestrictArray<Inputs>>) => Observable<State>
84-
85-
declare function useObservable<State>(inputFactory: InputFactory<State>): State | null
86-
declare function useObservable<State>(inputFactory: InputFactory<State>, initialState: State): State
87-
declare function useObservable<State, Inputs>(
88-
inputFactory: InputFactory<State, Inputs>,
81+
export type InputFactory<State> = (state$: Observable<State>) => Observable<State>
82+
export type InputFactoryWithInputs<State, Inputs> = (
83+
state$: Observable<State>,
84+
inputs$: Observable<RestrictArray<Inputs>>,
85+
) => Observable<State>
86+
87+
export function useObservable<State>(inputFactory: InputFactory<State>): State | null
88+
export function useObservable<State>(inputFactory: InputFactory<State>, initialState: State): State
89+
export function useObservable<State, Inputs>(
90+
inputFactory: InputFactoryWithInputs<State, Inputs>,
8991
initialState: State,
9092
inputs: RestrictArray<Inputs>,
9193
): State
@@ -185,41 +187,6 @@ ReactDOM.render(<App />, document.querySelector('#root'))
185187

186188
### `useEventCallback`
187189

188-
```tsx
189-
type RestrictArray<T> = T extends any[] ? T : []
190-
type VoidAsNull<T> = T extends void ? null : T
191-
192-
type EventCallbackState<EventValue, State, Inputs = void> = [
193-
(val: EventValue) => void,
194-
[State extends void ? null : State, BehaviorSubject<State | null>, BehaviorSubject<RestrictArray<Inputs> | null>]
195-
]
196-
type ReturnedState<EventValue, State, Inputs> = [
197-
EventCallbackState<EventValue, State, Inputs>[0],
198-
EventCallbackState<EventValue, State, Inputs>[1][0]
199-
]
200-
201-
type EventCallback<EventValue, State, Inputs> = Inputs extends void
202-
? (eventSource$: Observable<EventValue>, state$: Observable<State>) => Observable<State>
203-
: (
204-
eventSource$: Observable<EventValue>,
205-
state$: Observable<State>,
206-
inputs$: Observable<RestrictArray<Inputs>>,
207-
) => Observable<State>
208-
209-
declare function useEventCallback<EventValue, State = void>(
210-
callback: EventCallback<EventValue, State, void>,
211-
): ReturnedState<EventValue, State | null, void>
212-
declare function useEventCallback<EventValue, State = void>(
213-
callback: EventCallback<EventValue, State, void>,
214-
initialState: State,
215-
): ReturnedState<EventValue, State, void>
216-
declare function useEventCallback<EventValue, State = void, Inputs = void>(
217-
callback: EventCallback<EventValue, State, Inputs>,
218-
initialState: State,
219-
inputs: RestrictArray<Inputs>,
220-
): ReturnedState<EventValue, State, Inputs>
221-
```
222-
223190
#### Examples:
224191

225192
```tsx

src/use-observable.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type InputFactoryWithInputs<State, Inputs> = (
99
state$: Observable<State>,
1010
inputs$: Observable<RestrictArray<Inputs>>,
1111
) => Observable<State>
12+
1213
export function useObservable<State>(inputFactory: InputFactory<State>): State | null
1314
export function useObservable<State>(inputFactory: InputFactory<State>, initialState: State): State
1415
export function useObservable<State, Inputs>(

0 commit comments

Comments
 (0)