-
Notifications
You must be signed in to change notification settings - Fork 938
modular autoinit #6526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modular autoinit #6526
Changes from all commits
1ee90c7
233cc69
4ad6213
3bf4ce6
5456dbf
f46b60f
ad9bb94
89dfe97
5cd1a55
6acc816
c1757f7
4bc0bcf
cf7b8fc
cd3f7e1
28ab641
87c03a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
'@firebase/app': minor | ||
'@firebase/app-types': minor | ||
'@firebase/util': minor | ||
'@firebase/auth': patch | ||
'@firebase/database': patch | ||
'@firebase/firestore': patch | ||
'@firebase/functions': patch | ||
'@firebase/storage': patch | ||
'firebase': minor | ||
--- | ||
|
||
Add functionality to auto-initialize project config and emulator settings from global defaults provided by framework tooling. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ import { | |
LogOptions, | ||
setUserLogHandler | ||
} from '@firebase/logger'; | ||
import { deepEqual } from '@firebase/util'; | ||
import { deepEqual, getDefaultAppConfig } from '@firebase/util'; | ||
|
||
export { FirebaseError } from '@firebase/util'; | ||
|
||
|
@@ -110,10 +110,18 @@ export function initializeApp( | |
options: FirebaseOptions, | ||
config?: FirebaseAppSettings | ||
): FirebaseApp; | ||
/** | ||
* Creates and initializes a FirebaseApp instance. | ||
* | ||
* @public | ||
*/ | ||
export function initializeApp(): FirebaseApp; | ||
export function initializeApp( | ||
options: FirebaseOptions, | ||
_options?: FirebaseOptions, | ||
rawConfig = {} | ||
): FirebaseApp { | ||
let options = _options; | ||
|
||
if (typeof rawConfig !== 'object') { | ||
const name = rawConfig; | ||
rawConfig = { name }; | ||
|
@@ -132,6 +140,12 @@ export function initializeApp( | |
}); | ||
} | ||
|
||
options ||= getDefaultAppConfig(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First time seeing this syntax. Thank you for the education https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was James, heh. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Just mind that it overrides all falsy values—false, 0, "", null, undefined, NaN, etc. This can be surprise folk, especially with ints. You can use the nullish form, |
||
|
||
if (!options) { | ||
throw ERROR_FACTORY.create(AppError.NO_OPTIONS); | ||
} | ||
|
||
const existingApp = _apps.get(name) as FirebaseAppImpl; | ||
if (existingApp) { | ||
// return the existing app if options and config deep equal the ones in the existing app. | ||
|
@@ -188,6 +202,9 @@ export function initializeApp( | |
*/ | ||
export function getApp(name: string = DEFAULT_ENTRY_NAME): FirebaseApp { | ||
const app = _apps.get(name); | ||
if (!app && name === DEFAULT_ENTRY_NAME) { | ||
return initializeApp(); | ||
} | ||
if (!app) { | ||
throw ERROR_FACTORY.create(AppError.NO_APP, { appName: name }); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.