为什么秋田查询直接在组件中访问
Why are Akita Queries accessed directly in components
我正在学习 Akita 以将状态管理添加到 Angular 应用程序。当查看 architecture diagram in the Akita documentation and examples such as this one on the Akita GitHub repo I see that the Query is accessed directly in components. I was surprised to see this because I expected that the state management part of an application would be hidden behind the services and abstracted away from the consumers, i.e. components. Unlike the Query, the Store is hidden behind the Service 而不是直接在组件中访问时。在我看来,如果查询隐藏在服务后面,就像商店隐藏在服务后面一样,那么消费者只需要为每个数据源导入一件事,即服务。
所以我的问题是为什么 Akita 要我们直接在组件中访问 Query 而不是 Store?将查询隐藏在服务后面是否有缺点?
我在 Akita Gitter channel 中问了同样的问题,Akita 的作者 Netanel Basal 回答了我的问题如下:
There is no downside to do what you want. I already saw people that work like that, and it's totally valid. The Store is the data layer, and the component shouldn't know about it. It only should know how to get the data. That's why we inject the Query in the components.
我正在学习 Akita 以将状态管理添加到 Angular 应用程序。当查看 architecture diagram in the Akita documentation and examples such as this one on the Akita GitHub repo I see that the Query is accessed directly in components. I was surprised to see this because I expected that the state management part of an application would be hidden behind the services and abstracted away from the consumers, i.e. components. Unlike the Query, the Store is hidden behind the Service 而不是直接在组件中访问时。在我看来,如果查询隐藏在服务后面,就像商店隐藏在服务后面一样,那么消费者只需要为每个数据源导入一件事,即服务。
所以我的问题是为什么 Akita 要我们直接在组件中访问 Query 而不是 Store?将查询隐藏在服务后面是否有缺点?
我在 Akita Gitter channel 中问了同样的问题,Akita 的作者 Netanel Basal 回答了我的问题如下:
There is no downside to do what you want. I already saw people that work like that, and it's totally valid. The Store is the data layer, and the component shouldn't know about it. It only should know how to get the data. That's why we inject the Query in the components.