如果我的 React 应用程序中有 100 个 reducer,是否会在调度操作时调用所有 reducer?
If i have 100 reducers in my react app will all reducers get called when an action is dispatched?
如果是这样会导致性能问题吗?
其次
有没有办法在不调用所有 100 个 reducer 的情况下专门调用 reducer ?
这在 Redux FAQ 中有专门的回答:
https://redux.js.org/faq/performance#wont-calling-all-my-reducers-for-each-action-be-slow
It's important to note that a Redux store really only has a single reducer function.
However, even if you happen to have many different reducer functions composed together, and even with deeply nested state, reducer speed is unlikely to be a problem. JavaScript engines are capable of running a very large number of function calls per second, and most of your reducers are probably just using a switch statement and returning the existing state by default in response to most actions.
此外,“调用减速器”在这里是错误的心智模型。动作就像正在广播的“事件”——你永远不会直接“调用减速器”:
https://redux.js.org/style-guide/style-guide#model-actions-as-events-not-setters
如果是这样会导致性能问题吗?
其次
有没有办法在不调用所有 100 个 reducer 的情况下专门调用 reducer ?
这在 Redux FAQ 中有专门的回答:
https://redux.js.org/faq/performance#wont-calling-all-my-reducers-for-each-action-be-slow
It's important to note that a Redux store really only has a single reducer function.
However, even if you happen to have many different reducer functions composed together, and even with deeply nested state, reducer speed is unlikely to be a problem. JavaScript engines are capable of running a very large number of function calls per second, and most of your reducers are probably just using a switch statement and returning the existing state by default in response to most actions.
此外,“调用减速器”在这里是错误的心智模型。动作就像正在广播的“事件”——你永远不会直接“调用减速器”:
https://redux.js.org/style-guide/style-guide#model-actions-as-events-not-setters