Created
November 2, 2017 08:52
-
-
Save amay077/ca40b915d3d4059a2ce4c41bc75807ce to your computer and use it in GitHub Desktop.
LiveData.observe is NOT onChanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package your.awesome.package | |
fun <T> LiveData<T>.observeOnChanged(owner : LifecycleOwner, observer : Observer<T>) : Unit { | |
var prev : T? = null | |
this.observe(owner, Observer<T> { | |
if (!(prev?.equals(it) ?: false)) { | |
observer.onChanged(it) | |
} | |
prev = it | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment