UNPKG

react-native-firebase-compiled

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

77 lines (55 loc) 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.initialiseNativeModule = exports.getNativeModule = void 0; var _reactNative = require("react-native"); var _events = require("./events"); var _internals = _interopRequireDefault(require("./internals")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const NATIVE_MODULES = {}; /** * Prepends all arguments in prependArgs to all native method calls * @param NativeModule * @param argToPrepend */ const nativeWithArgs = (NativeModule, argToPrepend) => { const native = {}; const methods = Object.keys(NativeModule); for (let i = 0, len = methods.length; i < len; i++) { const method = methods[i]; native[method] = (...args) => NativeModule[method](...[...argToPrepend, ...args]); } return native; }; const nativeModuleKey = module => `${module._customUrlOrRegion || module.app.name}:${module.namespace}`; const getNativeModule = module => NATIVE_MODULES[nativeModuleKey(module)]; exports.getNativeModule = getNativeModule; const initialiseNativeModule = (module, config, customUrlOrRegion) => { const moduleName = config.moduleName, hasMultiAppSupport = config.hasMultiAppSupport, hasCustomUrlSupport = config.hasCustomUrlSupport, hasRegionsSupport = config.hasRegionsSupport, namespace = config.namespace; const nativeModule = _reactNative.NativeModules[moduleName]; const key = nativeModuleKey(module); if (!nativeModule && namespace !== 'utils') { throw new Error(_internals.default.STRINGS.ERROR_MISSING_MODULE(namespace, moduleName)); } // used by the modules that extend ModuleBase // to access their native module counterpart const argToPrepend = []; if (hasMultiAppSupport) { argToPrepend.push(module.app.name); } if (hasCustomUrlSupport || hasRegionsSupport) { argToPrepend.push(customUrlOrRegion); } if (argToPrepend.length) { NATIVE_MODULES[key] = nativeWithArgs(nativeModule, argToPrepend); } else { NATIVE_MODULES[key] = nativeModule; } (0, _events.initialiseNativeModuleEventEmitter)(module, config); return NATIVE_MODULES[key]; }; exports.initialiseNativeModule = initialiseNativeModule;