Skip to content

Commit

Permalink
Support default app in the modular SDK (#4702)
Browse files Browse the repository at this point in the history
* support default app

* fix lint error
  • Loading branch information
Feiyang1 authored Apr 6, 2021
1 parent 5ae52a0 commit 318d9bf
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages-exp/analytics-exp/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/

import { _getProvider, FirebaseApp } from '@firebase/app-exp';
import { _getProvider, FirebaseApp, getApp } from '@firebase/app-exp';
import {
Analytics,
AnalyticsCallOptions,
Expand Down Expand Up @@ -63,7 +63,7 @@ declare module '@firebase/component' {
*
* @param app - The FirebaseApp to use.
*/
export function getAnalytics(app: FirebaseApp): Analytics {
export function getAnalytics(app: FirebaseApp = getApp()): Analytics {
app = getModularInstance(app);
// Dependencies
const analyticsProvider: Provider<'analytics-exp'> = _getProvider(
Expand Down
4 changes: 2 additions & 2 deletions packages-exp/auth-exp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { FirebaseApp, _getProvider } from '@firebase/app-exp';
import { FirebaseApp, getApp, _getProvider } from '@firebase/app-exp';

import { initializeAuth } from './src';
import { registerAuth } from './src/core/auth/register';
Expand Down Expand Up @@ -118,7 +118,7 @@ export { PhoneMultiFactorGenerator } from './src/platform_browser/mfa/assertions
*
* @public
*/
export function getAuth(app: FirebaseApp): Auth {
export function getAuth(app: FirebaseApp = getApp()): Auth {
const provider = _getProvider(app, 'auth-exp');

if (provider.isInitialized()) {
Expand Down
4 changes: 2 additions & 2 deletions packages-exp/functions-exp/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { _getProvider, FirebaseApp } from '@firebase/app-exp';
import { _getProvider, FirebaseApp, getApp } from '@firebase/app-exp';
import { FUNCTIONS_TYPE } from './constants';

import { Provider } from '@firebase/component';
Expand All @@ -39,7 +39,7 @@ export * from './public-types';
* @public
*/
export function getFunctions(
app: FirebaseApp,
app: FirebaseApp = getApp(),
regionOrCustomDomain: string = DEFAULT_REGION
): Functions {
// Dependencies
Expand Down
6 changes: 4 additions & 2 deletions packages-exp/installations-exp/src/api/get-installations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
* limitations under the License.
*/

import { FirebaseApp, _getProvider } from '@firebase/app-exp';
import { FirebaseApp, getApp, _getProvider } from '@firebase/app-exp';
import { FirebaseInstallations } from '../interfaces/public-types';

/**
* Returns an instance of FirebaseInstallations associated with the given FirebaseApp instance.
*
* @public
*/
export function getInstallations(app: FirebaseApp): FirebaseInstallations {
export function getInstallations(
app: FirebaseApp = getApp()
): FirebaseInstallations {
const installationsImpl = _getProvider(
app,
'installations-exp'
Expand Down
4 changes: 2 additions & 2 deletions packages-exp/messaging-exp/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { MessagingService } from './messaging-service';
import { Provider } from '@firebase/component';
import { deleteToken as _deleteToken } from './api/deleteToken';
import { _getProvider, FirebaseApp } from '@firebase/app-exp';
import { _getProvider, FirebaseApp, getApp } from '@firebase/app-exp';
import { getToken as _getToken } from './api/getToken';
import { onBackgroundMessage as _onBackgroundMessage } from './api/onBackgroundMessage';
import { onMessage as _onMessage } from './api/onMessage';
Expand All @@ -39,7 +39,7 @@ import { getModularInstance } from '@firebase/util';
*
* @public
*/
export function getMessaging(app: FirebaseApp): FirebaseMessaging {
export function getMessaging(app: FirebaseApp = getApp()): FirebaseMessaging {
app = getModularInstance(app);
const messagingProvider: Provider<'messaging-exp'> = _getProvider(
app,
Expand Down
7 changes: 5 additions & 2 deletions packages-exp/performance-exp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
_registerComponent,
_getProvider,
registerVersion,
FirebaseApp
FirebaseApp,
getApp
} from '@firebase/app-exp';
import {
InstanceFactory,
Expand All @@ -47,7 +48,9 @@ const DEFAULT_ENTRY_NAME = '[DEFAULT]';
* @param app - The FirebaseApp to use.
* @public
*/
export function getPerformance(app: FirebaseApp): FirebasePerformance {
export function getPerformance(
app: FirebaseApp = getApp()
): FirebasePerformance {
app = getModularInstance(app);
const provider = _getProvider(app, 'performance-exp');
const perfInstance = provider.getImmediate() as PerformanceController;
Expand Down
4 changes: 2 additions & 2 deletions packages-exp/remote-config-exp/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { _getProvider, FirebaseApp } from '@firebase/app-exp';
import { _getProvider, FirebaseApp, getApp } from '@firebase/app-exp';
import {
LogLevel as RemoteConfigLogLevel,
RemoteConfig,
Expand All @@ -36,7 +36,7 @@ import { getModularInstance } from '@firebase/util';
*
* @public
*/
export function getRemoteConfig(app: FirebaseApp): RemoteConfig {
export function getRemoteConfig(app: FirebaseApp = getApp()): RemoteConfig {
app = getModularInstance(app);
const rcProvider = _getProvider(app, RC_COMPONENT_NAME);
return rcProvider.getImmediate();
Expand Down
14 changes: 11 additions & 3 deletions packages/database/src/exp/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
* limitations under the License.
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import { _FirebaseService, _getProvider, FirebaseApp } from '@firebase/app-exp';
import {
_FirebaseService,
_getProvider,
FirebaseApp,
getApp
// eslint-disable-next-line import/no-extraneous-dependencies
} from '@firebase/app-exp';
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
import { Provider } from '@firebase/component';

Expand Down Expand Up @@ -115,7 +120,10 @@ export { ServerValue };
* provided, the SDK connects to the default instance of the Firebase App.
* @returns The `FirebaseDatabase` instance of the provided app.
*/
export function getDatabase(app: FirebaseApp, url?: string): FirebaseDatabase {
export function getDatabase(
app: FirebaseApp = getApp(),
url?: string
): FirebaseDatabase {
return _getProvider(app, 'database-exp').getImmediate({
identifier: url
}) as FirebaseDatabase;
Expand Down
5 changes: 3 additions & 2 deletions packages/firestore/src/exp/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import {
_getProvider,
_removeServiceInstance,
FirebaseApp
FirebaseApp,
getApp
// eslint-disable-next-line import/no-extraneous-dependencies
} from '@firebase/app-exp';
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
Expand Down Expand Up @@ -151,7 +152,7 @@ export function initializeFirestore(
* instance is associated with.
* @returns The `Firestore` instance of the provided app.
*/
export function getFirestore(app: FirebaseApp): FirebaseFirestore {
export function getFirestore(app: FirebaseApp = getApp()): FirebaseFirestore {
return _getProvider(app, 'firestore-exp').getImmediate() as FirebaseFirestore;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/firestore/src/lite/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import {
_getProvider,
_removeServiceInstance,
FirebaseApp
FirebaseApp,
getApp
// eslint-disable-next-line import/no-extraneous-dependencies
} from '@firebase/app-exp';
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
Expand Down Expand Up @@ -205,7 +206,7 @@ export function initializeFirestore(
* instance is associated with.
* @returns The `Firestore` instance of the provided app.
*/
export function getFirestore(app: FirebaseApp): FirebaseFirestore {
export function getFirestore(app: FirebaseApp = getApp()): FirebaseFirestore {
return _getProvider(
app,
'firestore/lite'
Expand Down
5 changes: 3 additions & 2 deletions packages/storage/exp/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

import {
_getProvider,
FirebaseApp
FirebaseApp,
getApp
// eslint-disable-next-line import/no-extraneous-dependencies
} from '@firebase/app-exp';

Expand Down Expand Up @@ -290,7 +291,7 @@ export { StringFormat } from '../src/implementation/string';
* @returns A Firebase StorageService instance.
*/
export function getStorage(
app: FirebaseApp,
app: FirebaseApp = getApp(),
bucketUrl?: string
): StorageService {
app = getModularInstance(app);
Expand Down

0 comments on commit 318d9bf

Please sign in to comment.