|
1 | | -import { NgModule, NgZone } from '@angular/core'; |
| 1 | +import { NgModule, InjectionToken } from '@angular/core'; |
2 | 2 | import { FirebaseApp, AngularFireModule } from 'angularfire2'; |
3 | 3 | import { AngularFirestore } from './firestore'; |
| 4 | +import { from } from 'rxjs/observable/from'; |
4 | 5 |
|
5 | | -export function _getAngularFirestore(app: FirebaseApp) { |
6 | | - return new AngularFirestore(app); |
| 6 | +export const EnablePersistenceToken = new InjectionToken<boolean>('EnablePersistenceToken'); |
| 7 | + |
| 8 | +export function _getAngularFirestore(app: FirebaseApp, enablePersistence: boolean) { |
| 9 | + return new AngularFirestore(app, enablePersistence); |
7 | 10 | } |
8 | 11 |
|
9 | 12 | export const AngularFirestoreProvider = { |
10 | 13 | provide: AngularFirestore, |
11 | 14 | useFactory: _getAngularFirestore, |
12 | | - deps: [ FirebaseApp ] |
| 15 | + deps: [ FirebaseApp, EnablePersistenceToken ] |
13 | 16 | }; |
14 | 17 |
|
15 | 18 | export const FIRESTORE_PROVIDERS = [ |
16 | 19 | AngularFirestoreProvider, |
| 20 | + { provide: EnablePersistenceToken, useValue: false }, |
17 | 21 | ]; |
18 | 22 |
|
19 | 23 | @NgModule({ |
20 | 24 | imports: [ AngularFireModule ], |
21 | 25 | providers: [ FIRESTORE_PROVIDERS ] |
22 | 26 | }) |
23 | | -export class AngularFirestoreModule { } |
| 27 | +export class AngularFirestoreModule { |
| 28 | + static enablePersistence() { |
| 29 | + return { |
| 30 | + ngModule: AngularFireModule, |
| 31 | + providers: [ |
| 32 | + { provide: EnablePersistenceToken, useValue: true }, |
| 33 | + AngularFirestoreProvider |
| 34 | + ] |
| 35 | + } |
| 36 | + } |
| 37 | +} |
0 commit comments