EventHandler
Handles one event type of one screen.
A handler holds the logic for its event: it calls the app's repositories or use cases, updates the state and emits effects. It keeps nothing about the screen itself. The state and the effects come in with each call, as the ScreenStore of the screen, so a handler's constructor takes only what the handler really depends on.
class OnRefreshHandler(
private val tasks: TaskRepository,
) : EventHandler<OnRefresh, TaskListUiState, TaskListEffect> {
override val eventType = OnRefresh::class
override val strategy = DispatchStrategy.DropIfAlreadyRunning<OnRefresh>()
override suspend fun handle(event: OnRefresh, store: ScreenStore<TaskListUiState, TaskListEffect>) {
tasks.refresh()
store.emit(TaskListEffect.Refreshed)
}
}Content copied to clipboard
To report a failure, let it throw: the EventRouter passes it to the screen's ErrorHandler.