Skip to content

Commit

Permalink
Merge pull request #17 from RxSwiftCommunity/feature/firestore-source
Browse files Browse the repository at this point in the history
Firestore source
  • Loading branch information
arnauddorgans authored Apr 1, 2019
2 parents ff236b1 + d49cf48 commit 2bdd9dd
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Sources/Firestore/FIRDocumentReference+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,30 @@ extension Reactive where Base: DocumentReference {
}
}

/**
* Reads the document referenced by this `FIRDocumentReference`.
*
* @param source indicates whether the results should be fetched from the cache
* only (`Source.cache`), the server only (`Source.server`), or to attempt
* the server and fall back to the cache (`Source.default`).
* @param completion a block to execute once the document has been successfully read.
*/
public func getDocument(source: FirestoreSource) -> Observable<DocumentSnapshot> {
return Observable.create { observer in
self.base.getDocument(source: source) { snapshot, error in
if let error = error {
observer.onError(error)
} else if let snapshot = snapshot, snapshot.exists {
observer.onNext(snapshot)
observer.onCompleted()
} else {
observer.onError(NSError(domain: FirestoreErrorDomain, code: FirestoreErrorCode.notFound.rawValue, userInfo: nil))
}
}
return Disposables.create()
}
}

/**
* Attaches a listener for DocumentSnapshot events.
*
Expand Down

0 comments on commit 2bdd9dd

Please sign in to comment.