Promise 包装
定制弹框-

一、把任何异步操作包装成promise
1、假设需求:
(1)用户点击按钮,弹出确认窗体。
(2)用户确认和取消有不同的处理。
let confirm = popupManager.confirm('您确定么');
confirm.promise
.then(() => {
// do confirm staff
})
.catch(() => {
// do cancel staff
})
// 窗体的构造函数
class Confirm{
constructor() {
this.promise = new Promise((resolve, reject) => {
this.confirmButton.onClick = resolve;
this.cancelButton.onclick = reject;
})
}
}
一、把任何异步操作包装成promise
1、假设需求:
(1)用户点击按钮,弹出确认窗体。
(2)用户确认和取消有不同的处理。
let confirm = popupManager.confirm('您确定么');
confirm.promise
.then(() => {
// do confirm staff
})
.catch(() => {
// do cancel staff
})
// 窗体的构造函数
class Confirm{
constructor() {
this.promise = new Promise((resolve, reject) => {
this.confirmButton.onClick = resolve;
this.cancelButton.onclick = reject;
})
}
}