Created
February 5, 2021 10:25
-
-
Save kubk/d9d496271ea76f0da85d67530ed5ef28 to your computer and use it in GitHub Desktop.
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 ListStore<T> { | |
isLoading = false; | |
list: T[] = []; | |
constructor(loadList: () => Promise<T[]>) { | |
makeAutoObservable(this) | |
} | |
loadList() { | |
this.isLoading = true; | |
loadList() | |
.then(action((data) => this.list = data)) | |
.finally(action(() => this.isLoading = false)) | |
} | |
} | |
const userListStore = new ListStore<User>(() => api.loadUsers()); | |
const postListStore = new ListStore<Post>(() => api.loadPosts()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment