Skip to content

[Fix]: valueChanges should return Observable<T|null> #1321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 23, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/firestore/document/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ import { AngularFirestoreCollection } from '../collection/collection';

/**
* AngularFirestoreDocument service
*
* This class creates a reference to a Firestore Document. A reference is provided in
*
* This class creates a reference to a Firestore Document. A reference is provided in
* in the constructor. The class is generic which gives you type safety for data update
* methods and data streaming.
*
*
* This class uses Symbol.observable to transform into Observable using Observable.from().
*
*
* This class is rarely used directly and should be created from the AngularFirestore service.
*
*
* Example:
*
*
* const fakeStock = new AngularFirestoreDocument<Stock>(firebase.firestore.doc('stocks/FAKE'));
* await fakeStock.set({ name: 'FAKE', price: 0.01 });
* fakeStock.valueChanges().map(snap => {
* fakeStock.valueChanges().map(snap => {
* if(snap.exists) return snap.data();
* return null;
* }).subscribe(value => console.log(value));
Expand All @@ -40,7 +40,7 @@ export class AngularFirestoreDocument<T> {
/**
* The contstuctor takes in a DocumentReference to provide wrapper methods
* for data operations, data streaming, and Symbol.observable.
* @param ref
* @param ref
*/
constructor(public ref: firebase.firestore.DocumentReference) { }

Expand All @@ -54,7 +54,7 @@ export class AngularFirestoreDocument<T> {

/**
* Update some fields of a document without overwriting the entire document.
* @param data
* @param data
*/
update(data: Partial<T>): Promise<void> {
return this.ref.update(data);
Expand All @@ -70,8 +70,8 @@ export class AngularFirestoreDocument<T> {
/**
* Create a reference to a sub-collection given a path and an optional query
* function.
* @param path
* @param queryFn
* @param path
* @param queryFn
*/
collection<T>(path: string, queryFn?: QueryFn): AngularFirestoreCollection<T> {
const collectionRef = this.ref.collection(path);
Expand All @@ -89,9 +89,9 @@ export class AngularFirestoreDocument<T> {
/**
* Listen to unwrapped snapshot updates from the document.
*/
valueChanges(): Observable<T> {
valueChanges(): Observable<T|null> {
return this.snapshotChanges().map(action => {
return (action.payload.exists ? action.payload.data() : null) as T;
return action.payload.exists ? action.payload.data() : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be ? action.payload.data() as T : null?

});
}
}