gpt4 book ai didi

angular - 为什么在组件中直接访问 Akita Queries

转载 作者:行者123 更新时间:2023-12-04 01:01:01 24 4
gpt4 key购买 nike

我正在学习 Akita 以向 Angular 应用程序添加状态管理。当看architecture diagram in the Akita documentation和示例,例如 this one on the Akita GitHub repo我看到 Query 是直接在组件中访问的。我很惊讶地看到这一点,因为我预计应用程序的状态管理部分会隐藏在服务后面,并从消费者(即组件)中抽象出来。与查询不同,the Store is hidden behind the Service而不是直接在组件中访问。在我看来,如果 Query 隐藏在 Service 后面,就像 Store 隐藏在 Service 后面一样,那么消费者只需要为每个数据源导入一件事,即服务。

所以我的问题是为什么 Akita 希望我们直接在组件中访问 Query 而不是 Store?将 Query 隐藏在服务背后是否有不利之处?

最佳答案

我在 Akita Gitter channel 中问了同样的问题,秋田的作者 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.

关于angular - 为什么在组件中直接访问 Akita Queries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58386304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com