Skip to content

Instantly share code, notes, and snippets.

@nomanHasan
Created October 11, 2017 10:02
Show Gist options
  • Save nomanHasan/f30c9fc00efd6da5c528716a92cf4574 to your computer and use it in GitHub Desktop.
Save nomanHasan/f30c9fc00efd6da5c528716a92cf4574 to your computer and use it in GitHub Desktop.
7 #todoapp-angular-ngrx
// ........................
export function TodoReducer(state = defaultState, action: Action) {
switch (action.type) {
//...............
case TodoActions.UPDATE_TODO: {
return {
...state,
todos: state.todos.map(t => {
if (t._id == action.payload._id) {
t.loading = true;
}
return t
})
};
}
case TodoActions.UPDATE_TODO_SUCCESS: {
return modifyTodoState(state, action.payload, {})
}
case TodoActions.UPDATE_TODO_ERROR: {
return {
...state,
todos: state.todos.map(t => {
if (t._id == action.payload._id) {
t.error = true;
}
return t
})
};
}
//...............
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment