Skip to content

Instantly share code, notes, and snippets.

@kitze
Created January 8, 2016 16:28
Show Gist options
  • Save kitze/8d3053a007e9690428db to your computer and use it in GitHub Desktop.
Save kitze/8d3053a007e9690428db to your computer and use it in GitHub Desktop.
todos reducer
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