Created
February 13, 2021 08:32
-
-
Save RohitSurwase/af246f9664542e141b63b54aa659b0a7 to your computer and use it in GitHub Desktop.
Parent DataHolder for easy implementation of DataHolder for Activities.
This file contains 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
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