Open Qquanwei opened 6 years ago
This is expected behavior. withLatestFrom
needs a value from both sides before it will start emitting. The sequence above goes:
startWith
emits immediately but withLatestFrom
only has a cached "left" value and so doesn't emit.withLatestFrom
, however it doesn't emit because it only emits when the "left" side emits.withLatestFrom
finally emits with the new "left" value and the most recent "right" value.In other words: values on the "left" side will be ignored until the "right" side emits.
Side-note: It looks like you're using Rx 5 so you want that repo instead. This repo is for Rx 4 which is in maintenance-only mode. That said, I expect the answer above will apply to both versions.
If you're interested to read more, and if you're in a position where you can't ensure the "right" will emit before the "left", there's a discussion and solution about using both combineLatest and withLatestFrom to avoid this behavior on StackOverflow. I ended up making a custom operator, waitLatestFrom -- although it's for Rx 4 it should be easy to adapt to Rx 5.
When I only using startWith, it's works fine for me
output
But when uncomment
It's output
It's no sense with that result, isn't ?