share()
operator is applied to a BehaviorSubject.
BehaviorSubject has initial value.
Goal is to create a single shared subscribtion. But this shared subscribtion does not seem to work when BehaviorSubject has an initial value.
Getting unexpected results.
Code shown below:
let subject = new Rx.BehaviorSubject(0);
let published = subject
.do(v => console.log("side effect"))
.share();
published.subscribe((v) => console.log(v+" sub1"));
published.subscribe((v) => console.log(v+" sub2"));
subject.next(1);
Result:
"side effect"
"0 sub1"
"side effect"
"1 sub1"
"1 sub2"
Expected Result:
"side effect"
"0 sub1"
"1 sub1" <------------- this is missing from actual result
"side effect"
"1 sub1"
"1 sub2"