如何在不影响父流的 return 值的情况下获取另一个可观察值的值
How do I obtain the value of another observable, without it affecting the parent stream's return value
我想做一个http请求,不影响父流的值:
const mockHttpCall = () => of('http-result');
of('result1')
.pipe(
switchMap(() =>
mockHttpCall().pipe(
tap((innerResult) => console.log('innerResult: ', innerResult))
)
)
)
ie:这个流应该 return result1
而不是 http-result
.
我该怎么做?我认为使用 withLatestFrom
和 map
可能会恢复到原始值,但不确定这是否是个好主意。
Stackblitz:https://stackblitz.com/edit/rxjs-lrcuse?devtoolsheight=60&file=index.ts
你可以map
回到原来的值:
of('result1')
.pipe(
switchMap((result) =>
mockHttpCall().pipe(
tap((innerResult) => console.log('innerResult: ', innerResult)),
map(() => result)
)
)
)
.subscribe(console.log)
我想做一个http请求,不影响父流的值:
const mockHttpCall = () => of('http-result');
of('result1')
.pipe(
switchMap(() =>
mockHttpCall().pipe(
tap((innerResult) => console.log('innerResult: ', innerResult))
)
)
)
ie:这个流应该 return result1
而不是 http-result
.
我该怎么做?我认为使用 withLatestFrom
和 map
可能会恢复到原始值,但不确定这是否是个好主意。
Stackblitz:https://stackblitz.com/edit/rxjs-lrcuse?devtoolsheight=60&file=index.ts
你可以map
回到原来的值:
of('result1')
.pipe(
switchMap((result) =>
mockHttpCall().pipe(
tap((innerResult) => console.log('innerResult: ', innerResult)),
map(() => result)
)
)
)
.subscribe(console.log)