const { Observable, ReplaySubject } = Rx
let cpt = 0
const rs = new ReplaySubject(1)
rs
// should print for every `next`
// * COM 1
.do(console.log)
.subscribe()
const next = () => {
const n = cpt++
console.log('next', n)
rs.next(n)
}
const func = () => {
rs
.first()
// * COM 2
.do(_ => next())
.subscribe()
}
// SHOULD DISPLAY
// next 0
// 0
next()
// SHOULD DISPLAY
// next 1
// 1
func()
// SHOULD DISPLAY
// next 2
// 2 --> !!! DOES NOT APPEARS !!! <--
next()
/**
*
* COM 1 & COM 2
*
* To make it work as expected :
* - Replace the `do` by a `subscribe`
* - Remove the subscribe right after
*
*/
Environment
RxJS v5.2.0
What's the problem ?
When using
do
instead ofsubscribe
at the end of an observable chain, we are not notified (sometimes ?)Plunkr repro
@victornoel helped me to create a minimal repro (👍) of the issue and a Plunkr is available here : https://plnkr.co/edit/KjaL14tSbrns7uLqSZxO?p=preview
Code repro