是否存在修改可观察对象的 RxJS 运算符?

Are there RxJS operators that modify the observable?

本题仅供学习,不解决具体问题(如有需要请移至相应版块)

我正在学习 RxJS 库中的管道运算符。在此站点 (https://rxjs.dev/guide/operators) 中,它区分了管道运算符和创建者运算符。

它定义管道运算符如下:

A Pipeable Operator is a function that takes an Observable as its input and returns another Observable. It is a pure operation: the previous Observable stays unmodified.

并且它定义了创建者操作符如下:

Creation Operators are the other kind of operator, which can be called as standalone functions to create a new Observable. For example: of(1, 2, 3) creates an observable that will emit 1, 2, and 3, one right after another.

但这让我想知道:是否有这样一个运算符可以修改它作为输入获得的可观察对象并 returns 作为输出?我还没有遇到过这样的事情。有没有这样的运营商不存在的原因?这样的运算符会导致什么样的不良行为?

你可以把pipable操作看作是一系列的函数执行,大部分时候不需要修改upstream函数。我们感兴趣的是在我们继续进行时转换数据并添加自定义操作

fn(fn2(fn3(...)))

如果在任何情况下你想修改上游行为,上游可观察对象必须设计为允许这种情况,例如使用函数工厂让用户添加中间件

例如

const interceptor=()=>{...}
const getUpstreanFn=(middleware)=>(param)=>{ middleware()......}
const upstreamFn=getUpstreamFn(middleware)