首页 > 解决方案 > @ngrx with API, how do I recognise differences in results?

问题描述

I've stumbled into a problem and I feel that it's getting worse as time goes. The problem I'm having is that API-calls might give same results but with slightly different attributes, and I'm having a problem to figure out how to implement this with @ngrx.

Example:

So, is there a smart way to get round this? :)

标签: angularlaravelapistatengrx

解决方案


对此有两种可能的解决方案。最简单的方法是忽略这些是“相同”数据这一事实,并将两组不同的活动数据(一组丰富,一组不丰富)作为完全独立的事物存储在状态存储中。

另一种选择是重构 API 以提供一个端点,该端点仅返回活动的额外类别数据(例如/api/su/activitiycategories),然后如果您已经拥有该状态中的基本活动数据,则仅调用该第二个端点。然后,您将使用额外的类别数据更新状态数据。

您可能需要在状态中存储一个标志(例如“activitiesEnrichedWithCategories”)来控制您是否需要进行该调用。在基本活动不存在的情况下,您需要同时调用这两个函数来获取丰富的数据,或者/api/su/activitycategories/改为调用端点。

第二个选项实现起来要复杂得多,但如果有很多活动,那么额外的努力可能是值得的。


推荐阅读