1mobx.configure({ enforceActions: "observed" })
2
3class Store {
4 @observable githubProjects = []
5 @observable state = "pending" // "pending" / "done" / "error"
6
7 @action
8 fetchProjects() {
9 this.githubProjects = []
10 this.state = "pending"
11 fetchGithubProjectsSomehow().then(this.fetchProjectsSuccess, this.fetchProjectsError)
12 }
13
14 @action.bound
15 fetchProjectsSuccess(projects) {
16 const filteredProjects = somePreprocessing(projects)
17 this.githubProjects = filteredProjects
18 this.state = "done"
19 }
20
21 @action.bound
22 fetchProjectsError(error) {
23 this.state = "error"
24 }
25}
26