https://kotlinlang.org logo
#rx
Title
# rx
i

iex

02/25/2020, 4:08 PM
If works as expected if I use
flatMap
instead of
withLatestFrom
, but curious why
withLatestFrom
doesn't. I thought it will get the current value at the point of time I activate the subject.
z

Zach Klippenstein (he/him) [MOD]

02/25/2020, 4:32 PM
The reason
flatMap
works is because
flatMap
will resubscribe every time the upstream observable emits. And since
dealerAction
is a
Single
, it will only compute the value on subscription. So with
flatMap
, every time you click, you’re re-subscribing to
dealerAction
, which re-reads the preference, and you get your new value. With
withLatestFrom
,
dealerAction
is only subscribed to once, and since it’s a
Single
it will only emit once.
💯 1
i

iex

02/25/2020, 4:53 PM
wow, that's a pretty great explanation 🙂
understood
thanks again!