我需要通过返回Observable
来验证诺言,所以碰巧只有在“打开对话框”中单击“确认”时才返回此Observable。
我需要知道promise
之外是否已完成callback
。
我该如何以最佳方式做到这一点?
return dialog.afterClose.pipe(
switchMap((reauthenticated) => {
if (reauthenticated) {
const confirmDelete = this._modalService.warning({
nzTitle: 'Do you really want to delete this user?',
nzContent: `When a user is deleted all related data
it will be lost without any option and retrieve them.`,
nzOkText: 'Confirm',
nzCancelText: 'Cancel',
nzOnCancel: () => {
confirmDelete.destroy();
},
nzOnOk: () => {
this._message.info('User deleted success.', {
nzDuration: 5000,
nzPauseOnHover: true,
nzAnimate: true
});
// Only returned if you click Confirm.
return Observable.fromPromise(userRef.delete());
}
});
// I need to return if the promise was resolved
// here instead of returning only when I clicked Confirm.
setTimeout(() => {
confirmDelete.destroy();
}, 15000);
} else {
throw new Error('User not authenticated');
}
})
);