Hi guys, i'm currently looking at a project where ...
# coroutines
s
Hi guys, i'm currently looking at a project where coroutines are used fairly extensively for basic communication from fragment to ViewModel and so on to internal viewmodel components. Does anyone have thoughts on this type of architecture? pros / cons, etc. Thank you for your input!
Copy code
sealed class Action {
    data class ButtonClickAction(val data: Int): Action()
}

interface ActionHandler {
    suspend fun handleAction(action: Action)
}

class Fragment() {
    
    button.setOnClickListener {
        lifecycleScope.launch { 
            viewModel.handleAction(ButtonClickAction(data = 100))
        }        
    }
    
}

class ViewModel(
    private val otherActionHandler: ActionHandler,
	private val otherActionHandler2: ActionHandler): ActionHandler {
    
    override suspend fun handleAction(action: Action) {
        when(action) {
            is ButtonClickAction -> {
                otherActionHandler.handleAction(action)
            }
            else -> {
                otherActionHandler2.handleAction(action)
            }
        }
    }
}
🧵 3