Issue
I try to handle clicks on my buttons and send action to viewModel
private fun subscribeUI() {
lifecycleScope.launch {
binding.loginButton
.clicks()
.onEach { }
.map { Action.WelcomeAction.SelectLogin }
.collect { viewModel.actions.offer(it) }
binding.homeButton
.clicks()
.onEach { }
.map { Action.WelcomeAction.SelectHome }
.collect { viewModel.actions.offer(it) }
binding.registerButton
.clicks()
.onEach {}
.map { Action.WelcomeAction.SelectRegister }
.collect { viewModel.actions.offer(it) }
}
}
Only action from login button comes to my view model. How can I merge these three flows into one? Probably that's the problem there are 3 action streams to view model
Solution
private fun subscribeUI() {
merge(
binding.loginButton.clicks().map { Action.WelcomeAction.SelectLogin },
binding.homeButton.clicks().map { Action.WelcomeAction.SelectHome },
binding.registerButton.clicks().map { Action.WelcomeAction.SelectRegister }
)
.onEach { viewModel.actions.offer(it) }
.launchIn(lifecycleScope)
}
Answered By - IR42
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.