mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-24 04:24:52 +08:00
[internals] Move native events to individual modules to make it easier to see the relationship
This commit is contained in:
@@ -29,7 +29,7 @@ export default class ModuleBase {
|
||||
* @param options
|
||||
* @param withEventEmitter
|
||||
*/
|
||||
constructor(firebaseApp: FirebaseApp, options: Object, withEventEmitter: boolean = false) {
|
||||
constructor(firebaseApp: FirebaseApp, options: Object, events: string[] = []) {
|
||||
this._module = this.constructor._NATIVE_MODULE.replace('RNFirebase', '');
|
||||
this._firebaseApp = firebaseApp;
|
||||
this._appName = firebaseApp._name;
|
||||
@@ -41,9 +41,7 @@ export default class ModuleBase {
|
||||
// TODO: Get rid of
|
||||
this._native = getNativeModule(this);
|
||||
|
||||
if (withEventEmitter) {
|
||||
initialiseNativeModuleEventEmitter(this);
|
||||
}
|
||||
initialiseNativeModuleEventEmitter(this, events);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,24 +7,6 @@ import { getRawNativeModule } from './native';
|
||||
|
||||
import type ModuleBase from './ModuleBase';
|
||||
|
||||
const NATIVE_MODULE_EVENTS = {
|
||||
Storage: [
|
||||
'storage_event',
|
||||
'storage_error',
|
||||
],
|
||||
Auth: [
|
||||
'auth_state_changed',
|
||||
'phone_auth_state_changed',
|
||||
],
|
||||
Database: [
|
||||
'database_transaction_event',
|
||||
// 'database_server_offset', // TODO
|
||||
],
|
||||
Firestore: [
|
||||
'firestore_collection_sync_event',
|
||||
'firestore_document_sync_event',
|
||||
],
|
||||
};
|
||||
const NATIVE_EMITTERS: { [string]: NativeEventEmitter } = {};
|
||||
const NATIVE_SUBSCRIPTIONS: { [string]: boolean } = {};
|
||||
|
||||
@@ -70,9 +52,7 @@ const subscribeToNativeModuleEvents = (module: ModuleBase, eventName: string): v
|
||||
}
|
||||
};
|
||||
|
||||
export const initialiseNativeModuleEventEmitter = (module: ModuleBase): void => {
|
||||
const events = NATIVE_MODULE_EVENTS[module._module];
|
||||
|
||||
export const initialiseNativeModuleEventEmitter = (module: ModuleBase, events: string[]): void => {
|
||||
if (events && events.length) {
|
||||
for (let i = 0, len = events.length; i < len; i++) {
|
||||
subscribeToNativeModuleEvents(module, events[i]);
|
||||
|
||||
Reference in New Issue
Block a user