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);