Reverse (input) Pipelines #7462
dariomannu
started this conversation in
Ideas / Feature request
Replies: 1 comment 1 reply
-
I may have misunderstood the idea, but in general I believe you can achieve feeding values into subjects by using the share operator, so the first example you showed would look something like this. // shared connection point
const connector = new Subject<string>();
const shared$ = somePointerEventSource.pipe(
share({
connector: () => connector,
// other options depending on use case
})
)
// consumer side:
shared$.subscribe(); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
.pipe()
, despite not being a pleasure to repeat so many times, still offers an extremely powerful functionaliy, which is transforming the output of an observable with any operator function.However, I keep missing an "inbound" equivalent, something like a
pipeIn()
function, that can be used create transformations used to feed a target subject/behavior/observer.So, anyone feeding the
inputPipe
above, will indirectly feed strings to theconnector
, the actual target, despite emitting PointerEvents.A concrete use case? UI libraries and templates.
Reverse pipeline operator?
In another dimension, if JS had a reverse pipeline operator, too, ( >| ) we could even create reverse pipelines looking something like this:
In this example, the onchange event, as it emits, would first go through
evtToEmail
, before being "sourced" intoemailAddress
, in (IMHO) a simple, clear and elegant way.This is as opposed to definining emailAddress with a normal pipeline:
Refactoring and organisation
Anyway, back to the real world. Why should we need all this? Can we not do everything already with the standard pipe method and the pipe function? Yes, we can, except we end up having to refactor our main streams when their sources keep changing over time.
Suppose our main stream is a
const email = Subject<EmailAddress>
, the source can be a text field, a file reader, local storage, web sockets.With reverse pipelines, we can keep
email
untouched, including everything downstream and only add some new reverse pipes to convert from different data sources into whatemail
expects (EmailAddress).Without reverse pipelines, we first need to create a transformation pipe for each source, then redefine the main stream by merging them all with
mergeWith()
.Without input pipelines:
I feel llike with input pipes it would also be easier to keep the emphasis on a main stream as such. Without, it easily looks like a secondary derived state.
So, in summary, I wonder if the distinction between the two could not only help organise code more effectively, but possibly even help understand the overall flow more easily to readers?
Beta Was this translation helpful? Give feedback.
All reactions