seamless-immutable不会一致地更新状态

时间:2017-03-29 16:10:23

标签: redux immutability seamless-immutable

我正在使用seamless-immutable和redux,我在更新状态时遇到了一个奇怪的错误。这是我的代码,没有像action return或combineReducers这样的位。只是那个正在运行/导致错误的垃圾。

初始状态

{ 
  things: {
    fetching: false,
    rows: []
  }
}

动作处理程序

export default {
  [DEALERS_REQUEST]: (state, action) => {
    return Immutable({ ...state, fetching: true });
  },
  [DEALERS_RECEIVE]: (state, action) => {
    return Immutable({ ...state, rows: action.payload, fetching: false });
},

带有thunk的中间件

export const thingsFetch = (data) => {
  return (dispatch, getState) => {
    dispatch(thingsRequest());
    dispatch(thingsReceive(data));
  }
}

现在,奇怪的是,如果我把这两个行动放在一起,一切都很好。

如果我只发送thingsRequest(),我会得到一个"无法推送到不可变对象"错误。

我尝试过使用set,update,replace,merge之类的方法,但它们通常会返回" this.merge不是函数"。

我是在程序上做错了什么,还是应该联系模块开发人员报告问题?

1 个答案:

答案 0 :(得分:0)

This issue on this was that, on the case of an empty array, the component was trying to write back to the Immutable object with it's own error message.

To get around this, I pass the prop as mutable. There's also some redux-immutable modules that replace the traditional connect function to all the app to pass mutable props to components while maintaining immutability in the state.

相关问题