Ngxs-呼叫Angular服务:良好做法? [英] Ngxs - Call an Angular service : good practices?

查看:166
本文介绍了Ngxs-呼叫Angular服务:良好做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用ngxs时,我的应用程序应该做什么:

When I use ngxs what should my app do:

  • 我的组件调用服务,并且该服务使用以下命令调度操作 结果作为有效载荷?
  • 我的组件调度一个动作,而我的 国家打电话给该服务?
  • my component calls a service and the service dispatches an action with the result as the payload?
  • my component dispatches an action and my State calls the service?

推荐答案

我的观点是,分派操作本身应该是不可变的,不能用于返回结果.取而代之的是,有兴趣知道结果的客户端(通常是操作导致的状态改变)应该订阅状态改变.请注意,NGXS是CQRS实现.

My opinion is that the Dispatched Action should itself be immutable and not to be used to return result. Instead, client interested to know result (usually in state change cause by an Action) should subscribe to the state change. Note that NGXS is a CQRS implementation.

这篇关于Ngxs-呼叫Angular服务:良好做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆