在我的一种状态下,我不能使用@Action(...)
注释,所以我想改用 actions$ 流,就像这样
@State(...)
export class MyState implements NgxsOnInit {
constructor(private actions$: Actions) {}
ngxsOnInit(ctx: StateContext<any>): void {
this.actions$.pipe(ofActionSuccessful(MyAsyncAction)).subscribe(() => {
console.log('SUCCESS');
});
this.actions$
.pipe(
ofActionDispatched(MyAsyncAction),
tap(() => console.log('DISPATCHED')),
delay(1000),
map(() => console.log('DONE')
.subscribe();
}
}
不幸的是,控制台中的日志看起来像“DISPATCHED”、“SUCCESS”然后是“DONE”。有没有办法在使用 actions$ 流时处理动作生命周期?还是我应该走“旧”的方式,然后使用专门的MyAsyncActionSuccess
行动来处理这种情况?