如何使过滤后的不可变?

How do I make a filtered immutable?

这里是菜鸟问题。我正在玩 Redux,但无法弄清楚如何以优雅的方式使此功能(我正在删除已完成的待办事项)不可变: 这是来自我的减速机:

case "DELETE_CHECKED_TODOS":
    return state.filter((todo, index) => {
      return !todo.completed
    })

假设 state 是一个 Javascript 数组(或者可能是一个 Immutable.js 列表),这对我来说很好。这将 return 一个仅包含未设置 completed 的项目的新数组,而不修改旧数组,因此这是不可变更新的正确示例。

如需进一步参考,您可能需要通读 Structuring Reducers - Prerequisite Concepts and Structuring Reducers - Immutable Update Patterns sections in the Redux docs, as well as the articles in the Immutable Data section of my React/Redux links list