EventRouter
Creates the router of one screen.
The router creates the screen's ScreenStore from initialState and passes it to every handler it runs. Handlers run in child coroutines of scope and are cancelled with it: the router lives exactly as long as scope does and has nothing to close. One handler failing does not cancel the others.
While it lives, the router remembers only the events that are running or waiting to run, each until its run ends. Which events wait, are cancelled or are ignored is decided by the DispatchStrategy of each handler.
Parameters
Where the handlers run. A view model passes the scope it is closed with, for example the one from routerScope. The router keeps a job in this scope until the scope is cancelled, so pass a scope that gets cancelled, not one that something waits for: in a test, backgroundScope.
The state the screen starts with.
The handlers of the screen, one for each event type.
Receives every failure of a handler, with the event it was handling and the screen's store, so it can emit an effect or update the state. Cancellation is never reported. When this is null, a handler's exception is not caught: it reaches the CoroutineExceptionHandler of scope or, without one, the platform's handler for uncaught exceptions.
Is told what the router does with each event, in order and one report at a time. See RouterObserver. When this is null, the router does none of that work.
Throws
when two handlers are registered for the same event type.