我一直在编写一些自定义中间件。我想看到的只是我的商店(作为不同国家的连锁店)。每个减速机都有自己的状态,结合它应该给我我的商店。
import {createStore, applyMiddleware, compose} from 'redux';
import rootReducer from '../reducers';
import thunk from 'redux-thunk';
import {createLogger} from 'redux-logger';
import PouchDB from 'pouchdb';
const logger = createLogger({collapsed: true});
const customMiddleware = store => next => action => {
console.log(store.getState());
next(action);
}
export default function configureStore(initialState) {
return createStore(rootReducer, applyMiddleware(customMiddleware));
}

添加isImmutable后我尝试了这个:
const customMiddleware = store => next => action => {
const state = store.getState();
const storeTest = store.getState().toJS();
console.log(storeTest);
console.log(isImmutable(state) ? state.toJS() : state);
next(action);
}

storeTest提供想要的结果,但另一个日志没有。 Any idea how to fix this?
答案 0 :(得分:0)
看起来您的redux状态是immutable Map
而不是普通对象,因此您需要在记录它之前进行转换:
import { isImmutable } from 'immutable';
..
const customMiddleware = store => next => action => {
const state = store.getState();
console.log(isImmutable(state) ? state.toJS() : state);
next(action);
};