Skip to content

Conversation

skywalkerlw
Copy link

Description

This MR is to add an optional id property to Action protocol

Why

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
}

@haifengkao
Copy link

why don't you just check the type of action?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants