jrshikoku/storageControl.js
harukin-expo-dev-env 1a10bee3c8 部分整理とts化
2024-08-20 07:34:59 +00:00

23 lines
697 B
JavaScript

import storage from "./storageConfig";
import * as Updates from "expo-updates";
export const AS = {
getItem: (key) => storage.load({ key }),
setItem: (key, data) =>
storage.save({
key, // Note: Do not use underscore("_") in key!
data,
// if expires not specified, the defaultExpires will be applied instead.
// if set to null, then it will never expire.
expires: null,
}),
removeItem: (key) => storage.remove({ key }),
};
export const ASCore = ({ k, s, d, u }) =>
AS.getItem(k)
.then((d) =>
d ? s(d) : AS.setItem(k, d).then(() => u && Updates.reloadAsync())
)
.catch(() => AS.setItem(k, d).then(() => u && Updates.reloadAsync()));