Replies: 1 comment
-
This is a big assumption! For the purposes of the example, I think it's far more reasonable to assume The problem of keeping local memory state and remote server state in sync is simply a higher-level problem than what this library exists to solve, and I don't think the example code was attempting to comment on it. Edit: your question seems to assume |
Beta Was this translation helpful? Give feedback.
-
I've just read Introducing: identified collections, where example code is given of a function,
func todoCheckboxToggled(at id: Todo.ID) async
that mutates the state of an element in the publishedtodos
IdentifiedArray.
The first line in the function,
self.todos[id: id]?.isComplete.toggle()
, appears to directly mutate the todo element state, which I assume will cause the SwiftUI view driven by the viewModel to update. I understand this as mutating local viewModel data for the purpose of immediately updating the todo list view?Next is a
do/try/catch
block where presumably persistenttodo
data is mutated asynchronously via anapiClient
instance.Further, I assume that the viewModel implements an observer for changes to the persistent data, something along the lines of:
With these assumptions, I wonder why we toggle local todo state in addition to updating the (again presuming) more canonical data source via
apiClient
? In that scenario it seems we have two sources of truth: local and persistent. I might expect that we would not change the local data source in theToDoViewModel
toggle function, and simply update, and let the list view react to, the change in the persistent data source via the publisher.Beta Was this translation helpful? Give feedback.
All reactions