如何收听 NGXS 中的多个操作?

发布于 01-17 23:14 字数 323 浏览 4 评论 0原文

我正在将应用程序从NGRX转换为NGXS。在NGRX中,我可以“聆听”多种动作,并对它们做出适当的反应。如何使用NGXS来实现这一目标?

在ngrx中,我可能有以下内容,

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

因为我在ngxs中看到@Action装饰者可以接受和动作类型的 效果绘制方法时的动作类型。

I'm in the process of converting an application from NgRX to NgXs. In NgRx, I could 'listen' to multiple actions in an effect and react appropriately to them. How can I accomplish this using NgXS?

In NgRx, I may have something like the following in an effect

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

I see in NgXs that the @Action decorator can accept and array of action types, but I'm confused on how get the value from the multiple action types when delcaring the method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

莫言歌2025-01-24 23:14:48

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

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

In NGXS, you can listen to multiple actions via @Action decorator, like the following:

@Action([fromCustomers.pageLoaded, fromCustomers.pageRefreshed])
pageLoadedOrRefreshed(
  ctx: StateContext<YOUR_STATE_MODEL>,
  payload: fromCustomers.pageLoaded | fromCustomers.pageRefreshed
) {
  // do some stuff here...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文