Skip to content

Commit

Permalink
Allow document set options. Fixes angular#1332
Browse files Browse the repository at this point in the history
  • Loading branch information
moneal committed Nov 7, 2017
1 parent c33c3c3 commit 33ed4c4
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 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,21 +40,22 @@ 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) { }

/**
* Create or overwrite a single document.
* @param data
* @param options
*/
set(data: T): Promise<void> {
return this.ref.set(data);
set(data: T, options?: firebase.firestore.SetOptions): Promise<void> {
return this.ref.set(data, options);
}

/**
* 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 +71,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 Down

0 comments on commit 33ed4c4

Please sign in to comment.