From 3c70814cdca7e9e7760930a5a79627fe8deddc70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 11 Apr 2020 13:38:01 +0200 Subject: [PATCH] More ValueObservation migration doc --- Documentation/GRDB5MigrationGuide.md | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Documentation/GRDB5MigrationGuide.md b/Documentation/GRDB5MigrationGuide.md index 0affe87bc..9c4c124c6 100644 --- a/Documentation/GRDB5MigrationGuide.md +++ b/Documentation/GRDB5MigrationGuide.md @@ -183,6 +183,8 @@ The changes can quite impact your application. We'll describe them below, as wel // <- Here the view has already been updated. ``` + Note that the `.immediate` scheduling requires that the observation starts from the main thread. A fatal error is raised otherwise. +
GRDBCombine impact @@ -215,6 +217,39 @@ The changes can quite impact your application. We'll describe them below, as wel 3. Some value observations used to automatically remove duplicate values. This is no longer automatic. If your application relies on distinct consecutive values, use the [removeDuplicates] operator. +4. ValueObservation used to have a `scheduling` property, which was been removed. + + You can remove the explicit request to dispatch fresh values asynchronously on the main dispatch queue, because it is now the default behavior: + + ```swift + // BEFORE: GRDB 4 + var observation = ValueObservation.tracking(...) + observation.scheduling = .async(onQueue: .main, startImmediately: true) + observation.start(in: dbQueue, onError: ..., onChange: ...) + + // NEW: GRDB 5 + let queue: DispatchQueue = ... + let observation = ValueObservation.tracking(...) + observation.start(in: dbQueue, onError: ..., onChange: ...) + ``` + + For other dispatch queues, use the `scheduling` parameter of the `start` method: + + ```swift + // BEFORE: GRDB 4 + let queue: DispatchQueue = ... + var observation = ValueObservation.tracking(...) + observation.scheduling = .async(onQueue: queue, startImmediately: true) + observation.start(in: dbQueue, onError: ..., onChange: ...) + + // NEW: GRDB 5 + let queue: DispatchQueue = ... + let observation = ValueObservation.tracking(...) + observation.start(in: dbQueue, scheduling: .async(onQueue: queue), onError: ..., onChange: ...) + ``` + + The GRDB 4 `startImmediately` parameter is no longer supported: ValueObservation now always emits an initial value, without waiting for eventual changes. It is up to your application to ignore this initial value if it wants to. + ### Removed ValueObservation Methods