Last active
March 14, 2019 14:26
-
-
Save alex-okrushko/a1a34712955b17a800ef7307f06fcfb9 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
| export interface ResultState { | |
| result: Result|null, | |
| callState: CallState; | |
| } | |
| const initState: ResultState = { | |
| result: null, | |
| callState: LoadingState.INIT, | |
| } | |
| export function reducer(state: ResultState = initState, action: actions.All): ResultState { | |
| switch(action.type) { | |
| case actions.FETCH_RESULT: { | |
| return { | |
| ...state, | |
| // set to loading | |
| callState: LoadingState.LOADING, | |
| }; | |
| } | |
| case actions.FETCH_RESULT_SUCCESS: { | |
| return { | |
| ...state, | |
| result: action.result; | |
| callState: LoadingState.LOADED, | |
| }; | |
| } | |
| case actions.FETCH_RESULT_ERROR: { | |
| return { | |
| ...state, | |
| callState: {error: action.errorMsg}, | |
| }; | |
| } | |
| case default: { | |
| return state; // return state untouched | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment