Skip to content

Instantly share code, notes, and snippets.

@alonbardavid
Created October 9, 2019 17:42
Show Gist options
  • Save alonbardavid/5e7f7403c0ab53fe533ee52b6d19286b to your computer and use it in GitHub Desktop.
Save alonbardavid/5e7f7403c0ab53fe533ee52b6d19286b to your computer and use it in GitHub Desktop.
Why use mobx gist 2
class ResourceStore {
@observable
resources = {};
@action("REQUEST_RESOURCE")
requestResource(id) {
this.resources[id] = {loading:true};
return fetch(`url/resource/${id}`)
.then(response=>response.json())
.then(action("REQUEST_RESOURCE_SUCCESS",
resource=>{this.resources[id] = {loading:false,resource};}))
.catch(action("REQUEST_RESOURCE_FAILURE",
error=>{this.resources[id] = {loading:false,error};}))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment