Comments (2)
Hi @opryzhek Thanks for your question. Code duplication is one of the thing I would like to avoid in the first place. I will look into it to see if there are any other approaches.
from livedata-ktx.
I've run through the code and found out that all extension methods like filter
and map
are already duplicated for LiveDataKtx
, MutableLiveDataKtx
and MediatorLiveDataKtx
so we can just move some LiveDataKtx
methods to separate interface. This way there would be almost zero additional code duplication. Same could be done to MediatorLiveDataKtx.
package com.ronasit.apptemplate.ui
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
interface ILiveDataKtx<T> {
val safeValue: T?
fun getValue(): T
}
open class LiveDataKtx<T> : LiveData<T>(), ILiveDataKtx<T> {
override val safeValue: T? get() = super.getValue()
@Suppress("RedundantOverride")
override fun setValue(value: T) {
super.setValue(value)
}
@Suppress("UNCHECKED_CAST")
override fun getValue(): T {
return super.getValue() as T
}
@Suppress("RedundantOverride")
override fun postValue(value: T) {
super.postValue(value)
}
}
open class MutableLiveDataKtx<T>: MutableLiveData<T>(), ILiveDataKtx<T> {
override val safeValue: T? get() = super.getValue()
@Suppress("UNCHECKED_CAST")
override fun getValue(): T {
return super.getValue() as T
}
@Suppress("RedundantOverride")
override fun setValue(value: T) {
super.setValue(value)
}
@Suppress("RedundantOverride")
override fun postValue(value: T) {
super.postValue(value)
}
}
from livedata-ktx.
Related Issues (13)
- NonNull operation doesn't preserve immutability of LiveData HOT 1
- Supertypes of the following classes cannot be resolved. HOT 6
- Incompatible with LiveData 2.x as package name is changed HOT 1
- remove @Suppress("DEPRECATION") HOT 3
- SingleLiveData doesn't work as expected HOT 4
- different between versions 3.0.0 and 2.0.2 HOT 5
- Multiple implementation issue in android studio 3.5 HOT 2
- PublishLiveDataKtx not remove observer by lifecycle event
- debounce() uses Handler which makes it difficult to test
- Unnecessary Nullable types HOT 5
- minSdk version 19 -> 16? HOT 3
- Create `combineWith` operator
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from livedata-ktx.