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_SUCCESS: { |
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) { | |
//............... | |
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.CREATE_TODO_SUCCESS: { |
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.CREATE_TODO: { | |
return { |
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 Todo from '../../models/todo.model'; | |
import { initializeTodoState, TodoListState, TodoState } from './todo.state'; | |
import * as TodoActions from './todo.action'; | |
export type Action = TodoActions.All; | |
const defaultTodoStates: TodoState[] = [ | |
{ | |
...Todo.generateMockTodo(), | |
...initializeTodoState() |
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
//............................ | |
@Effect() | |
updateTodo$: Observable<Action> = this.actions$. | |
ofType<TodoActions.UpdateTodo>(TodoActions.UPDATE_TODO) | |
.mergeMap(action => | |
this.http.put(environment.client.base_url + '/api/todos/', action.payload) | |
.map((data: Response) => { | |
return new TodoActions.UpdateTodoSuccess({ |
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
//............................ | |
@Effect() | |
deleteTodo$: Observable<Action> = this.actions$. | |
ofType<TodoActions.DeleteTodo>(TodoActions.DELETE_TODO) | |
.mergeMap(action => | |
this.http.delete(environment.client.base_url + '/api/todos/' + action.payload._id) | |
.map((data: Response) => { | |
return new TodoActions.DeleteTodoSuccess({ |
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
//............................ | |
@Effect() | |
createTodo$: Observable<Action> = this.actions$. | |
ofType<TodoActions.CreateTodo>(TodoActions.CREATE_TODO) | |
.mergeMap(action => | |
this.http.post(environment.client.base_url + '/api/todos', action.payload) | |
.map((data: Response) => { |
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
//.............................. | |
@Effect() | |
GetTodos$: Observable<Action> = this.actions$. | |
ofType<TodoActions.GetTodos>(TodoActions.GET_TODOS) | |
.mergeMap(action => | |
this.http.get(environment.client.base_url + '/api/todos') | |
.map((data: Response) => { | |
console.log(data); |
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 { TodoState } from './todo.state'; | |
import { environment } from '../../../environments/environment'; | |
import 'rxjs/add/operator/map'; | |
import 'rxjs/add/operator/mergeMap'; | |
import 'rxjs/add/operator/catch'; | |
import { Injectable } from '@angular/core'; | |
import { Http } from '@angular/http'; | |
import { Observable } from 'rxjs/Observable'; | |
import { Action } from '@ngrx/store'; | |
import { Actions, Effect } from '@ngrx/effects'; |