这两个reducer是否在每次动作分派上都被调用?

问题描述 投票:0回答:1
func appStateReducer(state: AppState, action: Action) -> AppState {
  var state = state
  state.moviesState = moviesStateReducer(state: state.moviesState, action: 
    action)
  state.peoplesState = peoplesStateReducer(state: state.peoplesState, 
  action: action)
  return state
}

例如会:

store.dispatch(action: MoviesActions.RemoveFromWishlist(movie: movie))

结束同时调用moviesStatepeoplesState异径管吗?如果是这样,那么为什么不将一个条件放入每个动作仅调用一个reducer的任何原因?

来源:

https://github.com/Dimillian/MovieSwiftUI/blob/master/MovieSwift/Shared/flux/reducers/AppReducer.swift

高级目录源:

https://github.com/Dimillian/MovieSwiftUI/tree/52e852fc3da2524fd784374727e747eaba8497b6/MovieSwift/Shared/flux

swift redux reducers
1个回答
0
投票

默认情况下,是的,所有reducer函数将在每次操作时调用。根据docs,成为性能障碍的可能性很小。通常,只有一个reducer进行状态更新,而所有其他reducer都只通过它们的switch语句运行,因此时间复杂度随您拥有的actions的数量而定,这不太可能达到足以接受的数字有效时间(10^7左右)。

但是,您可以使用redux-ignore之类的库来使化简器忽略特定的动作,和/或使用reduxr-scoped-reducer来使化简器仅响应特定的动作。

© www.soinside.com 2019 - 2024. All rights reserved.