Created
June 4, 2019 14:27
-
-
Save jonathanwoahn/f4e3a9904a3ea8d0044c5216535ce7da to your computer and use it in GitHub Desktop.
This file contains 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 { Component, ViewChild, ElementRef } from '@angular/core'; | |
import { v4 as uuid } from 'uuid'; | |
import { Todo } from './app.module'; | |
import { DynamicFacadeService, DynamicFacade } from 'dynamic-ngrx'; | |
import { Store } from '@ngrx/store'; | |
import { Observable } from 'rxjs'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'] | |
}) | |
export class AppComponent { | |
@ViewChild('todoInput') todoInput: ElementRef; | |
todos$: Observable<Todo[]>; | |
private todoFacade: DynamicFacade<Todo>; | |
constructor( | |
private dynamicFacadeService: DynamicFacadeService, | |
private store: Store<any>, | |
) { | |
this.todoFacade = this.dynamicFacadeService.getFacade<Todo>('Todo'); | |
this.todos$ = this.todoFacade.entities$; | |
} | |
addTodo(event: KeyboardEvent): void { | |
if (event.keyCode !== 13) { return; } | |
const todo: Todo = { | |
id: uuid(), | |
text: this.todoInput.nativeElement.value, | |
}; | |
this.store.dispatch(this.todoFacade.actions.addOne(todo)); | |
this.todoInput.nativeElement.value = ''; | |
} | |
removeTodo(todo: Todo): void { | |
this.store.dispatch(this.todoFacade.actions.removeOne(todo.id)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment