Skip to content

Instantly share code, notes, and snippets.

@piotr-galas
Created March 1, 2018 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piotr-galas/a97997f41866da86ef687b5566176bd8 to your computer and use it in GitHub Desktop.
Save piotr-galas/a97997f41866da86ef687b5566176bd8 to your computer and use it in GitHub Desktop.
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