import { Inject , InjectionToken , Injector , ModuleWithProviders , NgModule , NgZone , Optional , PLATFORM_ID , VERSION as NG_VERSION , } from '@angular/core' ; import { FirebaseApp as IFirebaseApp , getApp , registerVersion } from 'firebase/app' ; import { FirebaseApp , FirebaseApps } from './app' ; import { VERSION , ɵAngularFireSchedulers } from '@angular/fire' ; export function defaultFirebaseAppFactory ( provided ) { if ( provided && provided . length === 1 ) { return provided [ 0 ] ; } return new FirebaseApp ( getApp ( ) ) ; } export const PROVIDED_FIREBASE_APPS = new InjectionToken < Array < FirebaseApp > > ( 'angularfire2._apps' ) ; const DEFAULT_FIREBASE_APP_PROVIDER = { provide : FirebaseApp , useFactory : defaultFirebaseAppFactory , deps : [ [ new Optional ( ) , PROVIDED_FIREBASE_APPS ] , ] , } ; const FIREBASE_APPS_PROVIDER = { provide : FirebaseApps , deps : [ [ new Optional ( ) , PROVIDED_FIREBASE_APPS ] , ] , } ; export function firebaseAppFactory ( fn ) { return ( zone , injector ) => { const app = zone . runOutsideAngular ( ( ) => fn ( injector ) ) ; return new FirebaseApp ( app ) ; } ; } @ NgModule ( { providers : [ DEFAULT_FIREBASE_APP_PROVIDER , FIREBASE_APPS_PROVIDER , ] } ) export class FirebaseAppModule { constructor ( @ Inject ( PLATFORM_ID ) platformId ) { registerVersion ( 'angularfire' , VERSION . full , 'core' ) ; registerVersion ( 'angularfire' , VERSION . full , 'app' ) ; registerVersion ( 'angular' , NG_VERSION . full , platformId . toString ( ) ) ; } } export function provideFirebaseApp ( fn , ... deps ) { return { ngModule : FirebaseAppModule , providers : [ { provide : PROVIDED_FIREBASE_APPS , useFactory : firebaseAppFactory ( fn ) , multi : true , deps : [ NgZone , Injector , ɵAngularFireSchedulers , ... deps , ] , } ] , } ; }