I have a ConnectableObservable
which is part of a BehaviourSubject
.
question$: ConnectableObservable<Result>;
private questionSubject: BehaviorSubject<Result>;
this.questionSubject = new BehaviorSubject<Result>(new Result('initial',{}));
this.question$ = (this.questionSubject.asObservable()).pipe(publish()) as ConnectableObservable<Result>;
I use next
method to emit
values when response from the server is received.
this.questionSubject.next(new Result(response.result,getQuestionResponse));
It seems that the Subject
is emitting past values as well.
jsonQuestion response: {"question-id":"78830909-b23e-4345-bc69-63f3ce039b20",...} //SUBJECT SENDS THIS
question-details.component.ts:369 got stream value Result {result: "success", additionalInfo: "{"question-id":"78830909-b23e-4345-bc69-63f3ce039b…2-ae23-f284213ff80a"},"is-question-creator":true}"}// OBSERVABLE RECEIVED THIS
... AND THE SAME TRACE COMES AGAIN!!
question-details.component.ts:369 got stream value Result {result: "success", additionalInfo: "{"question-id":"78830909-b23e-4345-bc69-63f3ce039b…2-ae23-f284213ff80a"},"is-question-creator":true}"}
Why is the Observable sending multiple values. How can i make it send only the latest value?