In the Update function, there are a couple of cases like this:
is PlayButtonClicked ->
onPlayButtonClicked(model.copy(musicLocation = event.musicLocation), event.context)
...
fun onPlayButtonClicked(model: MainModel, context: Context): Next<MainModel, MainEffect> = Next.next(model,
effects(AttemptToPlay(model.musicLocation, model.status, context)))
It's probably easier to read if all the business logic for handling the event is in a single place rather than two, like so:
is PlayButtonClicked ->
onPlayButtonClicked(model, event)
...
fun onPlayButtonClicked(model: MainModel, event: PlayButtonClicked): Next<MainModel, MainEffect> =
Next.next(model.copy(musicLocation = event.musicLocation),
effects(AttemptToPlay(event.musicLocation, model.status, event.context)))
Some Spotify teams consistently use functions with the signature onEventName(model, event) for all event updates, even if the actual update doesn't need any data from the model/event. I'm personally leaning towards inlining simple updates and only passing relevant information, so something like:
return when (event) {
is SomethingSimple -> Next.noChange()
is NeedsDataFromEventOnly -> onNDFO(event)
is NeedsModel -> onNeedsModel(model)
// ...
}
In the Update function, there are a couple of cases like this:
It's probably easier to read if all the business logic for handling the event is in a single place rather than two, like so:
Some Spotify teams consistently use functions with the signature
onEventName(model, event)for all event updates, even if the actual update doesn't need any data from the model/event. I'm personally leaning towards inlining simple updates and only passing relevant information, so something like: