Michael Long
Nov 22, 2022

--

I've been curious, can you explain how this would work in an asynchronous context? Every example of this I've seen to date assumes that the result of the state change action is immediately available as a mutated value.

e.g. newX = x.alter()

How would one update user state, say, an email address, when the result of that particular update is asynchronous, requiring data to be sent to a server and getting back a new user in response?

Do you make an alter() async ? If so do you now need async and non isolated reducers? Do you now need multiple Change enums (Change, AsyncChange) so you know which states to pass to the correct alter function?

Seriously. As I said, I've only seen examples that assume a simple immediately mutable state.... but a lot of applications have to talk to APIs and backends and even functions that are asynchronous.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (3)