Skip to content

Instantly share code, notes, and snippets.

@alex-okrushko
Last active March 14, 2019 14:26
Show Gist options
  • Select an option

  • Save alex-okrushko/a1a34712955b17a800ef7307f06fcfb9 to your computer and use it in GitHub Desktop.

Select an option

Save alex-okrushko/a1a34712955b17a800ef7307f06fcfb9 to your computer and use it in GitHub Desktop.
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