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
| toggleComplete(todo: ITodo) { | |
| const todoUpdate: Update<ITodo> = { | |
| id: todo.id, | |
| changes: { complete: !todo.complete } | |
| }; | |
| this.store.dispatch(new ToggleComplete(todoUpdate)); | |
| } | |
| edit(todo: ITodo) { | |
| this.dialogService.openEditDialog(todo).subscribe( |
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: ITodoState = initialTodoState, | |
| action: TodoActions | |
| ): ITodoState { | |
| switch (action.type) { | |
| case TodoActionTypes.AddTodo: { | |
| const todo = { | |
| ...action.payload.todo, | |
| id: uuid() | |
| }; |
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 class UpdateDescription implements Action { | |
| readonly type = TodoActionTypes.UpdateDescription; | |
| constructor(public payload: Update<ITodo>) {} | |
| } | |
| export class ToggleComplete implements Action { | |
| readonly type = TodoActionTypes.ToggleComplete; | |
| constructor(public payload: Update<ITodo>) {} | |
| } |
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 { ITodo } from '../models'; | |
| import * as ListActions from '../actions/todo-list.actions'; | |
| export type Action = ListActions.All; | |
| export function todosReducer(state: ITodo[], action: Action) { | |
| switch (action.type) { | |
| case ListActions.FETCH_TODOS_SUCCESS: | |
| return action.payload; | |
| default: |
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 { Action } from '@ngrx/store'; | |
| import { ITodoList, ITodo } from '../models'; | |
| export const FETCH_LISTS = 'FETCH_LISTS'; | |
| export const FETCH_LISTS_SUCCESS = 'FETCH_LISTS_SUCCESS'; | |
| export const SELECT_LIST = 'SELECT_LIST'; | |
| export const FETCH_TODOS = 'FETCH_TODO'; | |
| export const FETCH_TODOS_SUCCESS = 'FETCH_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
| import { Observable } from 'rxjs/Rx'; | |
| import { Component, OnInit } from '@angular/core'; | |
| import { ITodoList } from './models/todoList'; | |
| import { ITodo } from './models/todo'; | |
| // ngrx | |
| import { Store } from '@ngrx/store'; | |
| import { IAppState } from './models/appState'; | |
| import * as ListActions from './actions/list.actions'; |
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 { ITodoList } from './todoList'; | |
| import { ITodo } from './todo'; | |
| export interface IAppState { | |
| todoLists: ITodoList[]; | |
| currentTodoList: number; | |
| todos: ITodo[]; | |
| } | |
| export const INITIAL_STATE: IAppState = { |
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 { FormsModule } from '@angular/forms'; | |
| import { BrowserModule } from '@angular/platform-browser'; | |
| import { NgModule } from '@angular/core'; | |
| import { HttpClientModule } from '@angular/common/http'; | |
| import { AppComponent } from './app.component'; | |
| import { TodoService } from './todo.service'; | |
| // ngrx | |
| import { StoreModule } from '@ngrx/store'; |