diff --git a/client/actions/todos.js b/client/actions/todos.js index a87fbb8..778eee0 100644 --- a/client/actions/todos.js +++ b/client/actions/todos.js @@ -1,9 +1,9 @@ - +import { ADD_TODO, DELETE_TODO, EDIT_TODO, COMPLETE_TODO, COMPLETE_ALL, CLEAR_COMPLETED } from '../constants/action_names'; import { createAction } from 'redux-actions' -export const addTodo = createAction('add todo') -export const deleteTodo = createAction('delete todo') -export const editTodo = createAction('edit todo') -export const completeTodo = createAction('complete todo') -export const completeAll = createAction('complete all') -export const clearCompleted = createAction('clear complete') +export const addTodo = createAction(ADD_TODO) +export const deleteTodo = createAction(DELETE_TODO) +export const editTodo = createAction(EDIT_TODO) +export const completeTodo = createAction(COMPLETE_TODO) +export const completeAll = createAction(COMPLETE_ALL) +export const clearCompleted = createAction(CLEAR_COMPLETED) diff --git a/client/constants/action_names.js b/client/constants/action_names.js new file mode 100644 index 0000000..3efa843 --- /dev/null +++ b/client/constants/action_names.js @@ -0,0 +1,6 @@ +export const ADD_TODO = 'add todo'; +export const DELETE_TODO = 'delete todo'; +export const EDIT_TODO = 'edit todo'; +export const COMPLETE_TODO = 'complete todo'; +export const COMPLETE_ALL = 'complete all'; +export const CLEAR_COMPLETED = 'clear completed'; diff --git a/client/reducers/todos.js b/client/reducers/todos.js index c137ca1..da1789b 100644 --- a/client/reducers/todos.js +++ b/client/reducers/todos.js @@ -1,4 +1,4 @@ - +import { ADD_TODO, DELETE_TODO, EDIT_TODO, COMPLETE_TODO, COMPLETE_ALL, CLEAR_COMPLETED } from '../constants/action_names'; import { handleActions } from 'redux-actions' const initialState = [{ @@ -8,7 +8,7 @@ const initialState = [{ }] export default handleActions({ - 'add todo' (state, action) { + [ADD_TODO] (state, action) { return [{ id: state.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + 1, completed: false, @@ -16,11 +16,11 @@ export default handleActions({ }, ...state] }, - 'delete todo' (state, action) { + [DELETE_TODO] (state, action) { return state.filter(todo => todo.id !== action.payload ) }, - 'edit todo' (state, action) { + [EDIT_TODO] (state, action) { return state.map(todo => { return todo.id === action.payload.id ? { ...todo, text: action.payload.text } @@ -28,7 +28,7 @@ export default handleActions({ }) }, - 'complete todo' (state, action) { + [COMPLETE_TODO] (state, action) { return state.map(todo => { return todo.id === action.payload ? { ...todo, completed: !todo.completed } @@ -36,7 +36,7 @@ export default handleActions({ }) }, - 'complete all' (state, action) { + [COMPLETE_ALL] (state, action) { const areAllMarked = state.every(todo => todo.completed) return state.map(todo => { return { @@ -46,7 +46,7 @@ export default handleActions({ }) }, - 'clear complete' (state, action) { + [CLEAR_COMPLETED] (state, action) { return state.filter(todo => todo.completed === false) } }, initialState)