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

46 lines
998 B
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;
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) {
if (!config.moduleName) {
throw new Error('Missing module name');
}
if (!config.namespace) {
throw new Error('Missing namespace');
}
const { moduleName } = config;
this._app = app;
this.namespace = config.namespace;
// check if native module exists as all native
initialiseNativeModule(this, config);
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;
}
}