diff --git a/GRDB/ValueObservation/ValueObservation.swift b/GRDB/ValueObservation/ValueObservation.swift index d837874a1..226045280 100644 --- a/GRDB/ValueObservation/ValueObservation.swift +++ b/GRDB/ValueObservation/ValueObservation.swift @@ -135,9 +135,7 @@ extension ValueObservation where Reducer == ValueReducers.Auto { _ fetch: @escaping (Database) throws -> Value) -> ValueObservation> { - ValueObservation>(makeReducer: { - ValueReducers.Fetch(isSelectedRegionDeterministic: true, fetch: fetch) - }) + .init(makeReducer: { .init(isSelectedRegionDeterministic: true, fetch: fetch) }) } /// Creates a ValueObservation which notifies the values returned by the @@ -149,8 +147,6 @@ extension ValueObservation where Reducer == ValueReducers.Auto { _ fetch: @escaping (Database) throws -> Value) -> ValueObservation> { - ValueObservation>(makeReducer: { - ValueReducers.Fetch(isSelectedRegionDeterministic: false, fetch: fetch) - }) + .init(makeReducer: { .init(isSelectedRegionDeterministic: false, fetch: fetch) }) } } diff --git a/GRDB/ValueObservation/ValueReducer/Fetch.swift b/GRDB/ValueObservation/ValueReducer/Fetch.swift index 83560b69f..9d0af1f0f 100644 --- a/GRDB/ValueObservation/ValueReducer/Fetch.swift +++ b/GRDB/ValueObservation/ValueReducer/Fetch.swift @@ -1,13 +1,27 @@ extension ValueReducers { /// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) /// - /// A reducer which pass raw fetched values through. + /// A reducer which passes raw fetched values through. /// /// :nodoc: public struct Fetch: _ValueReducer { private let _fetch: (Database) throws -> Value public let isSelectedRegionDeterministic: Bool + /// Creates a ValueReducers.Fetch reducer, which passes raw fetched + /// values through. + /// + /// - parameter isSelectedRegionDeterministic: When true, the fetching + /// function is assumed to always fetch from the same database region. + /// This information is used by ValueObserver, which can optimize the + /// observation by computing the observed region only once, and + /// performing concurrent fetches of fresh values. + /// + /// When false, the ValueObserver always fetches fresh values from the + /// writer dispatch queue, and updates its observed region on + /// each fetch. + /// + /// - parameter fetch: A function that fetches the observed value. public init(isSelectedRegionDeterministic: Bool, fetch: @escaping (Database) throws -> Value) { self.isSelectedRegionDeterministic = isSelectedRegionDeterministic self._fetch = fetch