Created
January 10, 2020 14:14
-
-
Save khades/516b7427c24fc65a4b3a6ce075842e50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as actionTypes from "./actionTypes"; | |
export function dispatchFirstAction(payload: string) { | |
return { | |
type: actionTypes.FirstAction, | |
payload | |
}; | |
} | |
export function dispatchSecondAction(payload: number) { | |
return { | |
type: actionTypes.SecondAction, | |
payload | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as actionCreators from "./actionCreators"; | |
import * as actionTypes from "./actionTypes"; | |
export type InferValueTypes<T> = T extends { [key: string]: infer U } | |
? U | |
: never; | |
type State = { value: string }; | |
export default function reducer( | |
state: State = { value: "hello" }, | |
action: ReturnType<InferValueTypes<typeof actionCreators>> | |
): State { | |
switch (action.type) { | |
case actionTypes.FirstAction: | |
return { value: action.payload }; | |
case actionTypes.SecondAction: | |
return { value: state.value + action.payload }; | |
default: | |
return state; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const FirstAction = "TestReducer/FirstAction" as const; | |
export const SecondAction = "TestReducer/SecondAction" as const; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment