loading...

Discussion on: Advanced Async Logic with Redux Observable

Collapse
ibearua profile image
Ibe Arua

if you are using angular, can you show code snippet of adding this to the ngRedux configure store parameter. or do you a link to the full code.

I enjoyed it!

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;