From b6a61139350a2dad51bf620c450c746bbfe6536f Mon Sep 17 00:00:00 2001 From: Tim Blakely Date: Fri, 3 Nov 2017 12:04:11 -0700 Subject: [PATCH 1/2] [Fix]: valueChanges should return Observable --- src/firestore/document/document.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/firestore/document/document.ts b/src/firestore/document/document.ts index d1ce5d3db..9514674b0 100644 --- a/src/firestore/document/document.ts +++ b/src/firestore/document/document.ts @@ -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(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)); @@ -40,7 +40,7 @@ export class AngularFirestoreDocument { /** * 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) { } @@ -54,7 +54,7 @@ export class AngularFirestoreDocument { /** * Update some fields of a document without overwriting the entire document. - * @param data + * @param data */ update(data: Partial): Promise { return this.ref.update(data); @@ -70,8 +70,8 @@ export class AngularFirestoreDocument { /** * Create a reference to a sub-collection given a path and an optional query * function. - * @param path - * @param queryFn + * @param path + * @param queryFn */ collection(path: string, queryFn?: QueryFn): AngularFirestoreCollection { const collectionRef = this.ref.collection(path); @@ -89,9 +89,9 @@ export class AngularFirestoreDocument { /** * Listen to unwrapped snapshot updates from the document. */ - valueChanges(): Observable { + valueChanges(): Observable { return this.snapshotChanges().map(action => { - return (action.payload.exists ? action.payload.data() : null) as T; + return action.payload.exists ? action.payload.data() : null; }); } } From e5e3d9aa3fc7a0998a6d07ae3ba02bf75e49845e Mon Sep 17 00:00:00 2001 From: James Daniels Date: Tue, 23 Jan 2018 09:24:13 -0800 Subject: [PATCH 2/2] Cast data as T --- src/firestore/document/document.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/firestore/document/document.ts b/src/firestore/document/document.ts index 9514674b0..410d2b21b 100644 --- a/src/firestore/document/document.ts +++ b/src/firestore/document/document.ts @@ -91,7 +91,7 @@ export class AngularFirestoreDocument { */ valueChanges(): Observable { return this.snapshotChanges().map(action => { - return action.payload.exists ? action.payload.data() : null; + return action.payload.exists ? action.payload.data() as T : null; }); } }