react-native-firebase/lib/utils/ModuleBase.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

/**
* @flow
*/
import { initialiseLogger } from './log';
import { initialiseNativeModule } from './native';
import type App from '../modules/core/app';
import type { FirebaseModuleConfig, FirebaseNamespace } from '../types';
export default class ModuleBase {
_app: App;
_serviceUrl: ?string;
namespace: FirebaseNamespace;
2017-09-25 14:38:54 +00:00
2017-07-18 05:04:12 +00:00
/**
*
* @param app
* @param config
2017-07-18 05:04:12 +00:00
*/
constructor(app: App, config: FirebaseModuleConfig, serviceUrl: ?string) {
if (!config.moduleName) {
throw new Error('Missing module name');
}
if (!config.namespace) {
throw new Error('Missing namespace');
}
const { moduleName } = config;
this._app = app;
this._serviceUrl = serviceUrl;
this.namespace = config.namespace;
// check if native module exists as all native
initialiseNativeModule(this, config, serviceUrl);
2018-01-25 18:25:39 +00:00
initialiseLogger(
this,
`${app.name}:${moduleName.replace('RNFirebase', '')}`
);
}
/**
* Returns the App instance for current module
* @return {*}
*/
get app(): App {
return this._app;
}
}