Created
November 11, 2016 08:31
-
-
Save pekkis/0342449d66c320d8ea292adda0abc16d to your computer and use it in GitHub Desktop.
TUSSI
This file contains hidden or 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
import personService from 'services/person'; | |
import uuid from 'node-uuid'; | |
const defaultState = { | |
persons: [], | |
}; | |
export function getPersons() { | |
return { | |
type: 'PERSON_GET_PERSONS', | |
payload: personService.getPersons(), | |
}; | |
}; | |
export function addPerson(firstName, lastName) { | |
const person = { | |
...personService.generatePerson(), | |
firstName, | |
lastName, | |
}; | |
return { | |
type: 'PERSON_ADD_PERSON', | |
payload: person, | |
}; | |
} | |
export function deletePerson(id) { | |
return { | |
type: 'PERSON_DELETE_PERSON', | |
payload: id, | |
}; | |
}; | |
export default function personReducer(state = defaultState, action) { | |
const { type, payload } = action; | |
switch (type) { | |
case 'PERSON_GET_PERSONS_FULFILLED': | |
return { | |
...state, | |
persons: payload, | |
}; | |
case 'PERSON_ADD_PERSON': | |
return { | |
...state, | |
persons: state.persons.concat([payload]), | |
}; | |
case 'PERSON_DELETE_PERSON': | |
return { | |
...state, | |
persons: state.persons.filter(p => p.id !== payload), | |
}; | |
default: | |
return state; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment