I want to use these two solutions together with RxJS but I don't know how to do it.
pipe each data that Observable emits and have ability to act like a Subject:
// Sample code, this does not work properly :(, because next is not defined on Observable
const dummy = new Subject<number>().pipe(
map((num) => num + 1)
);
dummy.subscribe((number) => {
// expects 4 but get 3
})
dummy.next(3)
I want to emit data everywhere even outside of observable construction like Subscribe, and operate on each data emit using pipe method like Observable.
I can implement an simple emitter class that simulate this behavior but I want a RxJS way.
This is an abstraction that doesn't exist with RxJS.
You can build it yourself by defining kleisi composition for subjects. Basically do for subjects what pipe does for observables.
Subjects are observables and observers, so you can build the abstraction ontop of the operators that already exist by just tracking the source subject.
So why doesn't this already exist? Largly because it's not clear why it's even usefull. The operators operate on observables and not on observers.
Subjects are useful for multicasting (make a cold observable hot) and for interfacing/bridging between declarative and imperative code.
Historically attempts to integrate (instead of just interface) declarative and imperative api design has be frought with needless complexity.
The odd time that you need access to a subject and some steam of data together imperatively, it's probably clearer api to shove the two into an object or tuple and pass them atound that way. Extending the subject with a new type of composition just doesn't add much benefit, abstractly or concretely.