Enhancing Subjects with Bidirectional Data Flow and Data Transformation #7378
Replies: 1 comment 1 reply
-
Ackchyually, what you are suggesting already works since RxJS v4 to v7: https://codesandbox.io/s/infallible-merkle-3n9kw8?file=/src/index.mjs This is because the official operators from RxJS actually "lift" the source, so the resulting observable inherits all the methods from the original source. However, this can't be done in Typescript since it can't know if an operator will or will not lift 🏋️, so the typescript definition says that a Unfortunately (for you), this behaviour is deprecated, and it's removed on v8. Here's the issue that discusses removing it #7201 and here's the PR that removed it on v8 #7202 I personally think that it's better to separate the producers from the consumers, so I agree on the removal of this. Emitting values for the original sources from somewhere else can make it really hard to track why is a value being changed around. |
Beta Was this translation helpful? Give feedback.
-
Hello RxJS community,
I would like to propose an enhancement for Subjects that would enable bidirectional data flow by introducing a middleware function. Currently, when you create a Subject and apply transformations using pipe and operators like switchMap, the Subject is converted into an Observable, making it unidirectional.
Problem:
In certain scenarios, especially when dealing with components or segments of code that need both data consumption and emission capabilities, this unidirectional flow becomes limiting. The current approach restricts the ability to emit new values from the segment of code where the subscription is made.
Proposal:
I suggest extending the functionality of Subjects by introducing a middleware function. This function would allow for internal data transformations, providing the ability to share the Subject across different parts of the codebase while maintaining bidirectional data flow. The middleware function could be applied during the creation of the Subject, allowing users to define custom transformations.
Example:
Benefits:
Enables bidirectional data flow with a single Subject.
Simplifies code by avoiding the need for additional Observables in scenarios where bidirectional flow is required.
I would love to hear the community's thoughts on this proposal. Please share your feedback and suggestions.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions