Junior — Middle
Do you have experience developing applications using the Model-View-Intent (MVI) architectural pattern?
sobes.tech AI
Answer from AI
Yes, I have experience developing with the Model-View-Intent (MVI) pattern. In MVI, all application logic is built around data streams and user intentions (Intents). The Model contains the state, the View displays this state, and the Intent represents events initiated by the user, such as button presses.
An example of a simple MVI in Kotlin for Android:
// Intent - user actions
sealed class UserIntent {
object LoadData : UserIntent()
data class Submit(val input: String) : UserIntent()
}
// Model - UI state
data class ViewState(val isLoading: Boolean = false, val data: String? = null)
// ViewModel processes the Intent and updates the state
class MainViewModel : ViewModel() {
private val _state = MutableLiveData<ViewState>()
val state: LiveData<ViewState> = _state
fun processIntent(intent: UserIntent) {
when (intent) {
is UserIntent.LoadData -> {
_state.value = ViewState(isLoading = true)
// data loading...
_state.value = ViewState(isLoading = false, data = "Data loaded")
}
is UserIntent.Submit -> {
// handle submission
}
}
}
}
This approach helps clearly separate logic and UI, making testing and state management easier.