mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-24 04:24:52 +08:00
more work on multiple apps support
This commit is contained in:
@@ -3,12 +3,16 @@ import { NativeModules } from 'react-native';
|
||||
import INTERNALS from './internals';
|
||||
|
||||
// modules
|
||||
// todo
|
||||
import Crash from './modules/crash';
|
||||
import Performance from './modules/perf';
|
||||
import RemoteConfig from './modules/config';
|
||||
import Analytics from './modules/analytics';
|
||||
import Auth, { statics as AuthStatics } from './modules/auth';
|
||||
import AdMob, { statics as AdMobStatics } from './modules/admob';
|
||||
// ----
|
||||
|
||||
|
||||
import Auth, { statics as AuthStatics } from './modules/auth';
|
||||
import RemoteConfig from './modules/config';
|
||||
import Storage, { statics as StorageStatics } from './modules/storage';
|
||||
import Database, { statics as DatabaseStatics } from './modules/database';
|
||||
import Messaging, { statics as MessagingStatics } from './modules/messaging';
|
||||
@@ -56,6 +60,10 @@ export default class FirebaseApp {
|
||||
return this._staticsOrModuleInstance('auth', AuthStatics, Auth);
|
||||
}
|
||||
|
||||
get config() {
|
||||
return this._staticsOrModuleInstance('config', {}, RemoteConfig);
|
||||
}
|
||||
|
||||
get database() {
|
||||
return this._staticsOrModuleInstance('database', DatabaseStatics, Database);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import FirebaseApp from './firebase-app';
|
||||
|
||||
// module imports
|
||||
import Auth, { statics as AuthStatics } from './modules/auth';
|
||||
import RemoteConfig from './modules/config';
|
||||
import Storage, { statics as StorageStatics } from './modules/storage';
|
||||
import Database, { statics as DatabaseStatics } from './modules/database';
|
||||
import Messaging, { statics as MessagingStatics } from './modules/messaging';
|
||||
@@ -110,6 +111,11 @@ class FirebaseCore {
|
||||
return this._appNamespaceOrStatics('auth', AuthStatics, Auth);
|
||||
}
|
||||
|
||||
get config() {
|
||||
return this._appNamespaceOrStatics('config', {}, RemoteConfig);
|
||||
}
|
||||
|
||||
|
||||
get database() {
|
||||
return this._appNamespaceOrStatics('database', DatabaseStatics, Database);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,13 @@ import INTERNALS from './../internals';
|
||||
|
||||
const logs = {};
|
||||
|
||||
// Firebase Native SDKs that support multiple app instances
|
||||
const MULTI_APP_MODULES = [
|
||||
'auth',
|
||||
'database',
|
||||
'storage',
|
||||
];
|
||||
|
||||
export default class ModuleBase {
|
||||
constructor(firebaseApp, options, moduleName, withEventEmitter = false) {
|
||||
this._options = Object.assign({}, options);
|
||||
@@ -24,7 +31,12 @@ export default class ModuleBase {
|
||||
}
|
||||
|
||||
// used by the modules that extend ModuleBase to access their native module counterpart
|
||||
this._native = nativeWithApp(this._appName, nativeModule);
|
||||
if (!MULTI_APP_MODULES.includes(moduleName.toLowerCase())) {
|
||||
this._native = nativeModule;
|
||||
} else {
|
||||
this._native = nativeWithApp(this._appName, nativeModule);
|
||||
}
|
||||
|
||||
if (withEventEmitter) {
|
||||
this._eventEmitter = new NativeEventEmitter(this._native);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user