我如何在 NGXS 中收听多个操作?

How can I listen to multple actions in NGXS?

我正在将应用程序从 NgRX 转换为 NgXs。在 NgRx 中,我可以 'listen' 对一个效果中的多个动作做出适当的反应。我如何使用 NgXS 完成此操作?

在 NgRx 中,我可能会有类似下面的效果

this.actions$.pipe(
 ofType(fromCustomers.pageLoaded),
 ofType(fromCustomers.pageRefreshed)
)

我在 NgXs 中看到 @Action 装饰器可以接受动作类型数组,但我对如何在调用方法时从多个动作类型中获取值感到困惑。

在 NGXS 中,您可以通过 @Action 装饰器监听多个动作,如下所示:

@Action([fromCustomers.pageLoaded, fromCustomers.pageRefreshed])
pageLoadedOrRefreshed(
  ctx: StateContext<YOUR_STATE_MODEL>,
  payload: fromCustomers.pageLoaded | fromCustomers.pageRefreshed
) {
  // do some stuff here...
}