Skip to content

Commit

Permalink
feat(firestore): Support Firestore Settings, timestampsInSnapshots de…
Browse files Browse the repository at this point in the history
…fault to true (#1629)
  • Loading branch information
jamesdaniels authored and davideast committed May 12, 2018
1 parent b99bfa3 commit 570c0a7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/firestore/firestore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InjectionToken, NgZone, PLATFORM_ID } from '@angular/core';
import { FirebaseFirestore, CollectionReference, DocumentReference } from '@firebase/firestore-types';
import { FirebaseFirestore, CollectionReference, DocumentReference, Settings } from '@firebase/firestore-types';

import { Observable, Subscriber } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
Expand All @@ -18,7 +18,9 @@ import { FirebaseAppConfigToken, FirebaseOptionsToken, FirebaseAppNameToken, _fi
* The value of this token determines whether or not the firestore will have persistance enabled
*/
export const EnablePersistenceToken = new InjectionToken<boolean>('angularfire2.enableFirestorePersistence');
export const FirestoreSettingsToken = new InjectionToken<Settings>('angularfire2.firestore.settings');

export const DefaultFirestoreSettings = {timestampsInSnapshots: true} as Settings;

/**
* A utility methods for associating a collection reference with
Expand Down Expand Up @@ -110,13 +112,16 @@ export class AngularFirestore {
@Optional() @Inject(FirebaseAppConfigToken) config:FirebaseAppConfig,
@Optional() @Inject(FirebaseAppNameToken) name:string,
@Optional() @Inject(EnablePersistenceToken) shouldEnablePersistence: boolean,
@Optional() @Inject(FirestoreSettingsToken) settings: Settings,
@Inject(PLATFORM_ID) platformId: Object,
zone: NgZone
) {
this.scheduler = new FirebaseZoneScheduler(zone, platformId);
this.firestore = zone.runOutsideAngular(() => {
const app = _firebaseAppFactory(options, name, config);
return app.firestore();
const app = _firebaseAppFactory(config, name);
const firestore = app.firestore();
firestore.settings(settings || DefaultFirestoreSettings);
return firestore;
});

this.persistenceEnabled$ = zone.runOutsideAngular(() =>
Expand Down

0 comments on commit 570c0a7

Please sign in to comment.