I was looking through the interfaces of observables and saw you can pass anything that implements PartialObserver to the subscribe function. So I did that with BehaviorSubject.
Like this (A)
source$
.pipe(
tap(() => console.log('X')),
)
.subscribe(this._titlesX$);
So I did, but found something very strange. If I pass the behavior subject to the subscribe function the values get emitted, but to see that, you have to subscribe before using the BehaviorSubject as PartialObserver.
In the docs for BehaviorSubject you can find this:
A variant of Subject that requires an initial value and emits its current value whenever it is subscribed to.
So when using BehaviorSubject as partialObserver this behavior breaks.(No pun intended)
But when I use this method: Like this (B)
source$
.pipe(
tap(() => console.log('X')),
)
.subscribe(res => this._titlesX$(res));
Everything works as expected.
Why does method A not work? Is this a bug or am I just using it wrong?
Here is a link to the stackblitz all setup. Link to stackblitz project
titleX: represents method A titleY: represents method B
Subscribing with an BehaviorSubject should be possible. And the time when you subscribed should not matter. Otherwise it shouldn't be allowed as a parameter for the subscribe method.
subscribe
and not in atap
or a custom operator? – Ink