Skip to content

Commit

Permalink
removed top-level await, update CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
kamranasad7 committed Apr 18, 2024
1 parent 9c9628e commit 273d84f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
Binary file modified CHANGELOG.md
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/ReactiveStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ class Crypto {
}
}

const encryption = await Crypto.createInstance();
const encryption = Crypto.createInstance();
export { encryption };
10 changes: 5 additions & 5 deletions lib/hooks/useLsState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ const get = async <T>(key: string): Promise<T | null> => {
if (value === null) { return value; }

if (ReactiveStorage.isEncrypted()) {
return JSON.parse(await encryption.decrypt(value)) as T;
return JSON.parse(await (await encryption).decrypt(value)) as T;
}
else return JSON.parse(value) as T;
}

const set = async <T>(key: string, value: T | null): Promise<void> => {
if (ReactiveStorage.isEncrypted()) {
localStorage.setItem(key, await encryption.encrypt(JSON.stringify(value)))
localStorage.setItem(key, await (await encryption).encrypt(JSON.stringify(value)))
}
else localStorage.setItem(key, JSON.stringify(value));
}
Expand All @@ -28,7 +28,7 @@ const useLsState = <T>(key: string, defaultValue?: T): [T | null, (value: T) =>
}

const onStorageChange = async (e: StorageEvent) => {
if(e.key == key) { _setState(await get(key)); }
if (e.key == key) { _setState(await get(key)); }
}

useEffect(() => {
Expand All @@ -38,10 +38,10 @@ const useLsState = <T>(key: string, defaultValue?: T): [T | null, (value: T) =>
};

getInitialValue();

window.addEventListener('storage', onStorageChange);
return () => window.removeEventListener('storage', onStorageChange);
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

return [state, setState];
Expand Down
2 changes: 0 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import { dirname } from 'path';
import { fileURLToPath } from 'url';
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'
import topLevelAwait from "vite-plugin-top-level-await";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export default defineConfig({
plugins: [
dts({ include: "lib", insertTypesEntry: true, }),
topLevelAwait({}),
],
build: {
copyPublicDir: false,
Expand Down

0 comments on commit 273d84f

Please sign in to comment.