Inspired by Tanstack Query, this library allows creating data graphs that use the Observation framework to perform calculations, which could be async or not. These calculations could be anything from API calls, to expensive computations.
This is not a stable project, but an exploration of using the Observation framework in an interesting manner. It also does not offer the same set of features as Tanstack Query, given this is a single day coding experiment.
- Bite-sized async and caching state management. No need for complex data stores that have all available state making compilation and code indexing slow or error prone.
- Easily integratable for projects, no need to rewrite the entire data stack to start using.
To declare a data dependency graph, use either SQState for root data, which means, data that
doesn't have any dependencies, or SQDerived, which
let pageIndex = SQState(0)
let pageData = SQDerived(key: [pageIndex]) {
try await Task.sleep(for: .milliseconds(500))
return PageData(pageIndex: pageIndex.value)
}
Check the Examples directory for demo ViewController that uses this data architecture.
- I haven't explored how to make this work better with property wrappers, but given the need to
store references to the data, and you don't have access to
selfwhen declaring these as properties, I am not sure how feasible it is. - Given I wanted to do async computations, I couldn't find a way to avoid the
keyordepsfields for automatic tracking of used variables inside the async computation method. Maybe in the futurewithObservationTracking:onChange:will support async somehow. - I didn't explore this, but I think it should be easy to extract the
trackChangemethod in the example to make it simple to track changes of certainSQStateorSQDerivedto only update small portions of the UI and not all of it. - Because of some
Task.immediateusage, this is for now iOS 26, macOS26, tvOS 26 and watchOS 26 compatible only. Shouldn't be too hard to make it compatible for older versions. - Using UserDefaults as an easy store, I'm sure there are better stores out there for this kind of library.