loading...

Discussion on: Advanced Async Logic with Redux Observable

Collapse
osamaq profile image
Osama Qarem Author

Glad you liked it! Unfortunately I've never used Angular, but I hope this snippet will be of some help:

reducers/index.ts

import { combineReducers } from "redux";
import { combineEpics } from "redux-observable";
import {
  myEpic,
  myOtherEpic
} from "../actions";
import myReducer from "./myReducer";
import myOtherReducer from "./myOtherReducer";

// Pass epics.
// Actions will run through reducers first and then epics.
export const rootEpic = combineEpics(
  myEpic,
  myOtherEpic
);

// Pass reducers.
export default combineReducers({
  myReducer,
  myOtherReducer
});

store/index.ts

import { createStore, applyMiddleware } from "redux";
import thunk from "redux-thunk";
import reducers, { rootEpic } from "../reducers";
import { createEpicMiddleware } from "redux-observable";

const epicMiddleware = createEpicMiddleware();

const store = createStore(
  reducers,
  {},
  applyMiddleware(thunk, epicMiddleware)
);

epicMiddleware.run(rootEpic);

// Useful if using TypeScript (optional)
export type RootStoreType = ReturnType<typeof reducers>;

export default store;