UNPKG

airbridge-react-native-sdk

Version:

Airbridge SDK for React Native

39 lines 1.28 kB
import { NativeModules, NativeEventEmitter } from 'react-native'; import { createInteractor } from '../architecture/Interactor'; import { check } from '../utility/check'; import { log } from '../utility/log'; export const createDependency = () => { }; createDependency.AttributionModule = () => ({ emitter: new NativeEventEmitter(NativeModules.AttributionInteractor), interactor: createInteractor(NativeModules.AttributionInteractor), }); export const createAttributionModule = () => { // create dependency const { emitter, interactor } = createDependency.AttributionModule(); let cache; let listener = (result) => { cache = result; }; // initialize emitter.addListener('airbridge.attribution', (result) => { listener(result); }); interactor.listen(); // define method const setOnAttributionReceived = (onReceived) => { if (!check.function(onReceived)) { log.unmatchedType('onReceived', 'function'); return; } if (cache !== undefined) { onReceived(cache); cache = undefined; } listener = onReceived; }; // create object return { setOnAttributionReceived, }; }; //# sourceMappingURL=Attribution.js.map