Created
September 12, 2016 04:39
-
-
Save davelosert/e29c0dc759aa55722ed1b78dda4c6de8 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
interface ApiRepository { | |
getTodos(): Promise<Todo[]>; | |
getTodoById(id: number): Promise<Todo> | |
} | |
class HttpApiRepository implements ApiRepository { | |
getTodos() { | |
return http.get('/todos'); | |
} | |
getTodoById(id: number) { | |
return http.get(`/todos/${id}`); | |
} | |
} | |
class LocalStorageApiRepository implements ApiRepository { | |
getTodos() { | |
return Promise.resolve(localStorage.todos); | |
} | |
getTodoById(id: number) { | |
let todo = localStorage.todos.find((todo) => todo.id === id); | |
return Promise.resolve(todo); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment