Skip to content

Instantly share code, notes, and snippets.

@LayZeeDK
Created November 2, 2018 10:51
Show Gist options
  • Save LayZeeDK/96fea25f513a56b7b39d3f0745dbdeb3 to your computer and use it in GitHub Desktop.
Save LayZeeDK/96fea25f513a56b7b39d3f0745dbdeb3 to your computer and use it in GitHub Desktop.
TypeScript: Edit todo item view using the new keyword
class EditTodoItemView {
todoItem: TodoItem;
onInitialize(id: string): Promise<void> {
return this.readTodoItem(id)
.then(todoItem => this.todoItem = todoItem)
.then(() => undefined);
}
readTodoItem(id: string): Promise<TodoItem> {
return fetch("/todo/" + id)
.then((response: HttpResponse) => response.json())
.then(json => new TodoItem(json));
}
saveTodoItem(): Promise<void> {
return this.todoItem.save();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment