Quick actions

cmd+k|ctrl+k

Navigation

Languages

Reducer work test

Snippet info

Language

JavaScript

Visibility

public

Author

paulkotov

Created

2017-11-01T10:14:33Z

Updated

2017-11-01T10:19:46Z

let initialState = [];

// Actions
function loadMemos() {
  return {
    type: 'LOAD_MEMO'
  };
}

function saveMemo(data) {
  return {
    type: 'SAVE_MEMO',
    payload: {
      id: data.id,
      type: data.type,
      text: data.text
    }
  };
}

// Reducer
function memos(state = initialState, action = {}) {
  switch(action.type) {
    case 'LOAD_MEMOS':
      return state;

    case 'SAVE_MEMO':
      return [...state, {
        id: action.payload.id,
        type: action.payload.type,
        text: action.payload.text
        }
      ];
  }
}

const newMemo = saveMemo({id: 1, type: 'usermemo', text: 'Ener some text'});
const newState = memos(initialState, newMemo);
console.log(newMemo);
console.log(newState);
INFO