* Each Feature of AngularFire has a FirebaseApp injected. This way we * don't rely on the main Firebase App instance and we can create named * apps and use multiple apps.
(
@Inject(FIREBASE_OPTIONS) options: FirebaseOptions,
@Optional() @Inject(FIREBASE_APP_NAME) name: string | null | undefined,
@Optional() @Inject(ENABLE_PERSISTENCE) shouldEnablePersistence: boolean | null,
@Optional() @Inject(SETTINGS) settings: Settings | null,
// eslint-disable-next-line @typescript-eslint/ban-types
@Inject(PLATFORM_ID) platformId: Object,
zone: NgZone,
public schedulers: ɵAngularFireSchedulers,
@Optional() @Inject(PERSISTENCE_SETTINGS) persistenceSettings: PersistenceSettings | null,
@Optional() @Inject(USE_EMULATOR) _useEmulator: any,
@Optional() auth: AngularFireAuth,
@Optional() @Inject(USE_AUTH_EMULATOR) useAuthEmulator: any,
@Optional() @Inject(AUTH_SETTINGS) authSettings: any, // can't use firebase.auth.AuthSettings here
@Optional() @Inject(TENANT_ID) tenantId: string | null,
@Optional() @Inject(LANGUAGE_CODE) languageCode: string | null,
@Optional() @Inject(USE_DEVICE_LANGUAGE) useDeviceLanguage: boolean | null,
@Optional() @Inject(PERSISTENCE) persistence: string | null,
@Optional() _appCheckInstances: AppCheckInstances,
)
| 129 | * apps and use multiple apps. |
| 130 | */ |
| 131 | constructor( |
| 132 | @Inject(FIREBASE_OPTIONS) options: FirebaseOptions, |
| 133 | @Optional() @Inject(FIREBASE_APP_NAME) name: string | null | undefined, |
| 134 | @Optional() @Inject(ENABLE_PERSISTENCE) shouldEnablePersistence: boolean | null, |
| 135 | @Optional() @Inject(SETTINGS) settings: Settings | null, |
| 136 | // eslint-disable-next-line @typescript-eslint/ban-types |
| 137 | @Inject(PLATFORM_ID) platformId: Object, |
| 138 | zone: NgZone, |
| 139 | public schedulers: ɵAngularFireSchedulers, |
| 140 | @Optional() @Inject(PERSISTENCE_SETTINGS) persistenceSettings: PersistenceSettings | null, |
| 141 | @Optional() @Inject(USE_EMULATOR) _useEmulator: any, |
| 142 | @Optional() auth: AngularFireAuth, |
| 143 | @Optional() @Inject(USE_AUTH_EMULATOR) useAuthEmulator: any, |
| 144 | @Optional() @Inject(AUTH_SETTINGS) authSettings: any, // can't use firebase.auth.AuthSettings here |
| 145 | @Optional() @Inject(TENANT_ID) tenantId: string | null, |
| 146 | @Optional() @Inject(LANGUAGE_CODE) languageCode: string | null, |
| 147 | @Optional() @Inject(USE_DEVICE_LANGUAGE) useDeviceLanguage: boolean | null, |
| 148 | @Optional() @Inject(PERSISTENCE) persistence: string | null, |
| 149 | @Optional() _appCheckInstances: AppCheckInstances, |
| 150 | ) { |
| 151 | const app = ɵfirebaseAppFactory(options, zone, name); |
| 152 | const useEmulator: UseEmulatorArguments | null = _useEmulator; |
| 153 | |
| 154 | if (auth) { |
| 155 | ɵauthFactory(app, zone, useAuthEmulator, tenantId, languageCode, useDeviceLanguage, authSettings, persistence); |
| 156 | } |
| 157 | |
| 158 | [this.firestore, this.persistenceEnabled$] = ɵcacheInstance(`${app.name}.firestore`, 'AngularFirestore', app.name, () => { |
| 159 | const firestore = zone.runOutsideAngular(() => app.firestore()); |
| 160 | if (settings) { |
| 161 | firestore.settings(settings); |
| 162 | } |
| 163 | if (useEmulator) { |
| 164 | firestore.useEmulator(...useEmulator); |
| 165 | } |
| 166 | |
| 167 | if (shouldEnablePersistence && !isPlatformServer(platformId)) { |
| 168 | // We need to try/catch here because not all enablePersistence() failures are caught |
| 169 | // https://github.com/firebase/firebase-js-sdk/issues/608 |
| 170 | const enablePersistence = () => { |
| 171 | try { |
| 172 | return from(firestore.enablePersistence(persistenceSettings || undefined).then(() => true, () => false)); |
| 173 | } catch (e) { |
| 174 | if (typeof console !== 'undefined') { console.warn(e); } |
| 175 | return of(false); |
| 176 | } |
| 177 | }; |
| 178 | return [firestore, zone.runOutsideAngular(enablePersistence)]; |
| 179 | } else { |
| 180 | return [firestore, of(false)]; |
| 181 | } |
| 182 | |
| 183 | }, [settings, useEmulator, shouldEnablePersistence]); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Create a reference to a Firestore Collection based on a path or |
nothing calls this directly
no test coverage detected