July 2018
Beginner
236 pages
5h 34m
English
In the previous, simple example, we only had to wrap two segments of the code in runInAction(). That was quite straightforward and did not involve too much effort. However, there will be cases where you will have multiple await statements within a function. Consider the login() method shown next, which performs an action involving multiple awaits:
import { observable, action } from 'mobx';class AuthStore { @observable loginState = ''; @action.bound async login(username, password) { this.loginState = 'pending'; await this.initializeEnvironment(); this.loginState = 'initialized'; await this.serverLogin(username, password); this.loginState = 'completed'; await this.sendAnalytics(); this.loginState = 'reported'; } async initializeEnvironment ...
Read now
Unlock full access