可观察管道
Observable pipes
我对 observables 的管道有疑问
假设我有以下代码:
const skip$ = of(4);
const length$ = of(24);
const schoolId$ = of(1);
const source = combineLatest(skip$, length$, schoolId$).pipe(
map(([skip, length]) => `skip: ${skip}, length: ${length}`),
map(text => text ) // I need now schoolId, how can i get
);
在第二张地图中,我需要 schoolId。如果不这样做我怎么能得到 schoolId:
const source = combineLatest(skip$, length$, schoolId$).pipe(
map(([skip, length, schoolId]) => ({text: `skip: ${skip}, length: ${length}`, schoolId})),
map(text => `${text.text}, schoolId: ${text.schoolId}` )
);
这里有 stackblitz 可以尝试
与所有 ReactiveX 一样,您有很多选择。也许最接近你现在所拥有的是使用 withLatestFrom...
const source = combineLatest(skip$, length$).pipe(
map(([skip, length]) => (`skip: ${skip}, length: ${length}`)),
withLatestFrom(schoolId$),
map(([text, schoolId]) => `${text}, schoolId: ${schoolId}` )
);
我对 observables 的管道有疑问
假设我有以下代码:
const skip$ = of(4);
const length$ = of(24);
const schoolId$ = of(1);
const source = combineLatest(skip$, length$, schoolId$).pipe(
map(([skip, length]) => `skip: ${skip}, length: ${length}`),
map(text => text ) // I need now schoolId, how can i get
);
在第二张地图中,我需要 schoolId。如果不这样做我怎么能得到 schoolId:
const source = combineLatest(skip$, length$, schoolId$).pipe(
map(([skip, length, schoolId]) => ({text: `skip: ${skip}, length: ${length}`, schoolId})),
map(text => `${text.text}, schoolId: ${text.schoolId}` )
);
这里有 stackblitz 可以尝试
与所有 ReactiveX 一样,您有很多选择。也许最接近你现在所拥有的是使用 withLatestFrom...
const source = combineLatest(skip$, length$).pipe(
map(([skip, length]) => (`skip: ${skip}, length: ${length}`)),
withLatestFrom(schoolId$),
map(([text, schoolId]) => `${text}, schoolId: ${schoolId}` )
);