EventRouter

interface EventRouter<E : UiEvent, S : UiState, F : UiEffect>

What a screen shows to its UI: the state to draw, the effects to perform and one way in for events.

A view model implements it by delegating to the router that the EventRouter function creates, so it extends no class of this library:

class TaskListViewModel(
scope: CoroutineScope = routerScope(),
handlers: Collection<EventHandler<*, TaskListUiState, TaskListEffect>>,
) : ViewModel(scope),
EventRouter<TaskListEvent, TaskListUiState, TaskListEffect> by EventRouter(
scope = scope,
initialState = TaskListUiState.Loading,
handlers = handlers,
)

Properties

Link copied to clipboard
abstract val effects: Flow<F>

The effects of the screen. Each one is delivered once, to one collector. Effects emitted while nothing collects are kept for the next collector.

Link copied to clipboard
abstract val state: StateFlow<S>

The state of the screen. It always has a value, and a new collector gets the latest one first.

Functions

Link copied to clipboard
abstract fun onEvent(event: E)

Sends event to the handler registered for its exact class, which runs it as its DispatchStrategy says. It returns at once and is safe to call from any thread.