improve performance and memory utilization of clearAppData

This commit is contained in:
Niko Lockenvitz 2020-08-23 09:50:54 +02:00
parent d233220b39
commit 6ae3e2c1ae
No known key found for this signature in database
GPG key ID: 9403BD1956FFF190

View file

@ -1,4 +1,4 @@
import { showSnackbar } from './snackbarHelper';
import { showSnackbar } from "./snackbarHelper";
const LOCAL_STORAGE_APP_CONTEXT = "ffc_";
@ -25,16 +25,12 @@ export function remove(key: string): void {
}
function clearAppData(): void {
const keysToDelete = [];
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i) || "";
if (key.startsWith(LOCAL_STORAGE_APP_CONTEXT)) {
keysToDelete.push(key);
for (let i = localStorage.length - 1; i >= 0; i--) {
const key = localStorage.key(i);
if (key && key.startsWith(LOCAL_STORAGE_APP_CONTEXT)) {
localStorage.removeItem(key);
}
}
for (const key of keysToDelete) {
localStorage.removeItem(key);
}
}
export function readFromLocalStorage(context: Context) {