Skip to content

Instantly share code, notes, and snippets.

@jonathanwoahn
Last active June 7, 2019 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanwoahn/c4c8379798210f8f0e14e40272c8ca42 to your computer and use it in GitHub Desktop.
Save jonathanwoahn/c4c8379798210f8f0e14e40272c8ca42 to your computer and use it in GitHub Desktop.
@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