Skip to content
This repository has been archived by the owner on Jul 31, 2018. It is now read-only.

Chore/dry up action names #46

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions client/actions/todos.js
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions client/constants/action_names.js
Original file line number Diff line number Diff line change
@@ -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';
14 changes: 7 additions & 7 deletions client/reducers/todos.js
Original file line number Diff line number Diff line change
@@ -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 = [{
Expand All @@ -8,35 +8,35 @@ 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,
text: action.payload
}, ...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 }
: todo
})
},

'complete todo' (state, action) {
[COMPLETE_TODO] (state, action) {
return state.map(todo => {
return todo.id === action.payload
? { ...todo, completed: !todo.completed }
: todo
})
},

'complete all' (state, action) {
[COMPLETE_ALL] (state, action) {
const areAllMarked = state.every(todo => todo.completed)
return state.map(todo => {
return {
Expand All @@ -46,7 +46,7 @@ export default handleActions({
})
},

'clear complete' (state, action) {
[CLEAR_COMPLETED] (state, action) {
return state.filter(todo => todo.completed === false)
}
}, initialState)