0

在我的一种状态下,我不能使用@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行动来处理这种情况?

4

1 回答 1

0

可能与这个未解决的问题有关。该库与 Redux 开发工具不兼容。我相信 NGXS 正计划发布它自己的开发工具。

于 2018-12-05T11:54:19.497 回答