From fc64d868ef57c181b6a70c8acaf001e2a365beae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 19 Jul 2020 12:53:48 +0200 Subject: [PATCH] [skip travis] Update observation usage --- README.md | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a0cf61de8..740f25254 100644 --- a/README.md +++ b/README.md @@ -238,17 +238,26 @@ See the [Query Interface](#the-query-interface) Be notified of database changes ```swift +// Define the observed value let observation = ValueObservation.tracking { db in try Place.fetchAll(db) } -observation.start( + +// Start observation (Vanilla GRDB) +let cancellable = observation.start( in: dbQueue, - onError: { error in - print("fresh places could not be fetched") - } - onChange: { (places: [Place]) in - print("Places have changed.") - }) + onError: { error in ... } + onChange: { (places: [Place]) in print("Fresh places: \(places)") }) + +// Start observation (Combine) +let cancellable = observation.publisher(in: dbQueue).sink( + receiveCompletion: { completion in ... }, + receiveValue: { (places: [Place]) in print("Fresh places: \(places)") }) + +// Start observation (RxSwift) +let disposable = observation.rx.observe(in: dbQueue).subscribe( + onNext: { (places: [Place]) in print("Fresh places: \(places)") }, + onError: { error in ... }) ``` See [Database Observation].