Reactjs 是否使用redux存储中的合并还原程序重置嵌套isDirty状态?

Reactjs 是否使用redux存储中的合并还原程序重置嵌套isDirty状态?,reactjs,redux,react-redux,Reactjs,Redux,React Redux,因此,在我的商店中,每个routid有多个状态,每个routid都有一个isDirty状态。然后我有两个动作,RESET\u DIRTY和RESET\u ALL。下面的代码有效。但是我想我想知道是否有一种方法可以使用组合减速机来实现这一点,这样我就可以清理这个模式了 我的商店现在看起来像这样,我想知道怎么办 function fruits(state = {}, action) { return { isDirty: isDirty(state.isDirty, action)

因此,在我的商店中,每个
routid
有多个状态,每个
routid
都有一个
isDirty
状态。然后我有两个动作,
RESET\u DIRTY
RESET\u ALL
。下面的代码有效。但是我想我想知道是否有一种方法可以使用
组合减速机来实现这一点,这样我就可以清理这个模式了

我的商店现在看起来像这样,我想知道怎么办

function fruits(state = {}, action) {
  return { 
    isDirty: isDirty(state.isDirty, action)
  }
}

function isDirty(state = false, action) {
  switch (action.type) {
    case ActionTypes.RESET_DIRTY:
      return false;
    default:
      return state;
  }
}

export default function fruitStore(state = {}, action) {
  if (!action.type.startsWith('fruits')) {
    return state;
  }

  const { fruitId } = action;
  const { currentFruit } = fruitId ? { 
    [fruitId] : fruits(state[fruitId], action) 
  } : {};

  let newState = Object.assign({}, state, currentFruit);

  switch (action.type) {
    case ActionTypes.RESET_DIRTY_ALL:
      newState = Object.assign({}, newState);

      Object.keys(newState).forEach((key) => {
        newState[key].isDirty = false;
      });

      return newState;
    default:
      return newState;
  }   
}

清理Redux有很多非常好的模式,但是使用Ducks是到目前为止我最喜欢的模式。Github上的此repo提供了如何以这种方式构建文件的详细信息:


有趣。。但我现在遇到的问题是,如果只使用combineReducer来处理嵌套的更新,比如isDirty state resrt,那么它是可能的。所以我可以做简单的上面