Replies: 2 comments 3 replies
-
Personally I'd recommend modeling your app's data domain and then exposing it through a "store" in a classic definition of that name. For example your app is an address book, so you'd have a ContactsStore. Which can be modeled as a TCA client (plain struct) that abstracts all CoreData mechanics and exposes only app's model objects (preferably plain value structs). ContactsStore client will accept queries defined again in your app's domain terms, like |
Beta Was this translation helpful? Give feedback.
-
Personally I would suggest moving away from CoreData. I've had only pain from it, and its problems are not solvable. The big issue is that it makes everything impure, if your model is based on ManagedObjects you don't control the model. You can't delete objects, every modification has to go in a specific thread, etc. If you still want to use it I would advice to restrict its use only to storing and loading data, and then converting it to and from structs. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Was wondering on how you could see the architecture working with a more complex core data setup. I do know that core data supports using Combine with core data however it is still not so clear how to set up the dependencies in a nice way.
We need access to both the persistent store to create background contexts (for writing and then merging the changes into the main context) and a main context (for reading) would we keep these as environment dependencies or would we instead abstract these using a a struct based approach and create live version that would use core data under the hood? (A bit had to imagine how this could be setup)
Would we abstract the NSManageObject models or should these be ok to return from Effects? It's a good practice to work with NsManagedObjectIds for thread safety instead of passing around the objects, what are your thoughts on abstracting this? Or do you think it is reasonable to let core data specific things get out to the reducer level (meaning we would have to import CoreData and have a direct dependency at the reducer level)
In more complex setups there are a lot of different domain specific queries using NsPredicates, would this type of logic be living in the reducers or would you suggest preparing all the queries in advance and not working with NSPredicates directly (for example creating a client wrapper for each of the core data models and working directly with the client) in the reducers
Thoughts on willSave, didSave and didChange notifications and merging their changes into different interested contexts in the app.
Beta Was this translation helpful? Give feedback.
All reactions