在NGRX中选择和没有选择之间有什么区别?

发布于 2025-01-20 23:24:19 字数 361 浏览 2 评论 0原文

当我订阅商店的状态时,我通常使用两种方法。 它们之间有什么区别吗(比如性能什么的)

constructor(private store : Store<MyState>){
    //1
    this.store.pipe(select(x=>x.myComplexObject)).subscribe(x=> {
        this.data = x;
    })
    //2
    this.store.subscribe(x=> {
        this.data = x.myComplexObject;
    })
}

I have two ways usually use when I subscribe to a state of a store.
Is it any difference between them (like performance or something)

constructor(private store : Store<MyState>){
    //1
    this.store.pipe(select(x=>x.myComplexObject)).subscribe(x=> {
        this.data = x;
    })
    //2
    this.store.subscribe(x=> {
        this.data = x.myComplexObject;
    })
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城孤痞 2025-01-27 23:24:19

两者都是一样的。
但是,我建议您搬到选择器,因为这些优点具有多个优点:

  • 可以将多个选择器组合起来
  • 易于测试
  • ,因为它是记忆

https://ngrx.io/guide/store/selectors

Both are the same.
But, I would suggest moving to selectors because these have several advantages:

  • multiple selectors can be combined
  • easy to test
  • performant because it's memoized

https://ngrx.io/guide/store/selectors

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文