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

iex

02/25/2020, 4:03 PM
next problem 🙈, I'm deriving another thing from `dealerAction`:
Copy code
private val dealerButtonTrigger: PublishSubject<Unit> = PublishSubject.create()

init {
    dealerButtonTrigger.withLatestFrom(dealerAction.toObservable())
        .subscribe { (_, action) ->
            action.handle()
        }
}
Here, when I click (i.e. call
dealerButtonTrigger.onNext(Unit)
) after updating the dealer and navigating back, it still gives me the first dealer. Shouldn't it get the updated value?
z

Zach Klippenstein (he/him) [MOD]

02/25/2020, 4:27 PM
This is exactly why I was asking this question in the previous thread: https://kotlinlang.slack.com/archives/C0B8Y8BHC/p1582647883026000?thread_ts=1582644781.011600&amp;cid=C0B8Y8BHC
dealerAction
is a
Single
– it only emits a single value. It doesn’t have the concept of “updated value”. If the value can change over time, it should be an
Observable
, and the object backing
dealerAction
should have some way of signaling that the value changed.
Calling
toObservable()
just changes the type, it doesn’t magically add logic that knows how to detect when your data sources changes.
You actually already answered your own question here in the other thread 😉 https://kotlinlang.slack.com/archives/C0B8Y8BHC/p1582647493025000?thread_ts=1582644781.011600&amp;cid=C0B8Y8BHC
To get the “updated value” behavior you’re expecting, that’s what you’d need to do.
i

iex

02/25/2020, 4:52 PM
right! I get it now. That's also why it doesn't work out of the box (without
toObservable()
)
well, not necessarily. It still makes sense.
just not for my use case 😅