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