我有一个应用,其中如果某项操作失败(BiographyUpdate
),我想为用户提供使用烤面包来重试该操作的选项。当用户消除烤面包时,如果他们接受,则应重试该操作:
@Effect()
public BiographyUpdate: Observable<any> = this._actions.pipe(
ofType(AuthActionTypes.BIOGRAPHY_UPDATE),
map((action: BiographyUpdate) => action.payload),
switchMap(biography => this._profile.updateBiography(`${Environment.Endpoint}/users/update`, biography)
.map(() => new BiographyUpdateSuccess())
.catch(() => Observable.of(new BiographyUpdateFailure(biography)))
)
);
@Effect({ dispatch: false })
public BiographyUpdateFailure: Observable<any> = this._actions.pipe(
ofType(AuthActionTypes.BIOGRAPHY_UPDATE_FAILURE),
map((action: BiographyUpdateFailure) => action.payload),
tap(payload => {
const toast = this._toast.create({
message: "Update failed.",
...ToastDefaults,
duration: 3000,
closeButtonText: 'Retry'
});
toast.onDidDismiss(() => new BiographyUpdate(payload));
toast.present();
})
);
由于该操作是通过UI的回调调用的,所以我认为这种方式可以工作,但是该操作不再被调用。有什么建议吗?
答案 0 :(得分:0)
弄清楚了,我需要分派动作。这是我更新的失败操作:
为清楚起见,我仅在用户关闭Toast时分派该动作,而不是在自动关闭Toast时分派该动作。这不是Ionic记录的,但是有可能。
@Effect({ dispatch: false })
public BiographyUpdateFailure: Observable<any> = this._actions.pipe(
ofType(AuthActionTypes.BIOGRAPHY_UPDATE_FAILURE),
map((action: BiographyUpdateFailure) => action.payload),
tap(payload => {
const toast = this._toast.create({
message: "Update failed.",
...ToastDefaults,
duration: 3000,
closeButtonText: 'Retry'
});
toast.onDidDismiss((data, role) => {
if (role === 'close')
return this._store.dispatch(new BiographyUpdate(payload));
});
toast.present();
})
);