Created
February 16, 2018 13:22
-
-
Save rodrigonehring/c6c0d0526efeb41d5807792d6dc1666a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const initialState = { | |
project: "My-App", | |
lists: [ | |
{ | |
id: 1, | |
title: "A Fazer", | |
cards: [ | |
{ | |
id: 1, | |
description: "Comprar Pao" | |
} | |
] | |
}, | |
{ | |
id: 2, | |
title: "Fazendo", | |
cards: [ | |
{ | |
id: 1, | |
description: "Comprar Arroz" | |
} | |
] | |
}, | |
{ | |
id: 3, | |
title: "Feito", | |
cards: [ | |
{ | |
id: 1, | |
description: "Ler um livro" | |
} | |
] | |
} | |
] | |
} | |
function reducer(state, { type, payload }) { | |
switch (type) { | |
case 'add': | |
return { | |
...state, | |
lists: state.lists.concat(payload), | |
} | |
case 'remove': | |
return { | |
...state, | |
lists: state.lists.filter(item => item.id !== payload) | |
} | |
case 'update': | |
return { | |
...state, | |
lists: state.lists.map(item => item.id === payload.id ? | |
{ ...item, ...payload } : item) | |
} | |
default: | |
return state | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment