Skip to content

Commit

Permalink
feature #11: Create card reducers
Browse files Browse the repository at this point in the history
  • Loading branch information
Boosmith committed Aug 23, 2019
1 parent cdd2d58 commit 697ac5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/redux/reducers/cardReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as actionTypes from "../actions/actionTypes";
import initialState from "./initialState";

export default function cardReducer(state = initialState.cards, action) {
switch (action.type) {
case actionTypes.DELETE_CARD_OPTIMISTIC:
return state.filter(card => card._id !== action.card._id);
case actionTypes.CREATE_CARD_SUCCESS:
return [...state, { ...action.card }];
case actionTypes.LOAD_CARDS_SUCCESS:
return action.cards;
case actionTypes.UPDATE_CARD_SUCCESS:
return state.map(card =>
card._id === action.card._id ? action.card : card
);
default:
return state;
}
}
1 change: 1 addition & 0 deletions src/redux/reducers/initialState.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
cards: [],
users: [],
apiCallsInProgress: 0
};

0 comments on commit 697ac5c

Please sign in to comment.