UNPKG

react-native-mmkv

Version:

The fastest key/value storage for React Native. ~30x faster than AsyncStorage! Works on Android, iOS and Web.

45 lines (39 loc) 1.45 kB
"use strict"; import { TurboModuleRegistry } from 'react-native'; import { ModuleNotFoundError } from './ModuleNotFoundError'; import { getMMKVPlatformContextTurboModule } from './NativeMmkvPlatformContext'; /** * IMPORTANT: These types are also in the Types.ts file. * Due to how react-native-codegen works these are required here as the spec types can not be separated from spec. * We also need the types separate to allow bypassing importing turbo module registry in web */ /** * Configures the mode of the MMKV instance. */ export let Mode = /*#__PURE__*/function (Mode) { Mode[Mode["SINGLE_PROCESS"] = 0] = "SINGLE_PROCESS"; Mode[Mode["MULTI_PROCESS"] = 1] = "MULTI_PROCESS"; return Mode; }({}); /** * Used for configuration of a single MMKV instance. */ let mmkvModule; export function getMMKVTurboModule() { try { if (mmkvModule == null) { // 1. Load MMKV TurboModule mmkvModule = TurboModuleRegistry.getEnforcing('MmkvCxx'); // 2. Get the PlatformContext TurboModule as well const platformContext = getMMKVPlatformContextTurboModule(); // 3. Initialize it with the documents directory from platform-specific context const basePath = platformContext.getBaseDirectory(); mmkvModule.initialize(basePath); } return mmkvModule; } catch (cause) { // TurboModule could not be found! throw new ModuleNotFoundError(cause); } } //# sourceMappingURL=NativeMmkv.js.map