Open skywalkerlw opened 4 years ago
This MR is to add an optional id property to Action protocol
id
Action
With id added, we don't need to run all cases in reducer, here is an example
// old
func appStateReducer(state: AppState, action: Action) -> AppState { var state = state state.nextRacesState = nextRacesStateReducer(state: state.nextRacesState, action: action) state.timestampSyncState = timestampSyncStateReducer(state: state.timestampSyncState, action: action) return state }
// new
func appStateReducer(state: AppState, action: Action) -> AppState { var state = state switch action.id { case NextRacesActions.actionId: state.nextRacesState = nextRacesStateReducer(state: state.nextRacesState, action: action) case TimestampSyncActions.actionId: state.timestampSyncState = timestampSyncStateReducer(state: state.timestampSyncState, action: action) default: print("do nothing") } return state }
why don't you just check the type of action?
Description
This MR is to add an optional
id
property toAction
protocolWhy
With
id
added, we don't need to run all cases in reducer, here is an example// old
// new