为什么调度到减速器会导致所有减速器都被调用?

问题描述:

在这个 github redux 示例中,使用了事件 ADD_TODO 的调度添加任务.在调试过程中,我发现添加任务会导致 reducers todosvisibilityFilter 被调用.

In this github redux example, a dispatch of the event ADD_TODO is used to add a task. During the debugging, I found out that adding a task causes both the reducers todos and visibilityFilter being called.

如何在添加任务时只调用 todos 减速器而不是 visibilityFilter 减速器.如果我发送了类型为 SET_VISIBILITY_FILTER 的事件,则还有 visibilityFilter 减速器.

How can I call just the todos reducer and not visibilityFilter reducer when I add a task. Also the visibilityFilter reducer if I sent an event of type SET_VISIBILITY_FILTER.

combineReducers 实用程序有意为每个操作调用所有附加的 reducer 函数,并为它们提供响应的机会.这是因为建议的 Redux 减速器结构是减速器组合",其中许多大部分独立的减速器功能可以组合成一个结构,并且许多减速器功能可能会响应单个操作并更新它们自己的状态切片.

The combineReducers utility intentionally calls all attached reducer functions for every action, and gives them a chance to respond. This is because the suggested Redux reducer structure is "reducer composition", where many mostly-independent reducer functions can be combined into one structure, and many reducer functions could potentially respond to a single action and update their own slice of state.