gpt4 book ai didi

rxjs - 仅从 Store 中选择最近的值

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

对 SO 的一些搜索让我相信没有好的(简单的)方法可以解决标题中的问题。以下线程都非常相关:

Get current state in ngrx

Getting current state in ngrx

Get current ngrx state without subscribe

Using ngrx to obtain store's current state once

How to get current value of State object with @ngrx/store?

从最后一个线程 ^ 看来,实现这一点的唯一方法是使用 withLatestFrom()combineLatest() .

不可能是以下情况是确保您只收到 1 件商品并且该商品是最新商品的唯一方法:

of('terribleLatestValueHack').pipe(
withLatestFrom(this.store.select(itemSelector))
).subscribe((stringAndItem: [string, Item]) => {
const [, item] = stringAndItem;
// do something with item
});

鉴于从商店中选择一件最近的商品
  • 是一个(非常)简单的用例
  • 似乎是一个要求很高的功能

  • 我真的很想知道为什么现有的支持(显然有 - 在 NGRX v2 - 根据 How to get current value of State object with @ngrx/store? )已被删除。

    最佳答案

    我忘了补充,我的印象是 store.select(...).pipe(first())不会从商店退回最新的商品。但似乎确实如此,它返回的任何错误值的原因在于我们自己的代码。
    store.select(...).pipe(first())确实就是这样做的:从 Store 返回一个当前项目(并完成 Observable )。

    关于rxjs - 仅从 Store 中选择最近的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51595865/

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