It's likely that I'm just approaching the situation from the wrong angle, so I would absolutely welcome alternate suggestions.
What I'm trying to do: edit a string locally and, when editing is done, send an API request to a service to update the name of the object that owns that string property.
struct EPCombinedState: Equatable {
var user: AuthContent
var epState: EditPopulationState
}
struct EPState: Equatable {
var population: Population
...
}
struct Population: Equatable, Hashable, Identifiable, Codable {
var name: String
...
}
struct EditPopulationView: View {
let store: Store<EPCombinedState, EditPopulationAction>
var body: some View {
WithViewStore(store) { viewStore in
...
TextField(LocalizedStringKey.pvPopName, text: viewStore.binding(
get: { $0.epState.population.name },
send: { .editName($0) }
))
...
}
}
}
So, as I said, rather than have a separate "Send Update To Server" button, I'd like to have it work so that when the population name changes, we fire off a delayed effect that would send the name to the server, but if there's already such an Effect hanging (we're now on the second keystroke, e.g.) then cancel the currently pending Effect and start a new one.
Looking at the Cancellation case study, it seems that to cancel an Effect I'm supposed to return a cancel Effect. So, maybe I'm supposed to compose the "schedule a task" Effect along with a "cancel this other Effect" into one bigger one?