Rxjs 基于流值选择运算符
有一个数据源发出值0或1 如果0,我想通过switchMap操作符传递它 如果我想把它通过排气图操作员 我该怎么做Rxjs 基于流值选择运算符,rxjs,Rxjs,有一个数据源发出值0或1 如果0,我想通过switchMap操作符传递它 如果我想把它通过排气图操作员 我该怎么做 如果您想要切换操作符,那么您可能想要有两个不同的流 如果是这种情况,那么您可以使用filter操作符,并具有类似的功能 const source = from([0, 0, 0, 1, 1, 1]); const stream_0 = source.pipe( filter(val => val === 0), switchMap(value => {
如果您想要切换操作符,那么您可能想要有两个不同的流 如果是这种情况,那么您可以使用
filter
操作符,并具有类似的功能
const source = from([0, 0, 0, 1, 1, 1]);
const stream_0 = source.pipe(
filter(val => val === 0),
switchMap(value => {
return of("Operator switchMap, value: " + value);
})
)
const stream_1 = source.pipe(
filter(val => val === 1),
exhaustMap(value => {
return of('Operator exhaustMap, value: ' + value)
})
);
merge(stream_0, stream_1).subscribe(console.log);
如果您想要切换操作符,那么您可能想要有两个不同的流 如果是这种情况,那么您可以使用
filter
操作符,并具有类似的功能
const source = from([0, 0, 0, 1, 1, 1]);
const stream_0 = source.pipe(
filter(val => val === 0),
switchMap(value => {
return of("Operator switchMap, value: " + value);
})
)
const stream_1 = source.pipe(
filter(val => val === 1),
exhaustMap(value => {
return of('Operator exhaustMap, value: ' + value)
})
);
merge(stream_0, stream_1).subscribe(console.log);
我以这个结束(排气图在自定义操作员分页列表中)
this._baseSubject=new Subject();
这个._nextPageSubject=新主题();
此.\u items$=此.\u baseSubject.pipe(
开关映射((请求)=>{
返回此文件。_nextPageSubject.pipe(
startWith(要求),
分页列表(分页)
);
})
);
我以这个结束(排气图在自定义操作员分页列表中)
this._baseSubject=new Subject();
这个._nextPageSubject=新主题();
此.\u items$=此.\u baseSubject.pipe(
开关映射((请求)=>{
返回此文件。_nextPageSubject.pipe(
startWith(要求),
分页列表(分页)
);
})
);
this._baseSubject = new Subject<ListPaged>();
this._nextPageSubject = new Subject<ListPaged>();
this._items$ = this._baseSubject.pipe(
switchMap((req) => {
return this._nextPageSubject.pipe(
startWith(req),
paginateList(paginate)
);
})
);