缓存发射值可观察到的依赖性但不可观察的源
我目前正在实施一项新功能。该应用程序希望给卖方一个管理员可以看到各种东西。他们在仪表板上可以看到的一件事的一个例子是他们的最后10个订单。
该订单的API仅返回各种ID的数组(客户ID,产品ID,卖方ID等),以填充订单页面,我必须对每个订单进行3个不同的API调用,以使数据获取数据以呈现订单 现在,我必须创建一个与订单列表页面不同的仪表
板,我不想再次进行如此乏味的API调用。我想创建一个仪表板$可观察的,该仪表列表具有订购列表$的最后一个发射值,但我不希望订阅订单列表$的任何内容。 因此,当调用订单列表$时,它从服务器获得了最后的订单列表数据(我感觉不像订单列表一样敏感),当调用仪表板$时,获得订购列表$的最后发射值,如果订购列表$尚未发出任何值,然后仪表板$可以提出检索订单列表的请求。
I am currently implementing a new feature at work. The app wants to give sellers an admin where they can see various things. An example of one of the things they can see on their dashboard is their last 10 orders.
The order's API only returns an array of various ids (customer id, product id, seller id, etc) In order to populate the orders page, I have to make 3 different API call on each order to get the data to render on the order list page
Now that I have to create a dashboard that is different from the order list page, I do not want to make such a tedious API call again. I want to create a dashboard$ observable that has the last emitted value of orderList$ but I do not want anything subscribed to orderList$ to be cached.
So when orderList$ is called, it gets the lastest orderList data from the server (I do not feel something as sensitive as order list should be cached), when dashboard$ is called, get the last emitted value of orderList$ and if orderList$ has not emitted any values then dashboard$ can make a request to retrieve order list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在具有反应性状态时,我喜欢根据事件定义应该发生的事情。我的意思是,我将拥有一个
主题
,其中可以将值推入通知事件,从那里我们可以对这些事件做出反应。就您而言,这是您想要的想法:
因此,在管理员和仪表板页面上都可以重复使用此观察到的安全性。当然,在适当的情况下,您需要在两个主题上调用
下一个
,以便在需要时可以刷新订单。When working with a reactive state of mind, I like to define what should happen based on events. By this I mean that I'll have a
Subject
in which in can push values into to notify an event and from there we can react to these events.In your case, here's an idea for what you want:
So here it'd be safe to reuse this observable on both the admin and the dashboard page. Of course, you'll need to call
next
on the 2 subjects when appropriate so that the orders can be refreshed when they need to.