Skip to content

Instantly share code, notes, and snippets.

@jonasantonelli
Last active July 17, 2019 18:47
Show Gist options
  • Save jonasantonelli/9ed180d5340e4f93c94a1e33e302ee8d to your computer and use it in GitHub Desktop.
Save jonasantonelli/9ed180d5340e4f93c94a1e33e302ee8d to your computer and use it in GitHub Desktop.
Refactoring Reducer - Second Version
import schema from './schema';
import { ACTIONS } from './action';
export default (state = schema, action) => {
switch (action.type) {
case ACTIONS.FETCHING_LIST:
return {
...state,
list: {
value: [],
fetching: true
}
};
case ACTIONS.FETCHING_HEADER:
return {
...state,
header: {
value: {},
fetching: true
}
};
case ACTIONS.FETCHING_ITEM:
return {
...state,
selected: {
value: {},
fetching: true
}
};
case ACTIONS.UNSELECT_ITEM:
return {
...state,
selected: {
value: {},
fetching: false
}
};
case ACTIONS.FETCH_LIST_COMPLETE:
return {
...state,
list: {
value: action.list,
fetching: false
}
};
case ACTIONS.FETCH_ITEM_COMPLETE:
return {
...state,
selected: {
value: action.value,
fetching: false
}
};
case ACTIONS.FETCH_HEADER_COMPLETE:
return {
...state,
header: {
value: action.value,
fetching: false
}
};
case ACTIONS.ERROR:
return {
...state,
isError: true,
errorMessage: action.errorMessage
};
case ACTIONS.POSTING:
return {
...state,
isPosting: true
};
case ACTIONS.CREATED:
return {
...state,
isPosting: false
};
case ACTIONS.UPDATED:
return {
...state,
isPosting: false
};
default:
return state;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment