Ngxs 使用selectdecorator而不是selectmethod有什么好处吗?

Ngxs 使用selectdecorator而不是selectmethod有什么好处吗?,ngxs,Ngxs,看起来select的类型更安全,因为如果state.animals将其类型更改为number[]animalsWithMethod$也会更改它,但是animalsWithDecorator$仍然是字符串[]。一些优点如下 因此,第二种方法更适用于: 有程序选择器的 只选择一次状态或其一部分,而不连续观察 单元测试 OP询问了Select decorator的优点,所以您回答了相反的问题。另外,第二点是错误的:无论是选择装饰还是商店。只选择一次。这就是您将使用store.selectSnapsho

看起来select的类型更安全,因为如果state.animals将其类型更改为number[]animalsWithMethod$也会更改它,但是animalsWithDecorator$仍然是字符串[]。

一些优点如下

因此,第二种方法更适用于:

有程序选择器的 只选择一次状态或其一部分,而不连续观察 单元测试
OP询问了Select decorator的优点,所以您回答了相反的问题。另外,第二点是错误的:无论是选择装饰还是商店。只选择一次。这就是您将使用store.selectSnapshot或store.selectOnce的原因。
@Select(state => state.animals) 
animalsWithDecorator$: Observable<string[]>;
animalsWithMethod$ = this.store.select(state => state.animals);