Created
December 31, 2015 22:51
-
-
Save arackaf/5a8b3f59391377589bf8 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
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