How to use the @unimodules/core.EventEmitter function in @unimodules/core

To help you get started, we’ve selected a few @unimodules/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / expo / packages / expo-file-system / build / FileSystem.js View on Github external
import UUID from 'uuid-js';
import { Platform } from 'react-native';
import { EventEmitter, UnavailabilityError } from '@unimodules/core';
import ExponentFileSystem from './ExponentFileSystem';
import { EncodingType, } from './FileSystem.types';
if (!ExponentFileSystem) {
    console.warn("No native ExponentFileSystem module found, are you sure the expo-file-system's module is linked properly?");
}
// Prevent webpack from pruning this.
const _unused = new EventEmitter(ExponentFileSystem); // eslint-disable-line
export { EncodingType, };
function normalizeEndingSlash(p) {
    if (p != null) {
        return p.replace(/\/*$/, '') + '/';
    }
    return null;
}
export const documentDirectory = normalizeEndingSlash(ExponentFileSystem.documentDirectory);
export const cacheDirectory = normalizeEndingSlash(ExponentFileSystem.cacheDirectory);
export const { bundledAssets, bundleDirectory } = ExponentFileSystem;
export async function getInfoAsync(fileUri, options = {}) {
    if (!ExponentFileSystem.getInfoAsync) {
        throw new UnavailabilityError('expo-file-system', 'getInfoAsync');
    }
    return await ExponentFileSystem.getInfoAsync(fileUri, options);
}
github expo / expo / packages / expo-av / src / Audio / Recording.ts View on Github external
},
};

// TODO: For consistency with PlaybackStatus, should we include progressUpdateIntervalMillis here as
// well?
export type RecordingStatus = {
  canRecord: boolean;
  isRecording: boolean;
  isDoneRecording: boolean;
  durationMillis: number;
};

export { PermissionResponse, PermissionStatus };

let _recorderExists: boolean = false;
const eventEmitter = Platform.OS === 'android' ? new EventEmitter(ExponentAV) : null;

export async function getPermissionsAsync(): Promise {
  return ExponentAV.getPermissionsAsync();
}

export async function requestPermissionsAsync(): Promise {
  return ExponentAV.requestPermissionsAsync();
}

export class Recording {
  _subscription: Subscription | null = null;
  _canRecord: boolean = false;
  _isDoneRecording: boolean = false;
  _finalDurationMillis: number = 0;
  _uri: string | null = null;
  _onRecordingStatusUpdate: ((status: RecordingStatus) => void) | null = null;
github expo / expo / packages / expo-ads-admob / build / AdMobInterstitial.js View on Github external
import { EventEmitter, UnavailabilityError } from '@unimodules/core';
import AdMobNativeModule from './ExpoAdsAdMobInterstitialManager';
import { setTestDeviceIDAsync } from './AdMob';
const moduleName = 'AdMobInterstitial';
const eventNames = [
    'interstitialDidLoad',
    'interstitialDidFailToLoad',
    'interstitialDidOpen',
    'interstitialDidClose',
    'interstitialWillLeaveApplication',
];
const eventEmitter = new EventEmitter(AdMobNativeModule);
const eventHandlers = {};
for (const eventName of eventNames) {
    eventHandlers[eventName] = new Map();
}
export default {
    async setAdUnitID(id) {
        if (!AdMobNativeModule.setAdUnitID) {
            throw new UnavailabilityError(moduleName, 'setAdUnitID');
        }
        await AdMobNativeModule.setAdUnitID(id);
    },
    async setTestDeviceID(id) {
        console.warn('AdMobInterstitial.setTestDeviceID is deprecated. Test device IDs are now set globally. Use AdMob.setTestDeviceIDAsync instead.');
        await setTestDeviceIDAsync(id);
    },
    async requestAdAsync(options = {}) {
github Marwan01 / food-converter / node_modules / expo / build / ScreenOrientation / ScreenOrientation.js View on Github external
import { EventEmitter, Platform, UnavailabilityError } from '@unimodules/core';
import ExpoScreenOrientation from './ExpoScreenOrientation';
import { Orientation, OrientationLock, SizeClassIOS, WebOrientationLock, } from './ScreenOrientation.types';
export { Orientation, OrientationLock, SizeClassIOS, WebOrientationLock, };
const _orientationChangeEmitter = new EventEmitter(ExpoScreenOrientation);
let _orientationChangeSubscribers = [];
let _lastOrientationLock = OrientationLock.UNKNOWN;
export function allow(orientationLock) {
    console.warn("'ScreenOrientation.allow' is deprecated in favour of 'ScreenOrientation.lockAsync' and will be removed in SDK 35 or later");
    lockAsync(orientationLock);
}
export async function allowAsync(orientationLock) {
    console.warn("'ScreenOrientation.allowAsync' is deprecated in favour of 'ScreenOrientation.lockAsync'");
    await lockAsync(orientationLock);
}
export async function lockAsync(orientationLock) {
    if (!ExpoScreenOrientation.lockAsync) {
        throw new UnavailabilityError('ScreenOrientation', 'lockAsync');
    }
    const orientationLocks = Object.values(OrientationLock);
    if (!orientationLocks.includes(orientationLock)) {
github Marwan01 / food-converter / node_modules / expo-task-manager / src / TaskManager.ts View on Github external
error: TaskError | null,
  executionInfo: {
    eventId: string,
    taskName: string,
  },
}

export interface RegisteredTask {
  taskName: string,
  taskType: string,
  options: any,
}

type Task = (body: TaskBody) => void;

const eventEmitter = new EventEmitter(ExpoTaskManager);
const tasks: Map = new Map();

let isRunningDuringInitialization = true;

function _validateTaskName(taskName) {
  if (!taskName || typeof taskName !== 'string') {
    throw new TypeError('`taskName` must be a non-empty string.')
  }
}

export function defineTask(taskName: string, task: Task) {
  if (!isRunningDuringInitialization) {
    console.error(`TaskManager.defineTask must be called during initialization phase!`);
    return;
  }
  if (!taskName || typeof taskName !== 'string') {
github expo / expo / packages / expo-task-manager / src / TaskManager.ts View on Github external
error: TaskError | null;
  executionInfo: {
    eventId: string;
    taskName: string;
  };
}

export interface RegisteredTask {
  taskName: string;
  taskType: string;
  options: any;
}

type Task = (body: TaskBody) => void;

const eventEmitter = new EventEmitter(ExpoTaskManager);
const tasks: Map = new Map();

let isRunningDuringInitialization = true;

function _validateTaskName(taskName) {
  if (!taskName || typeof taskName !== 'string') {
    throw new TypeError('`taskName` must be a non-empty string.');
  }
}

export function defineTask(taskName: string, task: Task) {
  if (!isRunningDuringInitialization) {
    console.error(`TaskManager.defineTask must be called during initialization phase!`);
    return;
  }
  if (!taskName || typeof taskName !== 'string') {
github expo / expo / packages / expo-file-system / build / FileSystem.js View on Github external
constructor(url, fileUri, options = {}, callback, resumeData) {
        this._uuid = UUID.create(4).toString();
        this._url = url;
        this._fileUri = fileUri;
        this._options = options;
        this._resumeData = resumeData;
        this._callback = callback;
        this._subscription = null;
        this._emitter = new EventEmitter(ExponentFileSystem);
    }
    async downloadAsync() {
github Marwan01 / food-converter / node_modules / expo-location / src / ExpoLocation.web.ts View on Github external
}

interface PermissionResult {
  status: string;
}

class GeocoderError extends Error {
  code: string;

  constructor() {
    super('Geocoder service is not available for this device.');
    this.code = 'E_NO_GEOCODER';
  }
}

const emitter = new EventEmitter({} as any);

function positionToJSON(position: any): Position | null {
  if (!position) return null;

  const { coords = {}, timestamp } = position;
  return {
    coords: {
      latitude: coords.latitude,
      longitude: coords.longitude,
      altitude: coords.altitude,
      accuracy: coords.accuracy,
      altitudeAccuracy: coords.altitudeAccuracy,
      heading: coords.heading,
      speed: coords.speed,
    },
    timestamp,
github expo / expo / packages / expo-wallet / src / Wallet.ts View on Github external
import { UnavailabilityError, EventEmitter, Subscription, Platform } from '@unimodules/core';

import { PassViewFinishListener } from './Wallet.types';
import ExpoWallet from './ExpoWallet';
import AddPassButton from './AddPassButton';

const WalletEventEmitter = new EventEmitter(ExpoWallet);

export async function canAddPassesAsync(): Promise {
  if (!ExpoWallet.canAddPassesAsync) {
    return false;
  }
  return await ExpoWallet.canAddPassesAsync();
}

export async function addPassFromUrlAsync(url: string): Promise {
  if (!ExpoWallet.addPassFromUrlAsync) {
    throw new UnavailabilityError('expo-wallet', 'addPassFromUrlAsync');
  }
  return await ExpoWallet.addPassFromUrlAsync(url);
}

export function addPassViewDidFinishListener(
github expo / expo / packages / expo / build / ScreenOrientation / ScreenOrientation.js View on Github external
import { EventEmitter, Platform, UnavailabilityError } from '@unimodules/core';
import ExpoScreenOrientation from './ExpoScreenOrientation';
import { Orientation, OrientationLock, SizeClassIOS, WebOrientationLock, } from './ScreenOrientation.types';
export { Orientation, OrientationLock, SizeClassIOS, WebOrientationLock, };
const _orientationChangeEmitter = new EventEmitter(ExpoScreenOrientation);
let _orientationChangeSubscribers = [];
let _lastOrientationLock = OrientationLock.UNKNOWN;
export async function lockAsync(orientationLock) {
    if (!ExpoScreenOrientation.lockAsync) {
        throw new UnavailabilityError('ScreenOrientation', 'lockAsync');
    }
    const orientationLocks = Object.values(OrientationLock);
    if (!orientationLocks.includes(orientationLock)) {
        throw new TypeError(`Invalid Orientation Lock: ${orientationLock}`);
    }
    if (orientationLock === OrientationLock.OTHER) {
        return;
    }
    await ExpoScreenOrientation.lockAsync(orientationLock);
    _lastOrientationLock = orientationLock;
}