Skip to content

Instantly share code, notes, and snippets.

@toruticas
Created May 14, 2018 23:17
Show Gist options
  • Save toruticas/96862b328c0f317c1b19a08536b979be to your computer and use it in GitHub Desktop.
Save toruticas/96862b328c0f317c1b19a08536b979be to your computer and use it in GitHub Desktop.
Redux simple explanation
store.dispatch({
type: 'OPEN_NFE_VISUALIZATION',
accessKey: 123
})
store.dispatch({
type: 'CLOSE_NFE_VISUALIZATION'
})
function nfeList(state = {}, action) {
switch (action.type) {
case 'OPEN_NFE_VISUALIZATION':
return {
...state,
nfeIsOpen: true,
nfeTargetAK: action.accessKey
}
case 'CLOSE_NFE_VISUALIZATION':
return {
...state,
nfeIsOpen: true,
nfeTargetAK: -1,
}
default:
return state
}
}
console.log(store.getState())
/* Console Output
{
data: [{
accessKey: 123,
cnpj: "00.000.000/0000-00",
value: 100.00
}, {
accessKey: 124,
cnpj: "00.000.000/0001-00",
value: 200.00
}],
nfeIsOpen: false,
nfeTargetAK: -1,
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment