-
-
Save jayphelps/9c527880a16b1470e22c6006a584d7b3 to your computer and use it in GitHub Desktop.
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
class Middleware {} | |
class MiddlewareAPI<T> {} | |
interface Action { type: string } | |
declare class Observable<T> { | |
mapTo<T, R>(this: Observable<T>, value: R): Observable<R>; | |
} | |
class Scheduler {} | |
class Operator<T, R> {} | |
type ObservableInput<T> = Observable<T>; | |
export declare class ActionsObservable<T extends Action> extends Observable<T> { | |
/** | |
* Just like RxJS itself, we can't actually make this method always type-safe | |
* because we would need non-final position spread params e.g. | |
* `static of<T>(...items: T, scheduler?: Scheduler): ActionsObservable<T>` | |
* which isn't possible in either JavaScript or TypeScript. So instead, we | |
* provide safe typing for up to 6 items, following by a scheduler. | |
*/ | |
static of<T extends Action>(item1: T, scheduler?: Scheduler): ActionsObservable<T>; | |
static of<T extends Action>(item1: T, item2: T, scheduler?: Scheduler): ActionsObservable<T>; | |
static of<T extends Action>(item1: T, item2: T, item3: T, scheduler?: Scheduler): ActionsObservable<T>; | |
static of<T extends Action>(item1: T, item2: T, item3: T, item4: T, scheduler?: Scheduler): ActionsObservable<T>; | |
static of<T extends Action>(item1: T, item2: T, item3: T, item4: T, item5: T, scheduler?: Scheduler): ActionsObservable<T>; | |
static of<T extends Action>(item1: T, item2: T, item3: T, item4: T, item5: T, item6: T, scheduler?: Scheduler): ActionsObservable<T>; | |
static of<T extends Action>(...array: Array<T | Scheduler>): ActionsObservable<T>; | |
static from<T extends Action>(ish: ObservableInput<T>, scheduler?: Scheduler): ActionsObservable<T>; | |
static from<T extends Action, R extends Action>(ish: ArrayLike<T>, scheduler?: Scheduler): ActionsObservable<R>; | |
constructor(input$: Observable<T>); | |
lift<R extends Action>(operator: Operator<T, R>): ActionsObservable<R>; | |
lift<R>(operator: Operator<T, R>): Observable<R>; | |
ofType(...key: T['type'][]): ActionsObservable<T>; | |
ofType<R extends Action = T>(...key: R['type'][]): ActionsObservable<R>; | |
} | |
export declare interface Epic<T extends Action, S, D = any> { | |
(action$: ActionsObservable<T>, store: MiddlewareAPI<S>, dependencies: D): Observable<T>; | |
} | |
export interface EpicMiddleware<T extends Action, S, D = any> extends Middleware { | |
replaceEpic(nextEpic: Epic<T, S, D>): void; | |
} | |
interface Adapter { | |
input: (input$: Observable<any>) => any; | |
output: (output$: any) => Observable<any>; | |
} | |
interface Options<D = any> { | |
adapter?: Adapter; | |
dependencies?: D; | |
} | |
export declare function createEpicMiddleware<T extends Action, S, D = any>(rootEpic: Epic<T, S, D>, options?: Options<D>): EpicMiddleware<T, S, D>; | |
export declare function combineEpics<T extends Action, S, D = any>(...epics: Epic<T, S, D>[]): Epic<T, S, D>; | |
export declare function combineEpics<E>(...epics: E[]): E; | |
export declare function ofType<T extends Action>(...keys: T['type'][]): (source: Observable<T>) => Observable<T>; | |
export declare const EPIC_END: '@@redux-observable/EPIC_END'; | |
interface PingAction { type: 'PING' } | |
interface PongAction { type: 'PONG' } | |
interface SomethingElseAction { type: 'SOMETHING_ELSE' } | |
interface AnotherThingAction { type: 'ANOTHER_THING' } | |
type Actions | |
= PingAction | |
| PongAction | |
| SomethingElseAction | |
| AnotherThingAction | |
; | |
// The real output is PongAction but TypeScript doesn't | |
// seem to care and will accept anything. e.g. number | |
type OutputActions = number; | |
function pingEpic(action$: ActionsObservable<Actions>): Observable<OutputActions> { | |
return action$.ofType<PingAction>('PING') | |
.mapTo<PingAction, PongAction>({ type: 'PONG' }); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment