Below is a method that is within an ES2015 class.
It cannot be an arrow function because it is an async function.
But since it is not an arrow function, "this" is not in scope so I cannot do things like setstate.
Can someone please suggest how I can get this into scope? thanks!
async doSubmit(email_address, password) {
this.setState({isSubmitting: true, error: null})
try {
let data = await this.props.app.server.doSignIn(email_address, password)
} catch (jqXHR) {
let errorType = (jqXHR.status >= 400 && jqXHR.status < 500) ? 'application' : 'system'
let errorMessage = (errorType === 'application') ? jqXHR.responseJSON.description : jqXHR.error
this.setState({error: errorMessage, isSubmitting: false})
}
// following a signin event make sure the user image changes
this.props.app.reloadProfileImages()
try {
await this.props.app.initializeClouds()
} catch (err) {
xog('err', err)
this.setState({error: errorMessage, isSubmitting: false})
}
this.postSignIn(data)
}