@@ -3,67 +3,74 @@ import * as firebase from 'firebase/app';
33import { analytics , app , auth , database , firestore , functions , messaging , performance , remoteConfig , storage } from 'firebase/app' ;
44
55// INVESTIGATE Public types don't expose FirebaseOptions or FirebaseAppConfig, is this the case anylonger?
6- export interface FirebaseOptions { [ key : string ] : any ; }
7- export interface FirebaseAppConfig { [ key : string ] : any ; }
6+ export interface FirebaseOptions {
7+ [ key : string ] : any ;
8+ }
9+
10+ export interface FirebaseAppConfig {
11+ [ key : string ] : any ;
12+ }
813
914export const FIREBASE_OPTIONS = new InjectionToken < FirebaseOptions > ( 'angularfire2.app.options' ) ;
10- export const FIREBASE_APP_NAME = new InjectionToken < string | FirebaseAppConfig | undefined > ( 'angularfire2.app.nameOrConfig' ) ;
15+ export const FIREBASE_APP_NAME = new InjectionToken < string | FirebaseAppConfig | undefined > ( 'angularfire2.app.nameOrConfig' ) ;
1116
1217// Have to implement as we need to return a class from the provider, we should consider exporting
1318// this in the firebase/app types as this is our highest risk of breaks
1419export class FirebaseApp implements Partial < app . App > {
15- name : string ;
16- options : { } ;
17- analytics : ( ) => analytics . Analytics ;
18- auth : ( ) => auth . Auth ;
19- database : ( databaseURL ?: string ) => database . Database ;
20- messaging : ( ) => messaging . Messaging ;
21- performance : ( ) => performance . Performance ;
22- storage : ( storageBucket ?: string ) => storage . Storage ;
23- delete : ( ) => Promise < void > ;
24- firestore : ( ) => firestore . Firestore ;
25- functions : ( region ?: string ) => functions . Functions ;
26- remoteConfig : ( ) => remoteConfig . RemoteConfig ;
20+ name : string ;
21+ options : { } ;
22+ analytics : ( ) => analytics . Analytics ;
23+ auth : ( ) => auth . Auth ;
24+ database : ( databaseURL ?: string ) => database . Database ;
25+ messaging : ( ) => messaging . Messaging ;
26+ performance : ( ) => performance . Performance ;
27+ storage : ( storageBucket ?: string ) => storage . Storage ;
28+ delete : ( ) => Promise < void > ;
29+ firestore : ( ) => firestore . Firestore ;
30+ functions : ( region ?: string ) => functions . Functions ;
31+ remoteConfig : ( ) => remoteConfig . RemoteConfig ;
2732}
2833
2934export const VERSION = new Version ( 'ANGULARFIRE2_VERSION' ) ;
3035
31- export function ɵfirebaseAppFactory ( options : FirebaseOptions , zone : NgZone , nameOrConfig ?: string | FirebaseAppConfig | null ) {
32- const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]' ;
33- const config = typeof nameOrConfig === 'object' && nameOrConfig || { } ;
34- config . name = config . name || name ;
35- // Added any due to some inconsistency between @firebase /app and firebase types
36- const existingApp = firebase . apps . filter ( app => app && app . name === config . name ) [ 0 ] as any ;
37- // We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
38- // Could be solved with https://github.com/firebase/firebase-js-sdk/pull/1206
39- return ( existingApp || zone . runOutsideAngular ( ( ) => firebase . initializeApp ( options , config as any ) ) ) as FirebaseApp ;
36+ export function ɵfirebaseAppFactory ( options : FirebaseOptions , zone : NgZone , nameOrConfig ?: string | FirebaseAppConfig | null ) {
37+ const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]' ;
38+ const config = typeof nameOrConfig === 'object' && nameOrConfig || { } ;
39+ config . name = config . name || name ;
40+ // Added any due to some inconsistency between @firebase /app and firebase types
41+ const existingApp = firebase . apps . filter ( app => app && app . name === config . name ) [ 0 ] as any ;
42+ // We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
43+ // Could be solved with https://github.com/firebase/firebase-js-sdk/pull/1206
44+ return ( existingApp || zone . runOutsideAngular ( ( ) => firebase . initializeApp ( options , config as any ) ) ) as FirebaseApp ;
4045}
4146
4247const FirebaseAppProvider = {
43- provide : FirebaseApp ,
44- useFactory : ɵfirebaseAppFactory ,
45- deps : [
46- FIREBASE_OPTIONS ,
47- NgZone ,
48- [ new Optional ( ) , FIREBASE_APP_NAME ]
49- ]
48+ provide : FirebaseApp ,
49+ useFactory : ɵfirebaseAppFactory ,
50+ deps : [
51+ FIREBASE_OPTIONS ,
52+ NgZone ,
53+ [ new Optional ( ) , FIREBASE_APP_NAME ]
54+ ]
5055} ;
5156
5257@NgModule ( {
53- providers : [ FirebaseAppProvider ] ,
58+ providers : [ FirebaseAppProvider ]
5459} )
5560export class AngularFireModule {
56- static initializeApp ( options : FirebaseOptions , nameOrConfig ?: string | FirebaseAppConfig ) {
57- return {
58- ngModule : AngularFireModule ,
59- providers : [
60- { provide : FIREBASE_OPTIONS , useValue : options } ,
61- { provide : FIREBASE_APP_NAME , useValue : nameOrConfig }
62- ]
63- } ;
64- }
65- constructor ( @Inject ( PLATFORM_ID ) platformId : Object ) {
66- firebase . registerVersion ( 'angularfire' , VERSION . full , platformId . toString ( ) ) ;
67- firebase . registerVersion ( 'angular' , NG_VERSION . full ) ;
68- }
61+ static initializeApp ( options : FirebaseOptions , nameOrConfig ?: string | FirebaseAppConfig ) {
62+ return {
63+ ngModule : AngularFireModule ,
64+ providers : [
65+ { provide : FIREBASE_OPTIONS , useValue : options } ,
66+ { provide : FIREBASE_APP_NAME , useValue : nameOrConfig }
67+ ]
68+ } ;
69+ }
70+
71+ // tslint:disable-next-line:ban-types
72+ constructor ( @Inject ( PLATFORM_ID ) platformId : Object ) {
73+ firebase . registerVersion ( 'angularfire' , VERSION . full , platformId . toString ( ) ) ;
74+ firebase . registerVersion ( 'angular' , NG_VERSION . full ) ;
75+ }
6976}
0 commit comments