diff options
author | Gil <mcg@google.com> | 2018-04-15 16:56:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-15 16:56:43 -0700 |
commit | 4de2d80e4371e50419823961789424d40561f75a (patch) | |
tree | df0248786efd946233490508557d10faf2021554 /Firestore/Example/SwiftBuildTest/main.swift | |
parent | 5368c9e22f9a6b427466e9422645d688953013c0 (diff) |
Replace `QueryListenOptions` with simple booleans (#1106)
* Replace `QueryListenOptions` with simple booleans
Instead of calling
addSnapshotListener(
options:QueryListenOptions.includeQueryMetadataChanges()
.includeDocumentMetadataChanges())
call
addSnapshotListener(includeMetadataChanges:true)
Also change `QuerySnapshot.documentChanges()` into a method which
optionally takes `includeMetadataChanges:true`. By default even when
listening to a query with `inlcudeMetadataChanges:true` metadata-only
document changes are suppressed because they're confusing.
* Revert QuerySnapshot.documentChanges back to a property
Add usage.
Diffstat (limited to 'Firestore/Example/SwiftBuildTest/main.swift')
-rw-r--r-- | Firestore/Example/SwiftBuildTest/main.swift | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Firestore/Example/SwiftBuildTest/main.swift b/Firestore/Example/SwiftBuildTest/main.swift index ad6c0f6..8de5ed4 100644 --- a/Firestore/Example/SwiftBuildTest/main.swift +++ b/Firestore/Example/SwiftBuildTest/main.swift @@ -321,6 +321,26 @@ func listenToQueryDiffs(onQuery query: Query) { listener.remove() } +func listenToQueryDiffsWithMetadata(onQuery query: Query) { + let listener = query.addSnapshotListener(includeMetadataChanges: true) { snap, error in + if let snap = snap { + for change in snap.documentChanges(includeMetadataChanges: true) { + switch change.type { + case .added: + print("New document: \(change.document.data())") + case .modified: + print("Modified document: \(change.document.data())") + case .removed: + print("Removed document: \(change.document.data())") + } + } + } + } + + // Unsubscribe + listener.remove() +} + func transactions() { let db = Firestore.firestore() @@ -361,7 +381,6 @@ func types() { let _: GeoPoint let _: Timestamp let _: ListenerRegistration - let _: QueryListenOptions let _: Query let _: QuerySnapshot let _: SnapshotMetadata |