Skip to content

Instantly share code, notes, and snippets.

@vsavkin
Created July 13, 2017 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vsavkin/22ae4f139b69b8c127baffff7ad644b1 to your computer and use it in GitHub Desktop.
Save vsavkin/22ae4f139b69b8c127baffff7ad644b1 to your computer and use it in GitHub Desktop.
class TodosEffects {
constructor(private actions: Actions, private http: Http) {}
@Effect() addTodo = this.actions.ofType('ADD_TODO').
concatMap(todo => this.http.post(…).
map(() => ({type: 'TODO_ADDED', payload: todo})));
}
function todosReducer(todos: Todo[] = [], action: any): Todo[] {
if (action.type === 'TODO_ADDED') {
return [...todos, action.payload];
} else {
return todos;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment