A
A
Anna Shatkovskaya2018-12-25 05:57:39
JavaScript
Anna Shatkovskaya, 2018-12-25 05:57:39

How to remove nesting of promises?

Hello, tell me how to remove the nesting of promises in the code?

this.$store.dispatch(GET_ORDER, order).then( () => {
  let data = {}
  data.id = order
  data.order = {status, comment, totalPrice, paymentMethod}
  this.$store.dispatch(PATCH_ORDER, data).then( () => {
      if (this.responseServer){
              this.$refs.modalSend.hide()
              this.status=1
      }
   })
}, () => {
   this.$store.dispatch(POST_ORDER, {id, status, comment, totalPrice, paymentMethod}).then( () => {
       if (this.responseServer){
          this.$refs.modalSend.hide()
          this.status = 1
       }
   })
})

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anatoly Zharov, 2018-12-25
@Miki8887

like this

this.$store.dispatch(GET_ORDER, order).then(() => {
    let data = {};
    data.id = order;
    data.order = {
        status,
        comment,
        totalPrice,
        paymentMethod
    };
    return this.$store.dispatch(PATCH_ORDER, data);
}).catch(() => {
    return this.$store.dispatch(POST_ORDER, {
        id,
        status,
        comment,
        totalPrice,
        paymentMethod
    });
}).then(() => {
    if (this.responseServer) {
        this.$refs.modalSend.hide();
        this.status = 1;
    }
});

L
Ler Den, 2018-12-25
@givemoneybiatch

Rewrite to async/await ?

S
Sergey Egorov, 2018-12-25
@SergeyEgorov

When the application has

store
, you can subscribe handlers to its events and run the behavior, looking at changes in the contents of the store.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question