Skip to content

Instantly share code, notes, and snippets.

@arackaf
Created December 31, 2015 22:51
Show Gist options
  • Save arackaf/5a8b3f59391377589bf8 to your computer and use it in GitHub Desktop.
Save arackaf/5a8b3f59391377589bf8 to your computer and use it in GitHub Desktop.
const bookSubjectManagerInitialState = () => ({
singleBookModify: null,
selectedBooksModify: false,
addingSubjects: {},
removingSubjects: {}
});
function bookSubjectManagerReducer(state = bookSubjectManagerInitialState(), action = {}){
switch (action.type){
case ENABLE_SUBJECT_MODIFICATION_FOR_SINGLE_BOOK:
return Object.assign({}, state, { singleBookModify: action._id });
case ENABLE_SUBJECT_MODIFICATION_FOR_TOGGLED_BOOKS:
return Object.assign({}, state, { selectedBooksModify: true });
case CANCEL_SUBJECT_MODIFICATION:
return Object.assign({}, state, { singleBookModify: null, selectedBooksModify: false });
case TOGGLE_SUBJECT_ADD_FOR_SUBJECT_MODIFICATION:
return Object.assign({}, state, { addingSubjects: { ...state.addingSubjects, [action._id]: !state.addingSubjects[action._id] } });
case TOGGLE_SUBJECT_REMOVE_FOR_SUBJECT_MODIFICATION:
return Object.assign({}, state, { removingSubjects: { ...state.removingSubjects, [action._id]: !state.removingSubjects[action._id] } });
}
return state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment