Last active
May 24, 2016 20:28
-
-
Save mweststrate/78d857d3ebf95c06e5b4fcf68bae869b to your computer and use it in GitHub Desktop.
MobX store with actions
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
export class ContactStore { | |
@observable contacts = []; | |
@observable pendingRequestCount = 0; | |
@computed get isLoading() { | |
return this.pendingRequestCount > 0; | |
} | |
@action createRandomContact() { | |
this.pendingRequestCount++; | |
superagent.get('https://randomuser.me/api/').end( | |
action("createRandomContact-callback", (error, results) => { | |
const contact = new Contact(results[0]) | |
this.contacts.push(contact); | |
this.pendingRequestCount--; | |
}) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment