@@ -41,7 +41,7 @@ export class AppStore {
4141 }
4242
4343 // Check if an App already exists and, if so, ensure its AppOptions match
44- // those of this initializeApp request.
44+ // those of this ` initializeApp` request.
4545 if ( this . appStore . has ( appName ) ) {
4646 const currentApp = this . appStore . get ( appName ) ! ;
4747 // Ensure the autoInit state matches the existing app's. If not, throw.
@@ -56,10 +56,11 @@ export class AppStore {
5656 // initializeApp. With no options to compare, simply return the App.
5757 return currentApp ;
5858 } else {
59- // Auto-initialization was not used.
59+ // Auto-initialization was not used. Ensure the options don't contain
60+ // incomparable fields, and that options matches the existing app's.
6061
61- // httpAgent breaks idempotency since the objects cannot be compared.
62- // Throw if a httpAgent exists in AppOptions or the existing App .
62+ // ` httpAgent` objects cannot be compared with deepEquals impls .
63+ // Idempotency cannot be supported if one exists .
6364 if ( typeof options . httpAgent !== 'undefined' ) {
6465 throw new FirebaseAppError (
6566 AppErrorCodes . INVALID_APP_OPTIONS ,
@@ -72,11 +73,12 @@ export class AppStore {
7273 throw new FirebaseAppError (
7374 AppErrorCodes . INVALID_APP_OPTIONS ,
7475 `An existing app named "${ appName } " already exists with a different` +
75- ' options configuration: httpAgent'
76+ ' options configuration: httpAgent. '
7677 ) ;
7778 }
78- // Credential breaks idempotency since the objects cannot be compared.
79- // Throw if a Credential exists in AppOptions or the existing App.
79+
80+ // `Credential` objects cannot be compared with deepEquals impls.
81+ // Idempotency cannot be supported if one exists.
8082 if ( typeof options . credential !== 'undefined' ) {
8183 throw new FirebaseAppError (
8284 AppErrorCodes . INVALID_APP_OPTIONS ,
@@ -89,13 +91,15 @@ export class AppStore {
8991 throw new FirebaseAppError (
9092 AppErrorCodes . INVALID_APP_OPTIONS ,
9193 `An existing app named "${ appName } " already exists with a different` +
92- ' options configuration: Credential'
94+ ' options configuration: Credential. '
9395 ) ;
9496 }
9597
96- // FirebaseApp() appends an instance of Credential to the `options`
97- // field upon construction (below). Run a comparison of the app's
98- // options without this auto generated Credential.
98+ // The AppOptions object has no known incomparable fields.
99+
100+ // FirebaseApp() aguments app.options with a synthesized Credential
101+ // upon App construction (below). Run a comparison w/o Credential to
102+ // see if the base configurations match. Return the existing app if so.
99103 const currentAppOptions = { ...currentApp . options } ;
100104 delete currentAppOptions . credential ;
101105 if ( deepEqual ( options , currentAppOptions ) ) {
@@ -104,7 +108,7 @@ export class AppStore {
104108 throw new FirebaseAppError (
105109 AppErrorCodes . DUPLICATE_APP ,
106110 `A Firebase app named "${ appName } " already exists with a different options` +
107- ' configuration. '
111+ ' configuration.'
108112 ) ;
109113 }
110114 }
0 commit comments