Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add id for Action protocol #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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