@react-native-firebase/app
Version:
A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Functions, Messaging (FCM), Remote Config, Sto
45 lines (44 loc) • 1.69 kB
JavaScript
;
/* eslint-disable no-console */
import RNFBAppModule from "./web/RNFBAppModule.js";
const nativeModuleRegistry = {};
export function getReactNativeModule(moduleName) {
const nativeModule = nativeModuleRegistry[moduleName];
// Throw an error if the module is not registered.
if (!nativeModule) {
throw new Error(`Native module ${moduleName} is not registered.`);
}
if (!globalThis.RNFBDebug) {
return nativeModule;
}
return new Proxy(nativeModule, {
ownKeys(target) {
// FIXME - test in new arch context - I don't think Object.keys works
return Object.keys(target);
},
get: (_, name) => {
const prop = nativeModule[name];
if (typeof prop !== 'function') return prop;
return (...args) => {
console.debug(`[RNFB->Native][🔵] ${moduleName}.${String(name)} -> ${JSON.stringify(args)}`);
const result = prop(...args);
if (result && typeof result === 'object' && 'then' in result) {
return result.then(res => {
console.debug(`[RNFB<-Native][🟢] ${moduleName}.${String(name)} <- ${JSON.stringify(res)}`);
return res;
}, err => {
console.debug(`[RNFB<-Native][🔴] ${moduleName}.${String(name)} <- ${JSON.stringify(err)}`);
throw err;
});
}
console.debug(`[RNFB<-Native][🟢] ${moduleName}.${String(name)} <- ${JSON.stringify(result)}`);
return result;
};
}
});
}
export function setReactNativeModule(moduleName, nativeModule) {
nativeModuleRegistry[moduleName] = nativeModule;
}
setReactNativeModule('RNFBAppModule', RNFBAppModule);
//# sourceMappingURL=nativeModuleWeb.js.map