Last active
October 12, 2017 11:40
-
-
Save nomanHasan/da05c5efe56a6c67fcb7596def5c6a3c to your computer and use it in GitHub Desktop.
4 #todoapp-angular-ngrx
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
// ........................ | |
export function TodoReducer(state = defaultState, action: Action) { | |
switch (action.type) { | |
//............... | |
case TodoActions.GET_TODOS: { | |
return { ...state, loaded: false, loading: true }; | |
} | |
case TodoActions.GET_TODOS_SUCCESS: { | |
return { | |
...state, | |
todos: [ | |
...action.payload, | |
defaultTodoStates[0] | |
], | |
loading: false | |
}; | |
} | |
case TodoActions.DELETE_TODO: { | |
return { ...state, ...state.todos.splice(state.todos.indexOf(action.payload), 1) }; | |
} | |
case TodoActions.DELETE_TODO_SUCCESS: { | |
return state | |
} | |
case TodoActions.DELETE_TODO_ERROR: { | |
return { | |
...state, | |
todos: [ | |
...state.todos, | |
action.payload | |
] | |
} | |
} | |
//............... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment