[Build] SWC-ify, allow classes and async arrow functions (#24)
* [Build] SWC-ify, allow classes and async arrow functions * [Build] The SWC-ening is upon us. * [Build] Tidy * [Global] Make use of our newfound powers * [Build] Call bundle.close when done --------- Co-authored-by: Beef <beefers@riseup.net>
This commit is contained in:
parent
6ef8c97b86
commit
8354b3806c
5 changed files with 86 additions and 79 deletions
|
@ -5,26 +5,23 @@ const MMKVManager = RN.NativeModules.MMKVManager as MMKVManager;
|
|||
const DCDFileManager = RN.NativeModules.DCDFileManager as DCDFileManager;
|
||||
|
||||
const filePathFixer: (file: string) => string = RN.Platform.select({
|
||||
default: (f) => f,
|
||||
ios: (f) => `Documents/${f}`,
|
||||
default: (f) => f,
|
||||
ios: (f) => `Documents/${f}`,
|
||||
});
|
||||
|
||||
export const createMMKVBackend = (store: string): StorageBackend => ({
|
||||
get: async function() {
|
||||
return JSON.parse((await MMKVManager.getItem(store)) ?? "{}");
|
||||
},
|
||||
set: (data) => MMKVManager.setItem(store, JSON.stringify(data)),
|
||||
get: async () => JSON.parse((await MMKVManager.getItem(store)) ?? "{}"),
|
||||
set: (data) => MMKVManager.setItem(store, JSON.stringify(data)),
|
||||
});
|
||||
|
||||
export const createFileBackend = (file: string): StorageBackend => {
|
||||
let created: boolean;
|
||||
return {
|
||||
get: async function() {
|
||||
const path = `${DCDFileManager.getConstants().DocumentsDirPath}/${file}`;
|
||||
if (!created && !await DCDFileManager.fileExists(path))
|
||||
return (created = true, DCDFileManager.writeFile("documents", filePathFixer(file), "{}", "utf8"));
|
||||
return JSON.parse((await DCDFileManager.readFile(path, "utf8")));
|
||||
},
|
||||
set: (data) => void DCDFileManager.writeFile("documents", filePathFixer(file), JSON.stringify(data), "utf8"),
|
||||
};
|
||||
};
|
||||
let created: boolean;
|
||||
return {
|
||||
get: async () => {
|
||||
const path = `${DCDFileManager.getConstants().DocumentsDirPath}/${file}`;
|
||||
if (!created && !(await DCDFileManager.fileExists(path))) return (created = true), DCDFileManager.writeFile("documents", filePathFixer(file), "{}", "utf8");
|
||||
return JSON.parse(await DCDFileManager.readFile(path, "utf8"));
|
||||
},
|
||||
set: (data) => void DCDFileManager.writeFile("documents", filePathFixer(file), JSON.stringify(data), "utf8"),
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue