mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-24 04:24:52 +08:00
[typings] Continue work on flow
This commit is contained in:
@@ -8,38 +8,58 @@ import { isObject, isAndroid } from '../../utils';
|
||||
|
||||
import AdMob, { statics as AdMobStatics } from '../admob';
|
||||
import Auth, { statics as AuthStatics } from '../auth';
|
||||
import Analytics from '../analytics';
|
||||
import Crash from '../crash';
|
||||
import Performance from '../perf';
|
||||
import RemoteConfig from '../config';
|
||||
import Storage, { statics as StorageStatics } from '../storage';
|
||||
import Analytics, { statics as AnalyticsStatics } from '../analytics';
|
||||
import Config, { statics as ConfigStatics } from '../config';
|
||||
import Crash, { statics as CrashStatics } from '../crash';
|
||||
import Database, { statics as DatabaseStatics } from '../database';
|
||||
import Messaging, { statics as MessagingStatics } from '../messaging';
|
||||
import Firestore, { statics as FirestoreStatics } from '../firestore';
|
||||
import Links, { statics as LinksStatics } from '../links';
|
||||
import Messaging, { statics as MessagingStatics } from '../messaging';
|
||||
import Performance, { statics as PerformanceStatics } from '../perf';
|
||||
import Storage, { statics as StorageStatics } from '../storage';
|
||||
import Utils, { statics as UtilsStatics } from '../utils';
|
||||
|
||||
import type {
|
||||
AdMobModule,
|
||||
AnalyticsModule,
|
||||
AuthModule,
|
||||
ConfigModule,
|
||||
CrashModule,
|
||||
DatabaseModule,
|
||||
FirebaseModule,
|
||||
FirebaseModuleAndStatics,
|
||||
FirebaseOptions,
|
||||
FirebaseStatics,
|
||||
FirestoreModule,
|
||||
LinksModule,
|
||||
MessagingModule,
|
||||
PerformanceModule,
|
||||
StorageModule,
|
||||
UtilsModule,
|
||||
} from '../../types';
|
||||
|
||||
const FirebaseCoreModule = NativeModules.RNFirebase;
|
||||
|
||||
|
||||
export default class FirebaseApp {
|
||||
_extendedProps: { [string] : boolean };
|
||||
_initialized: boolean;
|
||||
_name: string;
|
||||
_namespaces: { [string]: Object };
|
||||
_namespaces: { [string]: FirebaseModule };
|
||||
_nativeInitialized: boolean;
|
||||
_options: FirebaseOptions;
|
||||
admob: () => AdMob;
|
||||
auth: () => Auth;
|
||||
analytics: () => Analytics;
|
||||
config: () => RemoteConfig;
|
||||
crash: () => Crash;
|
||||
database: () => Database;
|
||||
firestore: () => Firestore;
|
||||
links: () => Links;
|
||||
messaging: () => Messaging;
|
||||
perf: () => Performance;
|
||||
storage: () => Storage;
|
||||
utils: () => Utils;
|
||||
admob: AdMobModule;
|
||||
analytics: AnalyticsModule;
|
||||
auth: AuthModule;
|
||||
config: ConfigModule;
|
||||
crash: CrashModule;
|
||||
database: DatabaseModule;
|
||||
firestore: FirestoreModule;
|
||||
links: LinksModule;
|
||||
messaging: MessagingModule;
|
||||
perf: PerformanceModule;
|
||||
storage: StorageModule;
|
||||
utils: UtilsModule;
|
||||
|
||||
constructor(name: string, options: FirebaseOptions) {
|
||||
this._name = name;
|
||||
@@ -52,15 +72,15 @@ export default class FirebaseApp {
|
||||
|
||||
// modules
|
||||
this.admob = this._staticsOrModuleInstance(AdMobStatics, AdMob);
|
||||
this.analytics = this._staticsOrModuleInstance(AnalyticsStatics, Analytics);
|
||||
this.auth = this._staticsOrModuleInstance(AuthStatics, Auth);
|
||||
this.analytics = this._staticsOrModuleInstance({}, Analytics);
|
||||
this.config = this._staticsOrModuleInstance({}, RemoteConfig);
|
||||
this.crash = this._staticsOrModuleInstance({}, Crash);
|
||||
this.config = this._staticsOrModuleInstance(ConfigStatics, Config);
|
||||
this.crash = this._staticsOrModuleInstance(CrashStatics, Crash);
|
||||
this.database = this._staticsOrModuleInstance(DatabaseStatics, Database);
|
||||
this.firestore = this._staticsOrModuleInstance(FirestoreStatics, Firestore);
|
||||
this.links = this._staticsOrModuleInstance(LinksStatics, Links);
|
||||
this.messaging = this._staticsOrModuleInstance(MessagingStatics, Messaging);
|
||||
this.perf = this._staticsOrModuleInstance({}, Performance);
|
||||
this.perf = this._staticsOrModuleInstance(PerformanceStatics, Performance);
|
||||
this.storage = this._staticsOrModuleInstance(StorageStatics, Storage);
|
||||
this.utils = this._staticsOrModuleInstance(UtilsStatics, Utils);
|
||||
this._extendedProps = {};
|
||||
@@ -171,8 +191,8 @@ export default class FirebaseApp {
|
||||
* @return {function()}
|
||||
* @private
|
||||
*/
|
||||
_staticsOrModuleInstance(statics: Object = {}, InstanceClass: Class<*>) {
|
||||
const getInstance = () => {
|
||||
_staticsOrModuleInstance<M: FirebaseModule, S:FirebaseStatics>(statics: S, InstanceClass: Class<M>): FirebaseModuleAndStatics<M, S> {
|
||||
const getInstance = (): M => {
|
||||
const _name = `_${InstanceClass._NAMESPACE}`;
|
||||
|
||||
if (isAndroid && InstanceClass._NAMESPACE !== Utils._NAMESPACE && !INTERNALS.FLAGS.checkedPlayServices) {
|
||||
@@ -187,10 +207,8 @@ export default class FirebaseApp {
|
||||
return this._namespaces[_name];
|
||||
};
|
||||
|
||||
Object.assign(getInstance, statics, {
|
||||
return Object.assign(getInstance, statics, {
|
||||
nativeModuleExists: !!NativeModules[InstanceClass._NATIVE_MODULE],
|
||||
});
|
||||
|
||||
return getInstance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,34 +11,53 @@ import { isObject, isString } from '../../utils';
|
||||
// module imports
|
||||
import AdMob, { statics as AdMobStatics } from '../admob';
|
||||
import Auth, { statics as AuthStatics } from '../auth';
|
||||
import Analytics from '../analytics';
|
||||
import Crash from '../crash';
|
||||
import Performance from '../perf';
|
||||
import Links, { statics as LinksStatics } from '../links';
|
||||
import RemoteConfig from '../config';
|
||||
import Storage, { statics as StorageStatics } from '../storage';
|
||||
import Analytics, { statics as AnalyticsStatics } from '../analytics';
|
||||
import Config, { statics as ConfigStatics } from '../config';
|
||||
import Crash, { statics as CrashStatics } from '../crash';
|
||||
import Database, { statics as DatabaseStatics } from '../database';
|
||||
import Messaging, { statics as MessagingStatics } from '../messaging';
|
||||
import Firestore, { statics as FirestoreStatics } from '../firestore';
|
||||
import Links, { statics as LinksStatics } from '../links';
|
||||
import Messaging, { statics as MessagingStatics } from '../messaging';
|
||||
import Performance, { statics as PerformanceStatics } from '../perf';
|
||||
import Storage, { statics as StorageStatics } from '../storage';
|
||||
import Utils, { statics as UtilsStatics } from '../utils';
|
||||
|
||||
import type {
|
||||
AdMobModule,
|
||||
AnalyticsModule,
|
||||
AuthModule,
|
||||
ConfigModule,
|
||||
CrashModule,
|
||||
DatabaseModule,
|
||||
FirebaseModule,
|
||||
FirebaseModuleAndStatics,
|
||||
FirebaseOptions,
|
||||
FirebaseStatics,
|
||||
FirestoreModule,
|
||||
LinksModule,
|
||||
MessagingModule,
|
||||
PerformanceModule,
|
||||
StorageModule,
|
||||
UtilsModule,
|
||||
} from '../../types';
|
||||
|
||||
const FirebaseCoreModule = NativeModules.RNFirebase;
|
||||
|
||||
class FirebaseCore {
|
||||
_nativeEmitters: { [string]: NativeEventEmitter };
|
||||
_nativeSubscriptions: { [string]: boolean };
|
||||
admob: () => AdMob;
|
||||
auth: () => Auth;
|
||||
analytics: () => Analytics;
|
||||
config: () => RemoteConfig;
|
||||
crash: () => Crash;
|
||||
database: () => Database;
|
||||
firestore: () => Firestore;
|
||||
links: () => Links;
|
||||
messaging: () => Messaging;
|
||||
perf: () => Performance;
|
||||
storage: () => Storage;
|
||||
utils: () => Utils;
|
||||
admob: AdMobModule;
|
||||
analytics: AnalyticsModule;
|
||||
auth: AuthModule;
|
||||
config: ConfigModule;
|
||||
crash: CrashModule;
|
||||
database: DatabaseModule;
|
||||
firestore: FirestoreModule;
|
||||
links: LinksModule;
|
||||
messaging: MessagingModule;
|
||||
perf: PerformanceModule;
|
||||
storage: StorageModule;
|
||||
utils: UtilsModule;
|
||||
|
||||
constructor() {
|
||||
this._nativeEmitters = {};
|
||||
@@ -52,15 +71,15 @@ class FirebaseCore {
|
||||
|
||||
// modules
|
||||
this.admob = this._appNamespaceOrStatics(AdMobStatics, AdMob);
|
||||
this.analytics = this._appNamespaceOrStatics(AnalyticsStatics, Analytics);
|
||||
this.auth = this._appNamespaceOrStatics(AuthStatics, Auth);
|
||||
this.analytics = this._appNamespaceOrStatics({}, Analytics);
|
||||
this.config = this._appNamespaceOrStatics({}, RemoteConfig);
|
||||
this.crash = this._appNamespaceOrStatics({}, Crash);
|
||||
this.config = this._appNamespaceOrStatics(ConfigStatics, Config);
|
||||
this.crash = this._appNamespaceOrStatics(CrashStatics, Crash);
|
||||
this.database = this._appNamespaceOrStatics(DatabaseStatics, Database);
|
||||
this.firestore = this._appNamespaceOrStatics(FirestoreStatics, Firestore);
|
||||
this.links = this._appNamespaceOrStatics(LinksStatics, Links);
|
||||
this.messaging = this._appNamespaceOrStatics(MessagingStatics, Messaging);
|
||||
this.perf = this._appNamespaceOrStatics(DatabaseStatics, Performance);
|
||||
this.perf = this._appNamespaceOrStatics(PerformanceStatics, Performance);
|
||||
this.storage = this._appNamespaceOrStatics(StorageStatics, Storage);
|
||||
this.utils = this._appNamespaceOrStatics(UtilsStatics, Utils);
|
||||
}
|
||||
@@ -160,7 +179,7 @@ class FirebaseCore {
|
||||
* A (read-only) array of all initialized apps.
|
||||
* @return {Array}
|
||||
*/
|
||||
get apps(): Array<Object> {
|
||||
get apps(): Array<FirebaseApp> {
|
||||
return Object.values(INTERNALS.APPS);
|
||||
}
|
||||
|
||||
@@ -201,7 +220,7 @@ class FirebaseCore {
|
||||
* @return {function(FirebaseApp=)}
|
||||
* @private
|
||||
*/
|
||||
_appNamespaceOrStatics(statics: Object = {}, InstanceClass: Class<*>): Function {
|
||||
_appNamespaceOrStatics<M: FirebaseModule, S: FirebaseStatics>(statics: S, InstanceClass: Class<M>): FirebaseModuleAndStatics<M, S> {
|
||||
const namespace = InstanceClass._NAMESPACE;
|
||||
|
||||
const getNamespace = (app?: FirebaseApp) => {
|
||||
@@ -216,11 +235,9 @@ class FirebaseCore {
|
||||
return INTERNALS.APPS[_app._name][namespace](_app);
|
||||
};
|
||||
|
||||
Object.assign(getNamespace, statics, {
|
||||
return Object.assign(getNamespace, statics, {
|
||||
nativeModuleExists: !!NativeModules[InstanceClass._NATIVE_MODULE],
|
||||
});
|
||||
|
||||
return getNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user