Last active
June 7, 2019 04:29
-
-
Save jonathanwoahn/c4c8379798210f8f0e14e40272c8ca42 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
@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$; | |
this.store.dispatch(this.todoFacade.actions.load(undefined)); | |
} | |
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