【问题标题】:combineReducers converts Immutable Map into plain JS objectcombineReducers 将 Immutable Map 转换为纯 JS 对象
【发布时间】:2016-12-19 23:11:24
【问题描述】:

根据我的阅读,这应该不是问题(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 {}

【问题讨论】:

    标签: reactjs redux react-redux immutable.js


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-02
      • 1970-01-01
      • 1970-01-01
      • 2011-12-23
      • 1970-01-01
      • 1970-01-01
      • 2020-03-16
      • 2013-10-20
      相关资源
      最近更新 更多