Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Nov 25, 2021
1 parent bf27cff commit 82e7a1f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ This package ships with a [demo app]. See also the [GRDB demo apps] for various

---

🙌 `@Query` was vastly inspired from [Core Data and SwiftUI](https://davedelong.com/blog/2021/04/03/core-data-and-swiftui/) by [@davedelong](https://github.com/davedelong), with critical improvements contributed by [@steipete](https://github.com/steipete). Many thanks to both of you!
🙌 `@Query` was vastly inspired from [Core Data and SwiftUI](https://davedelong.com/blog/2021/04/03/core-data-and-swiftui/) by [@davedelong](https://github.com/davedelong), with [a critical improvement](https://github.com/groue/GRDB.swift/pull/955) contributed by [@steipete](https://github.com/steipete). Many thanks to both of you!


[Why @Query?]: #why-query
Expand Down
8 changes: 6 additions & 2 deletions Sources/GRDBQuery/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public struct Query<Request: Queryable>: DynamicProperty {
public var projectedValue: Binding<Request> {
Binding(
get: { tracker.request ?? initialRequest },
set: { tracker.request = $0 })
set: {
tracker.needsInitialRequest = false
tracker.request = $0
})
}

/// Creates a `Query`, given a queryable request, and a key path to the
Expand All @@ -90,7 +93,7 @@ public struct Query<Request: Queryable>: DynamicProperty {
public func update() {
// Feed tracker with necessary information,
// and make sure tracking has started.
if tracker.request == nil {
if tracker.needsInitialRequest {
tracker.request = initialRequest
}
tracker.startTrackingIfNecessary(in: database)
Expand All @@ -99,6 +102,7 @@ public struct Query<Request: Queryable>: DynamicProperty {
/// The object that keeps on observing the database as long as it is alive.
private class Tracker: ObservableObject {
private(set) var value: Request.Value?
var needsInitialRequest = true
var request: Request? {
willSet {
if request != newValue {
Expand Down

0 comments on commit 82e7a1f

Please sign in to comment.