UNPKG

airbridge-react-native-sdk

Version:

Airbridge SDK for React Native

50 lines 1.96 kB
import { NativeModules } from 'react-native'; import { createInteractor } from '../architecture/Interactor'; import { check } from '../utility/check'; import { log } from '../utility/log'; import { checkJSONObject, createJSONObject } from '../utility/json'; export const createDependency = () => { }; createDependency.EventModule = () => ({ interactor: createInteractor(NativeModules.EventInteractor), }); export const createEventModule = () => { // create dependency const { interactor } = createDependency.EventModule(); // define method const trackEvent = (category, semanticAttributes, customAttributes) => { if (!check.string(category)) { log.unmatchedType('category', 'string'); return; } if (!(check.null(semanticAttributes) || check.undefined(semanticAttributes) || check.object(semanticAttributes))) { log.unmatchedType('semanticAttributes', 'object?'); return; } if (!(check.null(customAttributes) || check.undefined(customAttributes) || check.object(customAttributes))) { log.unmatchedType('customAttributes', 'object?'); return; } if (!check.null(customAttributes) && check.defined(semanticAttributes) && !checkJSONObject(semanticAttributes)) { log.nonJSONValue('semanticAttributes'); semanticAttributes = createJSONObject(semanticAttributes); } if (!check.null(customAttributes) && check.defined(customAttributes) && !checkJSONObject(customAttributes)) { log.nonJSONValue('customAttributes'); customAttributes = createJSONObject(customAttributes); } interactor.trackEvent(category, semanticAttributes, customAttributes); }; // create object return { trackEvent, }; }; //# sourceMappingURL=Event.js.map