Skip to content

Instantly share code, notes, and snippets.

@mweststrate
Last active May 24, 2016 20:28
Show Gist options
  • Save mweststrate/78d857d3ebf95c06e5b4fcf68bae869b to your computer and use it in GitHub Desktop.
Save mweststrate/78d857d3ebf95c06e5b4fcf68bae869b to your computer and use it in GitHub Desktop.
MobX store with actions
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