diff --git a/GRDB/Fixit/GRDB-5.0.swift b/GRDB/Fixit/GRDB-5.0.swift index 1d728f3fe..af0ad91b9 100644 --- a/GRDB/Fixit/GRDB-5.0.swift +++ b/GRDB/Fixit/GRDB-5.0.swift @@ -211,19 +211,25 @@ extension ValueObservation where Reducer == Never { where Request.RowDecoder == Row { preconditionFailure() } - @available(*, unavailable, message: "Use ValueObservation.tracking(value:) instead") + @available(*, unavailable, message: "Use ValueObservation.tracking(_:) instead") public static func tracking( _ regions: DatabaseRegionConvertible..., fetch: @escaping (Database) throws -> Value) -> ValueObservation> { preconditionFailure() } - @available(*, unavailable, message: "Use ValueObservation.tracking(value:) instead") + @available(*, unavailable, message: "Use ValueObservation.tracking(_:) instead") public static func tracking( _ regions: [DatabaseRegionConvertible], fetch: @escaping (Database) throws -> Value) -> ValueObservation> { preconditionFailure() } + + @available(*, unavailable, renamed: "tracking(_:)") + public static func tracking( + value: @escaping (Database) throws -> Value) + -> ValueObservation> + { preconditionFailure() } } extension ValueObservation where Reducer.Value: Equatable { diff --git a/GRDB/ValueObservation/ValueObservation+Count.swift b/GRDB/ValueObservation/ValueObservation+Count.swift index 94e74d4dd..7814ff607 100644 --- a/GRDB/ValueObservation/ValueObservation+Count.swift +++ b/GRDB/ValueObservation/ValueObservation+Count.swift @@ -30,9 +30,7 @@ extension FetchRequest { public func observationForCount() -> ValueObservation>> { - return ValueObservation - .tracking(value: fetchCount) - .removeDuplicates() + ValueObservation.tracking(fetchCount).removeDuplicates() } } diff --git a/GRDB/ValueObservation/ValueObservation.swift b/GRDB/ValueObservation/ValueObservation.swift index 12a9f57da..37aec8de9 100644 --- a/GRDB/ValueObservation/ValueObservation.swift +++ b/GRDB/ValueObservation/ValueObservation.swift @@ -162,7 +162,7 @@ extension ValueObservation where Reducer == Never { /// - parameter value: A function that fetches the observed value from /// the database. public static func tracking( - value: @escaping (Database) throws -> Value) + _ value: @escaping (Database) throws -> Value) -> ValueObservation> { return ValueObservation>(makeReducer: { @@ -176,7 +176,7 @@ extension ValueObservation where Reducer == Never { /// - parameter value: A function that fetches the observed value from /// the database. public static func trackingVaryingRegion( - value: @escaping (Database) throws -> Value) + _ value: @escaping (Database) throws -> Value) -> ValueObservation> { return ValueObservation>(makeReducer: { diff --git a/GRDB/ValueObservation/ValueReducer/ValueReducer.swift b/GRDB/ValueObservation/ValueReducer/ValueReducer.swift index 416bc487a..3aba51534 100644 --- a/GRDB/ValueObservation/ValueReducer/ValueReducer.swift +++ b/GRDB/ValueObservation/ValueReducer/ValueReducer.swift @@ -72,8 +72,8 @@ public enum ValueReducers { } // TODO: define an empty NeverReducer enum instead of reusing Never. // This allows us to use Never as a marker for ValueObservation factory methods: // -// For example, ValueObservation.tracking(value:) is, practically, -// ValueObservation.tracking(value:). +// For example, ValueObservation.tracking(_:) is, practically, +// ValueObservation.tracking(_:). extension Never: _ValueReducer { public var isObservedRegionDeterministic: Bool { preconditionFailure() } public func fetch(_ db: Database) throws -> Never { preconditionFailure() } diff --git a/README.md b/README.md index f4b560be0..c2c671649 100644 --- a/README.md +++ b/README.md @@ -5505,7 +5505,7 @@ Tracked changes include changes performed by the [query interface](#the-query-in } // The same observation, with short-hand notation: - let observation = ValueObservation.tracking(value: Player.fetchAll) + let observation = ValueObservation.tracking(Player.fetchAll) ``` The observation can perform multiple requests, from multiple database tables, and even use raw SQL. @@ -5556,7 +5556,7 @@ import Combine import GRDB import GRDBCombine -let observation = ValueObservation.tracking(value: Player.fetchAll) +let observation = ValueObservation.tracking(Player.fetchAll) let cancellable = observation.publisher(in: dbQueue).sink( receiveCompletion: { completion in ... }, @@ -5575,7 +5575,7 @@ import GRDB import RxGRDB import RxSwift -let observation = ValueObservation.tracking(value: Player.fetchAll) +let observation = ValueObservation.tracking(Player.fetchAll) let disposable = observation.rx.changes(in: dbQueue).subscribe( onNext: { (players: [Player]) in @@ -5786,7 +5786,7 @@ When needed, you can help GRDB optimize observations and reduce database content super.viewWillAppear(animated) // Start observing the database - let observation = ValueObservation.tracking(value: Player.fetchAll) + let observation = ValueObservation.tracking(Player.fetchAll) observer = observation.start( in: dbQueue, onError: { error in ... }, @@ -5820,7 +5820,7 @@ When needed, you can help GRDB optimize observations and reduce database content import RxGRDB import RxSwift - let observation = ValueObservation.tracking(value: Player.fetchAll) + let observation = ValueObservation.tracking(Player.fetchAll) let observable = observation.rx .changes(in: dbQueue) .share(replay: 1, scope: .whileConnected) @@ -5832,7 +5832,7 @@ When needed, you can help GRDB optimize observations and reduce database content ```swift // Plain observation - let observation = ValueObservation.tracking(value: Player.fetchAll) + let observation = ValueObservation.tracking(Player.fetchAll) // Optimized observation let observation = ValueObservation.tracking(Player.all(), fetch: Player.fetchAll) diff --git a/TODO.md b/TODO.md index 098b6552c..ae384d12a 100644 --- a/TODO.md +++ b/TODO.md @@ -53,8 +53,6 @@ - [ ] https://forums.swift.org/t/how-to-encode-objects-of-unknown-type/12253/6 - [ ] Configuration.crashOnError = true - [ ] Glossary (Database Access Methods, etc.) -- [ ] ValueObservation.flatMap. Not sure it is still useful now that we have ValueObservation.tracking(value:) -- [ ] rename fetchOne to fetchFirst. Not sure because it is a big breaking change. Not sure because ValueObservation.tracking(value:) has reduced the need for observationForFirst. - [ ] Not sure: type safety for SQL expressions - [ ] Introduce some record protocol with an associated primary key type. Restrict filter(key:) methods to this type. Allow distinguishing FooId from BarId types. - [ ] Replace Column with TypedColumn. How to avoid code duplication (repeated types)? Keypaths?