Skip to content

Do all update logic in one place #3

Description

@pettermahlen

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)
   // ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions