https://kotlinlang.org logo
Title
m

melatonina

11/26/2019, 12:05 AM
Hello. I'm trying to use com.shopify.livedataktx.MutableLiveDataKtx to avoid the invasion of nullables and !! in kotlin code using ViewModel. How do you make a two-way binding with that kind of MutableLiveDataKtx?
r

rkeazor

11/26/2019, 1:45 AM
probably the same way you use liveData
But its only nullable,because of platform type, dont see the big deal really
m

melatonina

11/26/2019, 8:34 AM
@rkeazor it is a big deal: it introduces null everywhere.
@rkeazor In order to perform a two-way binding with MutableLiveDataKtx I had to use a binding converter. This triggers a NPE at compile-time. https://gist.github.com/mel4tonin4/05451ba80aca392caf12f661cc71b431
I have no idea of how to debug that. Do you see where the problem is?
r

rkeazor

11/26/2019, 12:04 PM
Isnt MutableLiveDataKtx a child of LiveData
You shouldnt have to do that
Just when you bind it remember to bind the lifecycle owner as well
There is something werid about your inverse binding adapter. But before you do that ,Make MutableLivrDataKtx extend mutableLiveData. Not livedata. It should work out the box with 2 way data binding
m

melatonina

11/26/2019, 1:00 PM
I'll look into that. I didn't write MutableLiveDataKtx. No idea why they subclassed LiveData
MutableLiveDataKtx subclassed LiveDataKtx and makes the mutating methods public, just like MutableLiveData does with LiveData.
r

rkeazor

11/26/2019, 1:15 PM
Does LiveDataKtx subclass livedata
I say just use MutableLiveData
It's not as big of deal as you think it is lol. The wrapper, isnt anything special
m

melatonina

12/17/2019, 12:18 AM
Thanks, Robert.