[internals][types] Fix a couple of minor issues
This commit is contained in:
parent
80cb54ee6d
commit
d1f2b3fcfa
@ -101,10 +101,6 @@ export default class AdMob extends ModuleBase {
|
||||
rewarded(adUnit: string): RewardedVideo {
|
||||
return new RewardedVideo(this, adUnit);
|
||||
}
|
||||
|
||||
get namespace(): string {
|
||||
return 'firebase:admob';
|
||||
}
|
||||
}
|
||||
|
||||
export const statics = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
getNativeModule(this._auth)/**
|
||||
/**
|
||||
* @flow
|
||||
* User representation wrapper
|
||||
*/
|
||||
|
@ -342,10 +342,6 @@ export default class Auth extends ModuleBase {
|
||||
return this._user;
|
||||
}
|
||||
|
||||
get namespace(): string {
|
||||
return 'firebase:auth';
|
||||
}
|
||||
|
||||
/**
|
||||
* KNOWN UNSUPPORTED METHODS
|
||||
*/
|
||||
|
@ -42,7 +42,7 @@ import type {
|
||||
|
||||
const FirebaseCoreModule = NativeModules.RNFirebase;
|
||||
|
||||
class FirebaseCore {
|
||||
class Firebase {
|
||||
admob: AdMobModule;
|
||||
analytics: AnalyticsModule;
|
||||
auth: AuthModule;
|
||||
@ -114,4 +114,4 @@ class FirebaseCore {
|
||||
}
|
||||
}
|
||||
|
||||
export default new FirebaseCore();
|
||||
export default new Firebase();
|
||||
|
@ -2,7 +2,8 @@
|
||||
* @flow
|
||||
* Disconnect representation wrapper
|
||||
*/
|
||||
import { typeOf } from './../../utils';
|
||||
import { typeOf } from '../../utils';
|
||||
import { getNativeModule } from '../../utils/native';
|
||||
import type Database from './';
|
||||
import type Reference from './reference';
|
||||
|
||||
@ -32,7 +33,7 @@ export default class Disconnect {
|
||||
* @returns {*}
|
||||
*/
|
||||
set(value: string | Object): Promise<void> {
|
||||
return this._database._native.onDisconnectSet(this.path, { type: typeOf(value), value });
|
||||
return getNativeModule(this._database).onDisconnectSet(this.path, { type: typeOf(value), value });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,7 +42,7 @@ export default class Disconnect {
|
||||
* @returns {*}
|
||||
*/
|
||||
update(values: Object): Promise<void> {
|
||||
return this._database._native.onDisconnectUpdate(this.path, values);
|
||||
return getNativeModule(this._database).onDisconnectUpdate(this.path, values);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,7 +50,7 @@ export default class Disconnect {
|
||||
* @returns {*}
|
||||
*/
|
||||
remove(): Promise<void> {
|
||||
return this._database._native.onDisconnectRemove(this.path);
|
||||
return getNativeModule(this._database).onDisconnectRemove(this.path);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,6 +58,6 @@ export default class Disconnect {
|
||||
* @returns {*}
|
||||
*/
|
||||
cancel(): Promise<void> {
|
||||
return this._database._native.onDisconnectCancel(this.path);
|
||||
return getNativeModule(this._database).onDisconnectCancel(this.path);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
getNativeModule(this)/**
|
||||
/**
|
||||
* @flow
|
||||
* Database representation wrapper
|
||||
*/
|
||||
|
@ -5,10 +5,11 @@ import { initialiseLogger } from './log';
|
||||
import { initialiseNativeModule } from './native';
|
||||
|
||||
import type App from '../modules/core/firebase-app';
|
||||
import type { FirebaseModuleConfig } from '../types';
|
||||
import type { FirebaseModuleConfig, FirebaseNamespace } from '../types';
|
||||
|
||||
export default class ModuleBase {
|
||||
_app: App;
|
||||
namespace: FirebaseNamespace;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -24,6 +25,7 @@ export default class ModuleBase {
|
||||
}
|
||||
const { moduleName } = config;
|
||||
this._app = app;
|
||||
this.namespace = config.namespace;
|
||||
|
||||
// check if native module exists as all native
|
||||
initialiseNativeModule(this, config);
|
||||
|
@ -13,13 +13,19 @@ import type ModuleBase from './ModuleBase';
|
||||
|
||||
// clean up time
|
||||
|
||||
const NATIVE_LOGGERS: { [ModuleBase]: Object } = {};
|
||||
const NATIVE_LOGGERS: { [string]: Object } = {};
|
||||
|
||||
export const getLogger = (module: ModuleBase) => NATIVE_LOGGERS[module];
|
||||
const getModuleKey = (module: ModuleBase): string => `${module.app.name}:${module.namespace}`;
|
||||
|
||||
export const getLogger = (module: ModuleBase) => {
|
||||
const key = getModuleKey(module);
|
||||
return NATIVE_LOGGERS[key];
|
||||
};
|
||||
|
||||
export const initialiseLogger = (module: ModuleBase, logNamespace: string) => {
|
||||
if (!NATIVE_LOGGERS[module]) {
|
||||
NATIVE_LOGGERS[module] = require('bows')(`🔥 ${logNamespace.toUpperCase()}`);
|
||||
const key = getModuleKey(module);
|
||||
if (!NATIVE_LOGGERS[key]) {
|
||||
NATIVE_LOGGERS[key] = require('bows')(`🔥 ${logNamespace.toUpperCase()}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -16,7 +16,7 @@ const MULTI_APP_MODULES = [
|
||||
'RNFirebaseStorage',
|
||||
];
|
||||
|
||||
const NATIVE_MODULES: { [ModuleBase]: Object } = {};
|
||||
const NATIVE_MODULES: { [string]: Object } = {};
|
||||
|
||||
/**
|
||||
* Prepends appName arg to all native method calls
|
||||
@ -37,13 +37,17 @@ const nativeWithApp = (appName: string, NativeModule: Object): Object => {
|
||||
return native;
|
||||
};
|
||||
|
||||
const getModuleKey = (module: ModuleBase): string => `${module.app.name}:${module.namespace}`;
|
||||
|
||||
export const getNativeModule = (module: ModuleBase): Object => {
|
||||
return NATIVE_MODULES[module];
|
||||
const key = getModuleKey(module);
|
||||
return NATIVE_MODULES[key];
|
||||
};
|
||||
|
||||
export const initialiseNativeModule = (module: ModuleBase, config: FirebaseModuleConfig): Object => {
|
||||
const { moduleName, namespace } = config;
|
||||
const nativeModule = NativeModules[moduleName];
|
||||
const key = getModuleKey(module);
|
||||
|
||||
if (!nativeModule && namespace !== 'utils') {
|
||||
throw new Error(INTERNALS.STRINGS.ERROR_MISSING_MODULE(namespace, moduleName));
|
||||
@ -52,12 +56,12 @@ export const initialiseNativeModule = (module: ModuleBase, config: FirebaseModul
|
||||
// used by the modules that extend ModuleBase
|
||||
// to access their native module counterpart
|
||||
if (!MULTI_APP_MODULES.includes(moduleName)) {
|
||||
NATIVE_MODULES[module] = nativeModule;
|
||||
NATIVE_MODULES[key] = nativeModule;
|
||||
} else {
|
||||
NATIVE_MODULES[module] = nativeWithApp(module.app.name, nativeModule);
|
||||
NATIVE_MODULES[key] = nativeWithApp(module.app.name, nativeModule);
|
||||
}
|
||||
|
||||
initialiseNativeModuleEventEmitter(module, config);
|
||||
|
||||
return NATIVE_MODULES[module];
|
||||
return NATIVE_MODULES[key];
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user