If works as expected if I use `flatMap` instead of...
# rx
i
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
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
wow, that's a pretty great explanation 🙂
understood
thanks again!