UNPKG

@react-native-firebase/app

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

73 lines (64 loc) 2.32 kB
"use strict"; /* * Copyright (c) 2016-present Invertase Limited & Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this library except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ // Memory storage Map instance export const memoryStorage = new Map(); // Storage key prefix export const prefix = '@react-native-firebase:'; const asyncStorageMemory = { setItem(key, value) { memoryStorage.set(key, value); return Promise.resolve(); }, getItem(key) { const hasValue = memoryStorage.has(key); if (hasValue) { return Promise.resolve(memoryStorage.get(key) || null); } return Promise.resolve(null); }, removeItem(key) { memoryStorage.delete(key); return Promise.resolve(); } }; let asyncStorage = asyncStorageMemory; // Get the current AsyncStorage instance (either React Native AsyncStorage or memory storage) export async function getReactNativeAsyncStorageInternal() { return asyncStorage; } // Set the AsyncStorage instance to use (React Native AsyncStorage or fallback to memory storage) export function setReactNativeAsyncStorageInternal(asyncStorageInstance) { asyncStorage = asyncStorageInstance || asyncStorageMemory; } // Check if currently using memory storage (fallback) export function isMemoryStorage() { return asyncStorage === asyncStorageMemory; } // Set an item in storage with the React Native Firebase prefix export async function setItem(key, value) { return await asyncStorage.setItem(prefix + key, value); } // Get an item from storage with the React Native Firebase prefix export async function getItem(key) { return await asyncStorage.getItem(prefix + key); } // Remove an item from storage with the React Native Firebase prefix export async function removeItem(key) { return await asyncStorage.removeItem(prefix + key); } //# sourceMappingURL=asyncStorage.js.map