Created
November 2, 2018 10:51
-
-
Save LayZeeDK/96fea25f513a56b7b39d3f0745dbdeb3 to your computer and use it in GitHub Desktop.
TypeScript: Edit todo item view using the new keyword
This file contains hidden or 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
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