1 line
7.6 KiB
Text
1 line
7.6 KiB
Text
|
{"version":3,"file":"angular-fire-app.js","sources":["../../../src/app/app.ts","../../../src/app/app.module.ts","../../../src/app/firebase.ts","../../../src/app/angular-fire-app.ts"],"sourcesContent":["import { FirebaseApp as IFirebaseApp, getApps } from 'firebase/app';\nimport { from, timer } from 'rxjs';\nimport { concatMap, distinct } from 'rxjs/operators';\n\n// Need to turn the FirebaseApp interface exported by firebase/app into a class\n// as types don't work in Angular DI. We want developers to be able to inject FirebaseApp like so\n// constructor(app: FirebaseApp)\n// the cleanest way to achieve this that I found is to export a new interface and class\n// the interface just extends the interface you want to turn into the class. This informs tyepscript\n// that the class has all the same methods/properties as the interface you want to extend without\n// breaking if Firebase adds/removes APIs in future releases. This was a big problem for @angular/fire\n// back when we constructed our own class. Then in the \"new class\" we just return the FirebaseApp in the\n// constructor, this also has the added benefit of Firebase methods taking our DI class without\n// casting. E.g,\n// constructor(private app: FirebaseApp) { }\n// ngOnDestroy() { deleteApp(this.app); }\n//\n// tslint:disable-next-line:no-empty-interface\nexport interface FirebaseApp extends IFirebaseApp {}\n\nexport class FirebaseApp {\n constructor(app: IFirebaseApp) {\n return app;\n }\n}\n\nexport interface FirebaseApps extends Array<IFirebaseApp> {}\n\nexport class FirebaseApps {\n constructor() {\n return getApps();\n }\n}\n\nexport const firebaseApp$ = timer(0, 300).pipe(\n concatMap(() => from(getApps())),\n distinct(),\n);\n","import {\n Inject,\n InjectionToken,\n Injector,\n ModuleWithProviders,\n NgModule,\n NgZone,\n Optional,\n PLATFORM_ID,\n VERSION as NG_VERSION,\n} from '@angular/core';\nimport { FirebaseApp as IFirebaseApp, getApp, registerVersion } from 'firebase/app';\n\nimport { FirebaseApp, FirebaseApps } from './app';\nimport { VERSION, ɵAngularFireSchedulers } from '@angular/fire';\n\nexport function defaultFirebaseAppFactory(provided: FirebaseApp[]|undefined) {\n // Use the provided app, if there is only one, otherwise fetch the default app\n if (provided && provided.length === 1) { return provided[0]; }\n return new FirebaseApp(getApp());\n}\n\n// With FIREBASE_APPS I wanted to capture the default app instance, if it is initialized by\n// the reserved URL; ɵPROVIDED_FIREBASE_APPS is not for public consumption and serves to ensure that all\n// provideFirebaseApp(...) calls are satisfied before FirebaseApp$ or FirebaseApp is resolved\nexport const PROVIDED_FIREBASE_APPS = new InjectionToken<Array<FirebaseApp>>('angularfire2._apps');\n\n// Injecting FirebaseApp will now only inject the default Firebase App\n// this allows allows beginners to import /__/firebase/init.js to auto initialize Firebase App\n// from the reserved URL.\nconst DEFAULT_FIREBASE_APP_PROVIDER = {\n provide: FirebaseApp,\n useFactory: defaultFirebaseAppFactory,\n deps: [\n [new Optional(), PROVIDED_FIREBASE_APPS ],\n ],\n};\n\nconst FIREBASE_APPS_PROVIDER = {\n provide: FirebaseApps,\n deps: [\n [new Optional(), PROVIDED_FIREBASE_APPS ],\n ],\n};\n\nexport function firebaseAppFactory(fn: (injector: Injector) => IFirebaseApp) {\n return (zone: NgZone, injector: Injector) => {\n const app = zone.runOutsideAngular(() => fn(injector));\n return new FirebaseApp(app);\n };\n}\n\n@NgModule({\n providers: [\n DEFAULT_FIREBASE_APP_PROVIDER,\n FIREBASE_APPS_PROVIDER,\n ]\n})\nexport class FirebaseAppModule {\n // tslint:disable-next-line:ban-types\n constructor(@Inject(PLATFORM_ID) platformId: Object) {\n registerVersion('angularfire', VERSION.full, 'core');\n registerVersion('angularfire', VERSION.full, 'app');\n registerVersion('angular', NG_VERSION.full, platformId.toString());\n }\n}\n\n// Calling initializeApp({ ... }, 'name') multiple times will add more FirebaseApps into the FIREBASE_APPS\n// injec
|