rxjs - 是否有修改 observable 的 RxJS 操作符?
问题描述
这个问题是为了学习目的,而不是为了解决一个特定的问题(如果需要,请把它移到适当的部分)。
我正在学习 RxJS 库中的管道运算符。在此站点 ( https://rxjs.dev/guide/operators ) 上,它区分了可管道操作符和创建者操作符。
它定义了可管道操作符,如下所示:
Pipeable Operator 是一个将 Observable 作为其输入并返回另一个 Observable 的函数。这是一个纯粹的操作:之前的 Observable 保持不变。
它定义了创建者操作符如下:
Creation Operators 是另一种运算符,可以作为独立函数调用以创建新的 Observable。例如: of(1, 2, 3) 创建一个 observable,它将一个接一个地发出 1、2 和 3。
但这让我想知道:是否有这样的运算符可以修改它作为输入获得的可观察对象并将其作为输出返回?我还没有遇到过这样的事情。有没有这样的运营商不存在的原因?这样的操作员会导致什么样的不良行为?
解决方案
You can see pipable operation as a series of function execution, in most of the time there's no need for modifying the upstream function. What we interest in is transforming data and add custom operation as we proceed down the stream
fn(fn2(fn3(...)))
if in any case you want to modify upstream behavior, the upstream observable has to be designed to allow such case, for instance use a function factory to let user add an middleware
e.g
const interceptor=()=>{...}
const getUpstreanFn=(middleware)=>(param)=>{ middleware()......}
const upstreamFn=getUpstreamFn(middleware)
推荐阅读
- java - 是否可以从序列化的 kryo 对象中提取单个字段值?
- javascript - 我可以为私人日历应用 Freebusy 查询(来自 Google Calendar API)吗?
- spring - JSF/DeltaSpike/Weld CDI 的春季会议没有持续
- ssrs-2008 - 差距报告生成器,之间没有文字
- javascript - 使用 rel="stylesheet/something" 将 LINK 元素附加到 DOM 时出现静默错误
- ibm-cloud-storage - 从 IBM Cloud Object Storage 流式传输数据
- google-apps-script - Google Script - 无法从一张纸复制到另一张纸
- log4net - log4net RollingFileAppender 在重新启动应用程序后意外覆盖翻转文件
- python - 在订购参数化测试时访问具有类范围的 pytest 夹具参数
- amazon-web-services - 气流在 ECS 中的多个容器中运行。在所有气流组件之间共享 DAGS 的简单/优雅方式?