From 8a9ccccf9399308a39bdd58727d971e9314d3150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 24 Nov 2018 14:47:34 +0100 Subject: [PATCH] Documentation --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3bde97e50..6a7aebd44 100644 --- a/README.md +++ b/README.md @@ -6435,7 +6435,7 @@ In order to track changes in the Hall of Fame, we'll use the `ValueObservation.t 1. A list of observed requests. 2. A closure that fetches a fresh value whenever one of the observed requests are modified. -In our case, any change to the `player` table can impact the Hall of Fame. We thus track the `Player.all()` request for all players, and fetch the Hall of Fame whenever players change: +In our case, any change to the `player` table can impact the Hall of Fame. We thus track the request for all players, `Player.all()`, and fetch a new Hall of Fame whenever players change: ```swift let observation = ValueObservation.tracking( @@ -6455,11 +6455,11 @@ let observer = observation.start(in: dbQueue) { hallOfFame: HallOfFame in #### Filtering out Consecutive Identical Values -It may happen that a database change does not modify the fetched values. In your Hall of Fame example, changes to the worst players do not modify the count of players, or the best players. +It may happen that a database change does not modify the fetched values. The Hall of Fame, for example, is not modified by changes that happen to the worst players. -In this case, you'll be notified with consecutive identical values. +When this happen, `ValueObservation.tracking(_:fetch:)` will notify identical consecutive values. -You can filter out those duplicates with the `ValueObservation.tracking(_:fetchDistinct:)` method. It requires the fetched value to adopt the Equatable protocol: +In order to filter out those duplicates, use `ValueObservation.tracking(_:fetchDistinct:)` instead. It requires the observed value to adopt the Equatable protocol: ```swift extension HallOfFame: Equatable { ... } @@ -6489,6 +6489,8 @@ protocol DatabaseRegionConvertible { } ``` +[DatabaseRegion](#databaseregion) is a type that helps observing the database. + Use this protocol when you want to encapsulate your complex requests in a dedicated type. In the sample code below, `TeamInfoRequest` is not only able to fetch a team and its players, but also to be observed. ```swift @@ -6538,8 +6540,6 @@ let observer = ValueObservation } ``` -See [DatabaseRegion](#databaseregion) for more information. - ### ValueObservation.tracking(_:reducer:)