Refactor storage handling across application

- Introduced a new storageHelpers module to centralize localStorage interactions, improving code maintainability and readability.
- Updated various components and managers to utilize the new storageHelpers functions for setting, getting, and removing items from localStorage.
- Added migration logic to handle localStorage items during application initialization, ensuring compatibility with the new storage structure.
- Enhanced logging during application initialization for better debugging.
This commit is contained in:
Will Miao
2025-03-22 05:32:18 +08:00
parent bb3d73b87c
commit 19ef73a07f
11 changed files with 169 additions and 27 deletions

View File

@@ -7,6 +7,7 @@ import { HeaderManager } from './components/Header.js';
import { SettingsManager } from './managers/SettingsManager.js';
import { showToast, initTheme, initBackToTop, lazyLoadImages } from './utils/uiHelpers.js';
import { initializeInfiniteScroll } from './utils/infiniteScroll.js';
import { migrateStorageItems } from './utils/storageHelpers.js';
// Core application class
export class AppCore {
@@ -17,6 +18,8 @@ export class AppCore {
// Initialize core functionality
async initialize() {
if (this.initialized) return;
console.log('AppCore: Initializing...');
// Initialize managers
state.loadingManager = new LoadingManager();
@@ -64,6 +67,11 @@ export class AppCore {
}
}
document.addEventListener('DOMContentLoaded', () => {
// Migrate localStorage items to use the namespace prefix
migrateStorageItems();
});
// Create and export a singleton instance
export const appCore = new AppCore();