Skip to content

Instantly share code, notes, and snippets.

@RohitSurwase
Created February 13, 2021 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RohitSurwase/af246f9664542e141b63b54aa659b0a7 to your computer and use it in GitHub Desktop.
Save RohitSurwase/af246f9664542e141b63b54aa659b0a7 to your computer and use it in GitHub Desktop.
Parent DataHolder for easy implementation of DataHolder for Activities.
open class AacMviDH<STATE, EFFECT> {
private val _states: MutableLiveData<STATE> = MutableLiveData()
val stateLiveData: LiveData<STATE>
get() = _states
private var _state: STATE? = null
var state: STATE
get() = _state
?: throw UninitializedPropertyAccessException("\"state\" was queried before being initialized")
set(value) {
Log.d(TAG, "setting viewState : $value")
_state = value
_states.value = value
}
private val _effects: SingleLiveEvent<EFFECT> = SingleLiveEvent()
val effectLiveData: SingleLiveEvent<EFFECT>
get() = _effects
var effect: EFFECT? = null
set(value) {
Log.d(TAG, "setting viewEffect : $value")
field = value
_effects.value = value
}
fun onCleared() {
_state = null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment