leoasis / redux-immutable-state-invariant

Redux middleware that detects mutations between and outside redux dispatches. For development use only.
MIT License
937 stars 37 forks source link

redux-saga compatibility #24

Closed ghost closed 8 years ago

ghost commented 8 years ago

So far redux-immutable-state-invariant gives warnings in the react components and in the reducers. but i'm not getting any errors from the sagas. Is there a plan for making this library work with generator functions needed for redux-saga?

ghost commented 8 years ago

Ahh sorry I wasn't checking the right action. It works with generator functions.

Here's how I did it:

import immutableStateInvariant from 'redux-immutable-state-invariant';

// add the middlewares
let middlewares = [];

// add the immutable dev middleware
if (process.env.NODE_ENV !== 'production') {
    middlewares.push(immutableStateInvariant());
}

// add the router middleware
middlewares.push(routerMiddleware(browserHistory));

// add the saga middleware
const sagaMiddleware = createSagaMiddleware();
middlewares.push(sagaMiddleware);

// apply the middleware
let middleware = applyMiddleware(...middlewares);

// add the redux dev tools
if (process.env.NODE_ENV !== 'production' && window.devToolsExtension) {
    middleware = compose(middleware, window.devToolsExtension());
}

// create the store
const store = createStore(reducers, middleware);
const history = syncHistoryWithStore(browserHistory, store);
sagaMiddleware.run(sagas);