Skip to content

Instantly share code, notes, and snippets.

@Tauka
Created April 15, 2017 23:46
Show Gist options
  • Select an option

  • Save Tauka/daadddfb5407041b5f14ca6cc23ce490 to your computer and use it in GitHub Desktop.

Select an option

Save Tauka/daadddfb5407041b5f14ca6cc23ce490 to your computer and use it in GitHub Desktop.
export default function reducer(state={
groups: [],
group: null,
groupsFetchPending: false,
groupsFetchSuccess: null,
groupFetchPending: false,
groupFetchSuccess: null,
groupNewPending: false,
groupNewSuccess: null,
groupNewPending: false,
groupNewSuccess: null,
groupAddStudentPending: false,
groupAddStudentSuccess: null,
groupAddStudentPending: false,
groupRemoveStudentSuccess: null,
groupRemoveStudentPending: false,
groupRemoveStudentSuccess: null
}, action) {
switch(action.type) {
case "GROUPS_FETCH_PENDING": {
return {...state, groupsFetchPending: true, groupsFetchSuccess: null}
}
case "GROUPS_FETCH_SUCCESS": {
return {...state, groupsFetchPending: false, groupsFetchSuccess: true, groups: action.payload}
}
case "GROUPS_FETCH_FAIL": {
return {...state, groupsFetchPending: false, groupsFetchSuccess: false}
}
case "GROUP_FETCH_FAIL": {
return {...state, groupFetchPending: false, groupFetchSuccess: false}
}
case "GROUP_FETCH_PENDING": {
return {...state, groupFetchPending: true, groupFetchSuccess: null}
}
case "GROUP_FETCH_SUCCESS": {
return {...state, groupFetchPending: false, groupFetchSuccess: true, group: action.payload}
}
case "GROUP_MY_FETCH_FAIL": {
return {...state, groupFetchPending: false, groupFetchSuccess: false}
}
case "GROUP_MY_FETCH_PENDING": {
return {...state, groupFetchPending: true, groupFetchSuccess: null}
}
case "GROUP_MY_FETCH_SUCCESS": {
return {...state, groupFetchPending: false, groupFetchSuccess: true, group: action.payload}
}
case "GROUP_NEW_FAIL": {
return {...state, groupNewPending: false, groupNewSuccess: false}
}
case "GROUP_NEW_PENDING": {
return {...state, groupNewPending: true, groupNewSuccess: null}
}
case "GROUP_NEW_SUCCESS": {
return {...state, groupNewPending: false, groupNewSuccess: true}
}
case "GROUP_DELETE_PENDING": {
return {...state, groupDeletePending: true, groupDeleteSuccess: null}
}
case "GROUP_DELETE_SUCCESS": {
return {...state, groupDeletePending: false, groupDeleteSuccess: true}
}
case "GROUP_DELETE_FAIL": {
return {...state, groupDeletePending: false, groupDeleteSuccess: false}
}
case "GROUP_MODIFY_FAIL": {
return {...state, groupModifyPending: false, groupModifySuccess: false}
}
case "GROUP_MODIFY_PENDING": {
return {...state, groupModifyPending: true, groupModifySuccess: null}
}
case "GROUP_MODIFY_SUCCESS": {
return {...state, groupModifyPending: false, groupModifySuccess: true}
}
case "GROUP_ADD_STUDENT_FAIL": {
return {...state, groupAddStudentPending: false, groupAddStudentSuccess: false}
}
case "GROUP_ADD_STUDENT_PENDING": {
return {...state, groupAddStudentPending: true, groupAddStudentSuccess: null}
}
case "GROUP_ADD_STUDENT_SUCCESS": {
return {...state, groupAddStudentPending: false, groupAddStudentSuccess: true}
}
case "GROUP_REMOVE_STUDENT_FAIL": {
return {...state, groupRemoveStudentPending: false, groupRemoveStudentSuccess: false}
}
case "GROUP_REMOVE_STUDENT_PENDING": {
return {...state, groupRemoveStudentPending: true, groupRemoveStudentSuccess: null}
}
case "GROUP_REMOVE_STUDENT_SUCCESS": {
return {...state, groupRemoveStudentPending: false, groupRemoveStudentSuccess: true}
}
}
return state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment