import { observable, action, computed } from 'mobx'; export default class EmployeeStore { @observable employees = []; @observable selectedEmployee = {}; @observable isLoading = false; @observable newEmployee = {}; constructor(context) { this.http = context.http; this.context = context; } @action getAll() { this.isLoading = true; return this.http.get("employees") .then(res => { this.isLoading = false; this.employees = res; }) .catch(err => { this.isLoading = false; throw err; }) } @action create(data) { this.isLoading = true; return this.http.post("employees", data) .then(res => { this.isLoading = false; }) .catch(err => { this.isLoading = false; }); } }