Created
January 8, 2016 16:28
-
-
Save kitze/8d3053a007e9690428db to your computer and use it in GitHub Desktop.
todos reducer
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 * as actions from "../actions/todos"; | |
const INITIAL_STATE = { | |
items: ['initial', 'todo', 'items'], | |
loading: false | |
} | |
export default (state = INITIAL_STATE, action) => { | |
console.log('action type is', action.type); | |
switch (action.type) { | |
case actions.ADD_TODO: | |
return { | |
...state, | |
items: [action.text, ...state.items] | |
} | |
break; | |
case actions.GET_TODOS_INIT: | |
console.error('initializing'); | |
return { | |
...state, | |
loading: true | |
} | |
break; | |
case actions.GET_TODOS: | |
console.error('got todos', action); | |
return { | |
...state, | |
items: action.value, | |
loading: false | |
} | |
break; | |
default: | |
console.error('returning the initial state') | |
return state; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment