Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different between versions 3.0.0 and 2.0.2 #23

Closed
Kadanza opened this issue Apr 27, 2019 · 5 comments
Closed

different between versions 3.0.0 and 2.0.2 #23

Kadanza opened this issue Apr 27, 2019 · 5 comments

Comments

@Kadanza
Copy link

Kadanza commented Apr 27, 2019

Hi

  • 1) what improvement has version 3.0.0?

  • 2) why need MutableLiveDataKtx instead MutableLiveData?

  • 3) In version 2.0 we has great extension observe without Observer

livedata.observe(this) {it ->

}

In version 3.0 observe without Observer is gone =(
We have now only ugly

.observe(lifecycleOwner, Observer { result ->

})

  • 4)

In version 2.0 I has unpleasant bug in android studio,
My breakpoint is skipped by android studio in extension observe, but code in worked

livedata.observe(this) {it ->
// here breakpoint
}

but common way work fine
.observe(lifecycleOwner, Observer { result ->
// result is non-null and always true
})

@Kadanza
Copy link
Author

Kadanza commented Jun 10, 2019

point 4 :
some device have this error (with old api Android)

Nexus 6p - Android 8.1 doesn't have this mistake

@henrytao-me
Copy link
Member

henrytao-me commented Jun 10, 2019

Hi @Kadanza, I missed your original message. Thanks for reaching out. Hopefully, I can address some of your questions below:

  1. what improvement has version 3.0.0?
  2. why need MutableLiveDataKtx instead MutableLiveData?

As listed in the README, v3 focuses on Kotlin friendly, preserve immutability, and extensibility. For instance, you still can set null value for a non-null LiveData which can cause NPE at runtime. Compiler should be able to prevent it.

// Allow to set null value to LiveData
val liveData = MutableLiveData<Boolean>()
liveData.value = null

// LiveDataKtx doesn't allow to null value
val liveData = MutableLiveDataKtx<Boolean>()
liveData.value = null // doesn't allow

// Set nullable in LiveDataKtx
val liveData = MutableLiveDataKtx<Boolean?>()
liveData.value = null
  1. In version 2.0 we has great extension observe without Observer

There is tradeoffs for the approach. Kotlin lambda generates different object down to Java layer which makes harder to remove the observer later on.

  1. In version 2.0 I has unpleasant bug in android studio

I haven't encountered this issue. I can take a look later.

@Kadanza
Copy link
Author

Kadanza commented Jun 11, 2019

point 3 : are you not recommend use version 2 because of problem with memory?

I use version 2 widely

@henrytao-me
Copy link
Member

henrytao-me commented Jun 11, 2019

If you use v2.0.2, removeObserver should work properly as we had a fix for it https://github.com/Shopify/livedata-ktx/releases/tag/v2.0.2.

So, migrating to v3 is an optional.

@henrytao-me
Copy link
Member

Let us know if you have any other concerns. I will close this issue for now. Feel free to reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants