Skip to content
Permalink
Browse files

fix(typings): adds store type to Epic (#174)

fixes #172

BREAKING CHANGE: TypeScript users only, the type interface for Epics now requires a second generic argument, your store's state interface. `interface Epic<ActionShape, StateShape>`. If you don't to strictly type your state, you can pass `any`
  • Loading branch information...
billba authored and jayphelps committed Jan 20, 2017
1 parent b5ce68a commit ca4b163d11555c6e2bcf22a4907d09c6a397845b
Showing with 15 additions and 22 deletions.
  1. +8 −8 index.d.ts
  2. +0 −1 package.json
  3. +7 −7 test/typings.ts
  4. +0 −6 typings.json
@@ -23,16 +23,16 @@ export declare class ActionsObservable<T> extends Observable<T> {
static from<T, R>(ish: ArrayLike<T>, scheduler?: Scheduler): ActionsObservable<R>;

constructor(input$: Observable<T>);
lift(operator: Operator<any, T>) : ActionsObservable<T>;
ofType(...key: any[]) : ActionsObservable<T>;
lift(operator: Operator<any, T>): ActionsObservable<T>;
ofType(...key: any[]): ActionsObservable<T>;
}

export declare interface Epic<T> {
(action$: ActionsObservable<T>, store: MiddlewareAPI<any>): Observable<T>;
export declare interface Epic<T, S> {
(action$: ActionsObservable<T>, store: MiddlewareAPI<S>): Observable<T>;
}

export interface EpicMiddleware<T> extends Middleware {
replaceEpic(nextEpic: Epic<T>): void;
export interface EpicMiddleware<T, S> extends Middleware {
replaceEpic(nextEpic: Epic<T, S>): void;
}

interface Adapter {
@@ -44,6 +44,6 @@ interface Options {
adapter?: Adapter;
}

export declare function createEpicMiddleware<T>(rootEpic: Epic<T>, options?: Options): EpicMiddleware<T>;
export declare function createEpicMiddleware<T, S>(rootEpic: Epic<T, S>, options?: Options): EpicMiddleware<T, S>;

export declare function combineEpics<T>(...epics: Epic<T>[]): Epic<T>;
export declare function combineEpics<T, S>(...epics: Epic<T, S>[]): Epic<T, S>;
@@ -68,7 +68,6 @@
"@types/chai": "^3.4.34",
"@types/es6-shim": "^0.31.32",
"@types/mocha": "^2.2.33",
"@types/redux": "^3.6.0",
"@types/sinon": "^1.16.32",
"babel-cli": "^6.11.4",
"babel-eslint": "^7.0.0",
@@ -17,30 +17,30 @@ interface FluxStandardAction {
meta?: any
}

const epic1: Epic<FluxStandardAction> = (action$: ActionsObservable<FluxStandardAction>, store) =>
const epic1: Epic<FluxStandardAction, any> = (action$: ActionsObservable<FluxStandardAction>, store) =>
action$.ofType('FIRST')
.mapTo({
type: 'first',
payload: store.getState()
});

const epic2: Epic<FluxStandardAction> = (action$, store) =>
const epic2: Epic<FluxStandardAction, any> = (action$, store) =>
action$.ofType('SECOND', 'NEVER')
.mapTo('second')
.mergeMap(type => Observable.of({ type }));

const epic3: Epic<FluxStandardAction> = action$ =>
const epic3: Epic<FluxStandardAction, any> = action$ =>
action$.ofType('THIRD')
.mapTo({
type: 'third'
});

const epic4: Epic<FluxStandardAction> = () =>
const epic4: Epic<FluxStandardAction, any> = () =>
Observable.of({
type: 'fourth'
});

const epic5: Epic<FluxStandardAction> = (action$, store) =>
const epic5: Epic<FluxStandardAction, any> = (action$, store) =>
action$.ofType('FIFTH')
.flatMap(({ type, payload }) => Observable.of({
type: 'fifth',
@@ -54,10 +54,10 @@ const epic6 = (action$, store) =>
payload
}));

const rootEpic1: Epic<FluxStandardAction> = combineEpics<FluxStandardAction>(epic1, epic2, epic3, epic4, epic5, epic6);
const rootEpic1: Epic<FluxStandardAction, any> = combineEpics<FluxStandardAction, any>(epic1, epic2, epic3, epic4, epic5, epic6);
const rootEpic2 = combineEpics(epic1, epic2, epic3, epic4, epic5, epic6);

const epicMiddleware1: EpicMiddleware<FluxStandardAction> = createEpicMiddleware<FluxStandardAction>(rootEpic1);
const epicMiddleware1: EpicMiddleware<FluxStandardAction, any> = createEpicMiddleware<FluxStandardAction, any>(rootEpic1);
const epicMiddleware2 = createEpicMiddleware(rootEpic2);

const reducer = (state = [], action) => state.concat(action);

This file was deleted.

0 comments on commit ca4b163

Please sign in to comment.
You can’t perform that action at this time.