When creating an RxJS BehaviorSubject
, it stays a BehaviorSubject
until it's pipe
'd. As soon a pipe
'd version is returned, it becomes an AnonymousSubject
.
Examples:
// Instance of `BehaviorSubject`
const behaviorSubject$ = new BehaviorSubject({ someValue: null })
// Suddenly becomes an Anonymous Subject
const anonymousSubject$ = (
behaviorSubject$
.pipe(
pluck('someValue')
)
)
// Also suddenly becomes an Anonymous Subject
const anonymousSubject$ = (
new BehaviorSubject({ someValue: null })
.pipe(
pluck('someValue')
)
)
I experience this same issue with ReplaySubject
as well. I can't seem to pipe through the subject and return that subject back. It always converts to an AnonymousSubject
. I think what I'm looking for here is Promise-like behavior where I can subscribe to this observable from anywhere and grab the one value passed into it.
behaviorSubject$.value
. Should I be using aReplaySubject
instead? – Asclepiadaceousvalue
from the result returned frompipe
though? – Coniumvalue
is a code smell and even iflift
returned aBehaviorSubject
, what would you expect thevalue
if the lifted subject to be? The original value or the plucked value? I think you should seriously reconsider usingvalue
. – Podgy.value
, but even if I use aReplaySubject
instead, it converts to anAnonymousSubject
, and I lose the value I passed. – AsclepiadaceousBehaviorSubject
allows you to dosubject.value
. I can't do that withAnonymousSubject
. – Asclepiadaceous