Basic guidance on how to use with TCA #47
-
|
Thanks so much for the library, already using it in a prototype and loving it. I'm having trouble figuring out how I would integrate this library and approach with TCA. I'm certain it's straightforward to do so, but for some reason the mental model of how the pieces would fit together just won't click for me. I looked for a case study involving TCA, but don't see any. Would you be willing to give just a few sentences, or a few short code snippets of how you would imagine this library being integrated into a reducer-driven TCA app? Just enough to put me on the scent would be great. Many thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
|
When we use observable models in our demos, they mostly map to TCA reducers:
Otherwise things look mostly the same. So you could take the SyncUps demo, which uses observable models, and consider how it would be ported. But the bottom line is you can use Let us know if you hit any particular stumbling blocks and we'll see if we can help! |
Beta Was this translation helpful? Give feedback.
-
|
I have a similar question, and I've managed to integrate SharingGRDB with TCA, but I'm struggling to find a way to have dynamic queries work. Specifically, I have defined a @Fetch(Albums(), animation: .default) var albums = Albums.Value()Which I then update as required in the reducer: return .run { _ in
state.$albums.load(Albums())
}The issue I'm having is that I'm not able to call Do you have any guidance on what I could do in this scenario? Thanks! |
Beta Was this translation helpful? Give feedback.
-
|
I'm struggling a bit with testing SharingGRDB in the Composable Architecture. Normally the But with a shared database this seems not to work. So I have to assert on the state of the database, which means I could miss a change. An alternative would be to treat the database as a dependency and create a But then all the What's the best way to test SharingGRDB? |
Beta Was this translation helpful? Give feedback.
-
|
Sorry to dig this up again, but I believe that my problem is very similar, so I hope this is the right place to ask for help (rather than creating a new discussion). While I have something that works for me, it doesn't quite feel like the right way. In my Reducer the State looked like this: public struct State {
var filter: Filter
@FetchAll var issues: [Issue]
init(filter: Filter) {
self.filter = filter
_issues = FetchAll(issuesQuery, animation: .default)
}
var issuesQuery: some StructuredQueriesCore.Statement<Issue> {
Issue
.where { ... }
.select { ... }
}
}Then in my Reducer's body I tried a couple of ways of updating the query return .run { [issues = state.$issues, query = state.issueQuery] _ in
try await issues.load(query)
}Problem: Capture of 'query' with non-Sendable type 'some Statement' in a '@sendable' closure Next I tried this: return .run { [state] _ in
try await issues.load(query)
}Problem: Capture of 'state' with non-Sendable type 'Content.State' in a '@sendable' closure Finally, I moved the return .run { [issues = state.$issues, filter = state.filter] _ in
try await issues.load(Self.issuesQuery(for: filter))
}This seems to work, but I really don't like needing a static function for this. |
Beta Was this translation helpful? Give feedback.
When we use observable models in our demos, they mostly map to TCA reducers:
Otherwise things look mostly the same. So you could take the SyncUps demo, which uses observable models, and consider how it would be ported.
But the bottom line is you can use
@FetchAll(and@FetchOneand@Fetch) wherever you want, or wherever@Sharedproperties are held. This includes reducer state, effects, even directly in a view if you want. And you can use@Dependency(\.defaultDatabase)to write to the database.Let us know if you hit an…