Model, View, Intent의 앞 글자를 따서 만든 아키텍처 패턴을 일컫는 용어입니다. 관심사 분리를 위해 3개의 키워드로 나눠지며, GUI 프로그래밍에서 주로 언급되는 패턴입니다.
Intent
가 아닙니다.Reducer = (State, Event) → State State Reducer는 새로운 상태를 만드는 로직의 집합입니다. 즉, 기존의 상태를 새로운 상태로 변환하고, 상태를 한 곳에서 관리합니다.
sealed class Event {
object Increment : Evnent()
object Decrement : Evnent()
}
data class State(val counter: Int = 0)
class ViewModel {
val state = MutableStateFlow(State())
// Intent를 호출하는 트리거
fun handleEvent(event: Event) {
when (event) {
is Increment -> state.update { it.copy(counter = it.counter + 1) }
is Decrement -> state.update { it.copy(counter = it.counter - 1) }
}
}
}
sealed class Event
data class State