onEvent

inline fun <A, B> onEvent(trigger: Event<A>, crossinline perform: suspend (A) -> B): Event<B>(source)

onEvent acts similarly to map, however, rather than transforming each value of the input Event by a pure synchronous function, onEvent will launch a perform coroutine for every frame in which trigger has fired.

Essentially, onEvent lets us perform some action "outside" the regular Timeline, and responds with a new Event that fires when said actions complete.

Unlike map, for onEvent the perform action is encouraged to be a side-effecting function (making API calls, fetching data, etc...) if appropriate.

Example:

val buttonClick: Event<Unit> = submitButton.clicks()

val submitResponse: Event<DataResponse> = onEvent(buttonClick) {
fetchData()
}