Skip to content
Snippets Groups Projects
Select Git revision
  • b11132349b4688dc341c9abff0c796e89d6eae6f
  • master default protected
  • 2023-ujoncdelutan
  • 2023-update
  • 1.4.7 protected
  • 1.4.6 protected
  • 1.4.5 protected
  • 1.4.4 protected
  • 1.4.3 protected
  • 1.4.2 protected
  • 1.4.1 protected
  • 1.4.0 protected
  • 1.3.19 protected
  • 1.3.18 protected
  • 1.3.17 protected
  • 1.3.16 protected
  • 1.3.15 protected
  • 1.3.14 protected
  • 1.3.13 protected
  • 1.3.12 protected
  • 1.3.10 protected
  • 1.3.11 protected
  • 1.3.9 protected
  • 1.3.8 protected
24 results

NewsReducer.js

Blame
  • To find the state of this project's repository at the time of any of these versions, check out the tags.
    NewsReducer.js 618 B
    import { GET_NEWS, ADD_NEWS, DELETE_NEWS, EDIT_NEWS } from '../actions/types';
    
    const INITIAL_STATE = [];
    
    export default (state = INITIAL_STATE, action) => {
      switch (action.type) {
        case GET_NEWS:
          return action.payload;
        case ADD_NEWS:
          return [action.payload, ...state];
        case EDIT_NEWS:
          const array = state.filter(item => item.id === action.payload.id);
          state.splice(state.indexOf(array.pop()), 1, action.payload);
          return [...state];
        case DELETE_NEWS:
          state.splice(state.indexOf(action.payload), 1);
          return [...state];
        default:
          return state;
      }
    };