import * as types from '../actions/action-types';
import initialState from './initial-state';

export default (state = initialState.courses, action) => {
    switch (action.type) {
    case types.LOAD_COURSES_SUCCESS:
        return action.courses;

    default:
        return state;
    }
};

import * as types from '../actions/action-types';
import initialState from './initial-state';

export default (state = initialState.courses, action) => {
    switch (action.type) {
    case types.LOAD_COURSES_SUCCESS:
        return action.courses;

    case types.CREATE_COURSE_SUCCESS:
        return [
            ...state,
            Object.assign({}, action.course),
        ];

    case types.UPDATE_COURSE_SUCCESS:
        return [
            ...state.filter(course => course.id !== action.course.id),
            Object.assign({}, action.course),
        ];

    default:
        return state;
    }
};

Handle creates and updates in the reducer
Handle creates and updates in the reducer
