Files
jrshikoku/storageControl.ts
harukin-expo-dev-env bcfa24f30a Refactor navigation types and improve type safety across components
- Removed usage of `any` in navigation hooks and replaced with specific types.
- Added type definitions for navigation parameters in `navigation.ts`.
- Updated components to utilize the new navigation types for better type safety.
- Enhanced `SwitchArea` component with generic type support for boolean and string values.
- Introduced type checks and parsing functions for API responses in `mockApi` to ensure data integrity.
- Created a refactoring backlog document to track future improvements and refactoring tasks.
- Removed unused functions and cleaned up code in various components for better maintainability.
2026-08-20 23:51:09 +00:00

31 lines
877 B
TypeScript

import storage from "./storageConfig";
import * as Updates from "expo-updates";
export const AS = {
getItem: (key: string) => storage.load({ key }),
setItem: (key: string, data: unknown) =>
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 = <T>(s: {
k: string;
s: (value: T) => void;
d: T;
u?: boolean;
}) => Promise<unknown>;
export const ASCore: ASCoreProps = <T,>({ k, s, d, u }) =>
AS.getItem(k)
.then((value: T) =>
value ? s(value) : AS.setItem(k, d).then(() => u && Updates.reloadAsync())
)
.catch(() => AS.setItem(k, d).then(() => u && Updates.reloadAsync()));