net*_*djw 5 rxjs typescript rxjs6
我的项目我需要将我的分页器的pageSize值(每页项目数)与以前的值进行比较,如果新值更高,那么我需要从存储中加载数据。但如果它不是更高,我不想做任何事情。
例如在这段代码中:
export class MyComponent {
paginatorPageSize: BehaviorSubject<number> = new BehaviorSubject<number>(10);
// ...
savePageSettings() {
this.pageService.save().pipe(
map((result: any) => {
// ...
}),
tap(() => this.anyCode.here()),
switchMap((result: any) => {
// ...
}),
switchMap(() => {
const previousPageSize = ??? // <--- here how can I get the prevoius value of paginatorPageSize?
if (previousPageSize >= this.paginatorPageSize.value) {
return this.pageService.getAll();
}
return of(null)
})
).subscribe();
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法获得 RxJS Subject / BehavioSubject 或任何类型的主题的先前发出的值?
bub*_*les 14
只需使用pairwise运算符。
savePageSettings() {
this.pageService.save().pipe(
map((result: any) => {
// ...
}),
tap(() => this.anyCode.here()),
switchMap((result: any) => {
// ...
}),
pairwise(),
switchMap(([oldResult, newResult]) => {
const previousPageSize = oldResult.pageSize;
if (previousPageSize >= this.paginatorPageSize.value) {
return this.pageService.getAll();
}
return of(null)
})
).subscribe();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4243 次 |
| 最近记录: |