ファイルの分離
This commit is contained in:
25
storageControl.ts
Normal file
25
storageControl.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import storage from "./storageConfig";
|
||||
import * as Updates from "expo-updates";
|
||||
|
||||
export const AS = {
|
||||
getItem: (key: string) => storage.load({ key }),
|
||||
setItem: (key: string, data: any) =>
|
||||
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: string) => storage.remove({ key }),
|
||||
};
|
||||
|
||||
type ASCoreProps = (s: { k: any; s: any; d: any; u: any }) => Promise<any>;
|
||||
|
||||
export const ASCore: ASCoreProps = ({ 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()));
|
Reference in New Issue
Block a user