@Miki8887
Front-end разработчик

Как убрать вложенность промисов?

Здравствуйте, подскажите, как убрать вложенность промисов в коде?
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
       }
   })
})
  • Вопрос задан
  • 180 просмотров
Решения вопроса 1
@SeaBreeze876
Front-end разработчик
вот так
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;
    }
});
Ответ написан
Пригласить эксперта
Ответы на вопрос 2
@givemoneybiatch
Немного веб, немного гейм
Переписать на async/await ?
Ответ написан
SergeyEgorov
@SergeyEgorov
Веб разработчик
Когда в приложении есть
store
, можно на его события подписать обработчики и запускать поведение, глядя на изменения в содержимом хранилища.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы