@athrok/react-native-mmkv
Version:
React Native MMKV persistence wrapper for Athrok state management library.
126 lines (122 loc) • 3.92 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// react-storage/index.tsx
var react_storage_exports = {};
__export(react_storage_exports, {
PersistenceProvider: () => PersistenceProvider
});
module.exports = __toCommonJS(react_storage_exports);
var import_react = __toESM(require("react"));
var import_athrok = require("athrok");
// react-storage/utils/windowStorage.ts
var windowStorageParser = (storage) => ({
/**
* Retrieves all keys from the storage.
* @returns {string[]} - An array of keys present in the storage.
* @example
* ```ts
* const keys = localStorage.getKeys();
* console.log('Keys:', keys);
* ```
*/
getKeys: () => {
return Object.keys(storage);
},
/**
* Retrieves the value associated with the given name from the storage.
* @param name - The name of the item to retrieve.
* @returns - The value associated with the name, or null if the name does not exist in the storage.
* @example
* ```ts
* const value = localStorage.getItem('key');
* console.log('Retrieved value:', value);
* ```
*/
getItem: (name) => {
return storage.getItem(name);
},
/**
* Sets the value associated with the given name in the storage.
* @param name - The name of the item to set.
* @param value - The value to set.
* @example
* ```ts
* localStorage.setItem('key', 'value');
* ```
*/
setItem: (name, value) => {
storage.setItem(name, value);
},
/**
* Removes the item associated with the given name from the storage.
* @param name - The name of the item to remove.
* @example
* ```ts
* localStorage.removeItem('key');
* ```
*/
removeItem: (name) => {
storage.removeItem(name);
}
});
var localStorageParser = () => {
return windowStorageParser(localStorage);
};
var sessionStorageParser = () => {
return windowStorageParser(sessionStorage);
};
// react-storage/index.tsx
var LocalStoragePersistenceProvider = ({
children
}) => {
import_react.default.useState(
import_athrok.StorageManager.initialize({
storage: localStorageParser()
})
);
return children;
};
var SessionStoragePersistenceProvider = ({
children
}) => {
import_react.default.useState(
import_athrok.StorageManager.initialize({
storage: sessionStorageParser()
})
);
return children;
};
var PersistenceProvider = {
LocalStorage: LocalStoragePersistenceProvider,
SessionStorage: SessionStoragePersistenceProvider
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
PersistenceProvider
});