如何修复 NgRx Effects 中的执行顺序?
How to fix order of execution in NgRx Effects?
效果应该采用负载并在对话框中显示。
对话框关闭后,它应该 post 一些东西并派发一个新动作。
问题是,在我关闭对话框之前正在调度操作。
@Effect()
bookTable$ = this.actions$.pipe(
ofType(BookTableActionTypes.BOOK_TABLE),
map(action => action.payload),
exhaustMap((booking: Booking) => this.dialog.open(BookTableDialogComponent, {
width: this.window.responsiveWidth(),
data: booking.booking,
}).afterClosed()
.pipe( () => this.bookTableService.postBooking(booking),
map((res: any) => new BookTableSuccess(res)),
catchError(error => of(new BookTableFail({error: error})))
)));
.pipe( () => this.bookTableService.postBooking(booking),
map((res: any) => new BookTableSuccess(res)),
catchError(error => of(new BookTableFail({error: error})))
)));
以上代码只能在对话框关闭后执行。
您的 pipe
中似乎缺少用于调用 API 的 rxjs 运算符。尝试 switchMap
更改 observable。
.pipe(
switchMap(() => this.bookTableService.postBooking(booking)),
map((res: any) => new BookTableSuccess(res)),
catchError(error => of(new BookTableFail({error: error})))
);
效果应该采用负载并在对话框中显示。 对话框关闭后,它应该 post 一些东西并派发一个新动作。
问题是,在我关闭对话框之前正在调度操作。
@Effect()
bookTable$ = this.actions$.pipe(
ofType(BookTableActionTypes.BOOK_TABLE),
map(action => action.payload),
exhaustMap((booking: Booking) => this.dialog.open(BookTableDialogComponent, {
width: this.window.responsiveWidth(),
data: booking.booking,
}).afterClosed()
.pipe( () => this.bookTableService.postBooking(booking),
map((res: any) => new BookTableSuccess(res)),
catchError(error => of(new BookTableFail({error: error})))
)));
.pipe( () => this.bookTableService.postBooking(booking),
map((res: any) => new BookTableSuccess(res)),
catchError(error => of(new BookTableFail({error: error})))
)));
以上代码只能在对话框关闭后执行。
您的 pipe
中似乎缺少用于调用 API 的 rxjs 运算符。尝试 switchMap
更改 observable。
.pipe(
switchMap(() => this.bookTableService.postBooking(booking)),
map((res: any) => new BookTableSuccess(res)),
catchError(error => of(new BookTableFail({error: error})))
);