[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:
redstonekasi 2023-02-26 01:34:16 +01:00 committed by GitHub
parent 6ef8c97b86
commit 8354b3806c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 86 additions and 79 deletions

View file

@ -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"),
};
};