Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder update fn signature to State, Action, Environment #14

Merged
merged 1 commit into from Mar 26, 2022

Conversation

gordonbrander
Copy link
Collaborator

@gordonbrander gordonbrander commented Mar 26, 2022

This PR changes the order of update function arguments:

  • Changes update function signature from update(State, Environment, Action) to update(State, Action, Environment)
  • Changes Store from Store<State, Environment, Action> to Store<State, Action, Environment>

Why?

  • This order of arguments is used by two other Elm-like libraries: Swift Composable Architecture and Redux-like state container.
  • Context arguments like environment often seem to be passed last in Swift. E.g. UIViewRepresentable.Context is passed last to methods in SwiftUI.
  • State and Action are always used, but Environment might be nil, or an empty struct. You don't always need environment. It is optional.
  • The order reads better in the signature, since state and action are always paired together in update function and Update struct.

@gordonbrander gordonbrander merged commit 546c7d0 into main Mar 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant