Created
March 1, 2018 11:15
-
-
Save piotr-galas/a97997f41866da86ef687b5566176bd8 to your computer and use it in GitHub Desktop.
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
class A{ | |
saveArea(callback){ | |
const {t} = this.props; | |
new Api('/nurses/area').post(this.prepareData()) | |
.then(response => { | |
if(response.status === 200){ | |
response.json().then(json => { | |
this.setState({ | |
popupTitle: t('area.success.title'), | |
popupDescription: t('area.success.description'), | |
popupVisibility: true | |
}); | |
callback(,,,) | |
}) | |
}else if(response.status === 422){ | |
this.setState({ | |
popupTitle: t('area.failure.title'), | |
popupDescription: t('area.failure.description'), | |
popupVisibility: true | |
}); | |
} | |
}) | |
} | |
} | |
const a = new A() | |
a.saveArea(() => {...}) #undefined | |
############################################################################################################### | |
class A{ | |
async saveArea(){ | |
const {t} = this.props; | |
const response = await new Api('/nurses/area').post(this.prepareData()) | |
if(response.status === 200){ | |
const json = await response.json() | |
this.setState({ | |
popupTitle: t('area.success.title'), | |
popupDescription: t('area.success.description'), | |
json: json, | |
popupVisibility: true | |
}); | |
}else if(response.status === 422){ | |
this.setState({ | |
popupTitle: t('area.failure.title'), | |
popupDescription: t('area.failure.description'), | |
popupVisibility: true | |
}); | |
} | |
return json | |
} | |
} | |
async function init(){ | |
const a = new A() | |
const result = a.saveArea()((result) => {...}) #Promise | |
} | |
init() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment