Skip to content

Commit 26d46a2

Browse files
committed
types: add type definition #2
1 parent 00fb323 commit 26d46a2

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

README.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,32 @@ let increment = store => {
5353
}
5454

5555
export const store = createStore([increment, createEpicMiddleware(epics)]);
56-
```
56+
```
57+
58+
Using TypeScript you can assign `Epic` interface to the function to specify `action` and `state` typing
59+
60+
#### `epic.ts`
61+
```typescript
62+
import { combineEpics, ofEvent, Epic } from 'storeon-observable';
63+
import { mapTo, delay } from 'rxjs/operators'
64+
65+
interface State {
66+
isPinging: boolean;
67+
}
68+
69+
const epic: Epic<State> = (action$, state$) => action$.pipe(
70+
ofEvent('ping'),
71+
delay(1000),
72+
mapTo('pong'),
73+
);
74+
75+
export const epics = combineEpics([epic]);
76+
```
77+
78+
## Acknowledgments
79+
80+
This module based on [redux-observable](https://github.com/redux-observable/redux-observable).
81+
82+
## LICENSE
83+
84+
[MIT](LICENCE)

index.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Store } from 'storeon';
2+
import { Observable } from 'rxjs';
3+
4+
export declare interface Epic<State = unknown> {
5+
(action$: Observable<string>, state$: Observable<State>): Observable<string>;
6+
}
7+
8+
export declare function createEpicMiddleware(rootEpic: Epic): (store: Store) => void;
9+
10+
export declare function combineEpics(epics: Epic[]): Epic;
11+
12+
export declare function ofEvent(key: string): (source: Observable<string>) => Observable<string>;

0 commit comments

Comments
 (0)