在 this medium.com 上关于 NGRX 5 的文章(2 月 13 日)他们提供了可管道选择器。这让我想起了在 rxjs 中阅读有关可管道选择器的内容,其中它们不仅可以通过“它的纯函数,兄弟”来证明,而且还可以通过函数可以在不同的情况下声明和重用的方式来证明,而无需每次都使用映射来调用可出租的功能。
所以我可以同意,这在 rxjs 中是一件好事,但为什么我们在 ngrx 中需要这个 - 用于选择器。链接的文章显示了以下示例:
import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
interface AppState {
count: number;
}
@Component({
selector: 'my-app',
template: `
<button (click)="increment()">Increment</button>
<div>Current Count: {{ count$ | async }}</div>
<button (click)="decrement()">Decrement</button>
<button (click)="reset()">Reset Counter</button>
`
})
export class MyAppComponent {
count$: Observable<number>;
constructor(private store: Store<AppState>) {
this.count$ = store.pipe(select('count'));
}
}
所以我们现在调用store.pipe(select(...));
而不是 store.select(Selector);
- yield 在哪里?为什么我应该更改我的代码以使用此行为或至少开始使用可管道选择器?
最佳答案
在 NgRx 7 中,此弃用已恢复 - see changelog .
关于NGRX 5 管道选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49790865/