Created
December 5, 2019 02:57
-
-
Save yshrsmz/3599d0014993af604bf0378f6843c59f to your computer and use it in GitHub Desktop.
AbstractStateNotifier
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
abstract class AbstractStateNotifier<ACTION : Action, STATE : State, EFFECT : Effect, VM : MviViewModel<*, ACTION, STATE, EFFECT>>( | |
uiContext: CoroutineContext | |
) : CoroutineScope { | |
private val job = SupervisorJob() | |
override val coroutineContext: CoroutineContext = job + uiContext | |
fun stateChanged(vm: VM, state: (state: STATE) -> Unit): Job { | |
return launch { vm.states.collect { state(it) } } | |
} | |
fun effectReceived(vm: VM, effect: (effect: EFFECT) -> Unit): Job { | |
return launch { vm.effects.collectUnhandled { effect(it) } } | |
} | |
fun dispose() { | |
job.cancel() | |
} | |
} |
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
class DepositProductDetailVMStateNotifier(uiContext: CoroutineContext) : | |
AbstractStateNotifier< | |
DepositProductDetailAction, | |
DepositProductDetailState, | |
DepositProductDetailEffect, | |
DepositProductDetailViewModel>(uiContext) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment