Created
October 9, 2019 17:42
-
-
Save alonbardavid/5e7f7403c0ab53fe533ee52b6d19286b to your computer and use it in GitHub Desktop.
Why use mobx gist 2
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
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