Skip to content

Instantly share code, notes, and snippets.

@artberri
Created May 28, 2019 17:55
Show Gist options
  • Save artberri/83918cd4672c45b79a8b813f329403cf to your computer and use it in GitHub Desktop.
Save artberri/83918cd4672c45b79a8b813f329403cf to your computer and use it in GitHub Desktop.
import { Service, BasePresenter, Mediator } from '../framework';
import { ITodoView } from '../views';
import { AppState, ToggleTodoCommand, RemoveTodoCommand, EditTodoCommand } from '../model';
@Service()
export class TodoPresenter extends BasePresenter<ITodoView> {
constructor(
private readonly state: AppState,
private readonly mediator: Mediator
) {
super();
}
protected init(): void {
this.view.setViewMode();
this.state.subscribe(() => {
this.view.todo.isCompleted ? this.view.completeTodo() : this.view.activateTodo();
});
}
public editTodo(title: string): void {
this.mediator.send(new EditTodoCommand({
todo: this.view.todo,
title
}));
this.view.setViewMode();
}
public removeTodo(): void {
this.mediator.send(new RemoveTodoCommand(this.view.todo));
}
public toggleTodo(): void {
this.mediator.send(new ToggleTodoCommand(this.view.todo));
}
public setEditMode(): void {
this.view.setEditMode();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment