From 424b16dea3a5ec50f031e0421598cf1903cd18af Mon Sep 17 00:00:00 2001 From: The Big Red Geek Date: Mon, 25 Jan 2016 22:59:10 -0800 Subject: [PATCH 1/2] dried up action names into constants --- client/actions/todos.js | 14 +++++++------- client/constants/action_names.js | 6 ++++++ client/reducers/todos.js | 14 +++++++------- 3 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 client/constants/action_names.js 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..f8dceb0 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) From 7327107440e6032c5cf89f2dfd53ae51996e4f03 Mon Sep 17 00:00:00 2001 From: The Big Red Geek Date: Mon, 25 Jan 2016 23:01:03 -0800 Subject: [PATCH 2/2] fix --- client/reducers/todos.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/reducers/todos.js b/client/reducers/todos.js index f8dceb0..da1789b 100644 --- a/client/reducers/todos.js +++ b/client/reducers/todos.js @@ -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 }