Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix(TypeScript type definition): Add combineEpics(), provide more acc…
- Loading branch information
Showing
2 changed files
with
31 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,17 @@ | ||
import { Middleware } from 'redux'; | ||
import { Middleware, MiddlewareAPI, Action } from 'redux'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { Operator } from 'rxjs/Operator'; | ||
|
||
export declare function createEpicMiddleware(): Middleware; | ||
|
||
// ./node_modules/rxjs/Observable.d.ts | ||
export declare class ActionsObservable<T> extends Observable<T> { | ||
export declare class ActionsObservable extends Observable<Action> { | ||
constructor(actionsSubject: Observable<Action>); | ||
lift(operator: Operator<any, Action>); | ||
ofType(...key: any[]); | ||
} | ||
|
||
// ./node_modules/rxjs/Observable.d.ts specifies an `Observable`'s `source` | ||
// property like so: `protected source: Observable<any>;` | ||
// since `actionsSubject` is being assigned to an `Observable`'s `source` | ||
// property it is being given the type: `Observable<any>` | ||
constructor(actionsSubject: Observable<any>); | ||
export declare interface Epic { | ||
(action$: ActionsObservable, store: MiddlewareAPI<any>): Observable<Action>; | ||
} | ||
|
||
// ./node_modules/rxjs/Observable.d.ts specifies operators as generics like so | ||
// `protected operator: Operator<any, T>;` | ||
lift(operator: Operator<any, T>); | ||
export declare function createEpicMiddleware(...epics: Epic[]): Middleware; | ||
|
||
// ./node_modules/redux/index.d.ts specifies `Action` as having a `type` | ||
// property with a type signature of `any` | ||
// since `key` is being compared with an `Action`'s `type`, `key` has a type | ||
// signature of `any` | ||
ofType(...key: any[]); | ||
} | ||
export declare function combineEpics(...epics: Epic[]): Epic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
import { createEpicMiddleware, ActionsObservable } from '../index'; | ||
import { createEpicMiddleware, combineEpics, ActionsObservable } from '../index'; | ||
import { Action } from 'redux'; | ||
import { Observable } from 'rxjs/Observable'; | ||
|
||
// should be a function | ||
createEpicMiddleware(); | ||
const epic1 = (action$, store) => | ||
action$.ofType('FIRST') | ||
.mapTo({ | ||
type: 'first', | ||
payload: store.getState() | ||
}); | ||
|
||
const epic2 = (action$, store) => | ||
action$.ofType('SECOND') | ||
.mapTo({ | ||
type: 'second', | ||
payload: store.getState() | ||
}); | ||
|
||
const rootEpic = combineEpics(epic1, epic2); | ||
|
||
createEpicMiddleware(rootEpic); | ||
|
||
// should be a constructor that returns an observable | ||
const actionsSubject = Observable.create(() => {}); | ||
const aoTest: Observable<string> = new ActionsObservable(actionsSubject); | ||
const aoTest: Observable<Action> = new ActionsObservable(actionsSubject); |