Skip to content

Instantly share code, notes, and snippets.

@rodrigonehring
Created February 16, 2018 13:22
Show Gist options
  • Save rodrigonehring/c6c0d0526efeb41d5807792d6dc1666a to your computer and use it in GitHub Desktop.
Save rodrigonehring/c6c0d0526efeb41d5807792d6dc1666a to your computer and use it in GitHub Desktop.
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