combineReducers将不可变映射转换为普通的JS对象



根据我的阅读,这应该不是一个问题(redux是v3.3)?我做错了什么?

rootReducer.js

import { combineReducers } from 'redux';
import { routeReducer } from 'react-router-redux';
import { reducer as reduxAsyncConnectReducer } from 'redux-async-connect';
import myReducer from './modules/myReducer';
export default combineReducers({
  routeReducer,
  reduxAsyncConnectReducer,
  myReducer,
});


myReducer.js

import { Map } from 'immutable';
const initialState = Map({});
export default (state = initialState, action = {}) => {
  switch (action.type) {
    default:
      // On the third run "@@INIT" the state gets converted from a Map to a plain JS object :(
      console.log('action:', action.type, 'state:', state);
      return state;
  }
};


输出

action: @@redux/INIT
state: Map {size: 0, _root: undefined, __ownerID: undefined, __hash: undefined, __altered: false}
action: @@redux/PROBE_UNKNOWN_ACTION_x.5.a.b.w.u.f.k.8.3.q.b.s.5.e.e.4.5.c.d.i
state: Map {size: 0, _root: undefined, __ownerID: undefined, __hash: undefined, __altered: false}
action: @@INIT
state: Object {}

是否可以尝试不使用不可变映射作为初始状态…我只是使用一个标准对象?redux-async-connect似乎有一些问题/额外的工作来支持immutable.js。详见https://github.com/Rezonans/redux-async-connect/pull/45

相关内容

  • 没有找到相关文章

最新更新