Skip to content

Allow document set options. Fixes #1332 #1333

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 1 commit into from
Nov 17, 2017
Merged
Changes from all commits
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
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