Created
May 28, 2019 17:55
-
-
Save artberri/83918cd4672c45b79a8b813f329403cf 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 { 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