在此文章有关NGRX 5 medium.com(2月13日),他们目前pipeable选择.这让我想起了rxjs中有关可管理选择器的内容,它们不仅可以通过'纯函数,兄弟'来证明,而且还可以通过函数的方式在不同的情况下声明和重用,而不必每次都使用map来调用letable功能.
所以我同意,这在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'));
}
}
Run Code Online (Sandbox Code Playgroud)
所以我们现在打电话store.pipe(select(...));
而不是store.select(Selector);- 收益在哪里?为什么我应该更改我的代码以使用此行为或至少开始使用可管理选择器?
| 归档时间: |
|
| 查看次数: |
529 次 |
| 最近记录: |