forked from Ninjalama/streamyfin_mirror
Signed-off-by: Lance Chant <13349722+lancechant@users.noreply.github.com> Signed-off-by: lancechant <13349722+lancechant@users.noreply.github.com> Co-authored-by: Fredrik Burmester <fredrik.burmester@gmail.com> Co-authored-by: Uruk <contact@uruk.dev> Co-authored-by: Gauvain <68083474+Gauvino@users.noreply.github.com>
34 lines
978 B
TypeScript
34 lines
978 B
TypeScript
import { MMKV } from "react-native-mmkv";
|
|
|
|
declare module "react-native-mmkv" {
|
|
interface MMKV {
|
|
get<T>(key: string): T | undefined;
|
|
setAny(key: string, value: any | undefined): void;
|
|
}
|
|
}
|
|
|
|
// Add the augmentation methods directly to the MMKV prototype
|
|
// This follows the recommended pattern while adding the helper methods your app uses
|
|
MMKV.prototype.get = function <T>(key: string): T | undefined {
|
|
try {
|
|
const serializedItem = this.getString(key);
|
|
if (!serializedItem) return undefined;
|
|
return JSON.parse(serializedItem);
|
|
} catch (error) {
|
|
console.warn(`Failed to parse MMKV value for key "${key}":`, error);
|
|
return undefined;
|
|
}
|
|
};
|
|
|
|
MMKV.prototype.setAny = function (key: string, value: any | undefined): void {
|
|
try {
|
|
if (value === undefined) {
|
|
this.delete(key);
|
|
} else {
|
|
this.set(key, JSON.stringify(value));
|
|
}
|
|
} catch (error) {
|
|
console.warn(`Failed to set MMKV value for key "${key}":`, error);
|
|
}
|
|
};
|