State Object
The global application state containing all user data.Central state object persisted to IndexedDB
Current schema version for migrations (default: 7)
Study cycle configuration
ativo: boolean - Whether cycle mode is activeciclosCompletos: number - Completed cycles countdisciplinas: array - Disciplines in the cycle
Study planning configuration
ativo: boolean - Whether planning is activetipo: string - Planning type (‘ciclo’ or ‘semanal’)disciplinas: array - Selected discipline IDsrelevancia: object - Relevance weights by disciplinehorarios: object - Schedule configurationsequencia: array - Generated study sequence
Exam notices with disciplines and topics
Study events and sessions
Archived events (older than 90 days)
Study habits tracking by type (questoes, revisao, discursiva, etc.)
Scheduled revisions
User preferences and configuration
visualizacao: string - View mode (‘mes’, ‘semana’, ‘dia’)primeirodiaSemana: number - First day of week (0=Sunday, 1=Monday)mostrarNumeroSemana: boolean - Show week numbersagruparEventos: boolean - Group events in calendarfrequenciaRevisao: array - Revision intervals in days [1, 7, 30, 90]materiasPorDia: number - Subjects per day in planning
Free timer session state
_timerStart: number|null - Timer start timestamptempoAcumulado: number - Accumulated seconds
Exam board intelligence data
hotTopics: array - Trending topicsuserMappings: object - User topic mappingslessonMappings: object - Lesson to topic mappings
Core Functions
setState
Update the global state with normalized data.Partial or complete state object to merge
setState automatically normalizes the input, ensuring all required properties exist with default values.initDB
Initialize IndexedDB connection and load persisted state.Resolves when initialization is complete
scheduleSave
Schedule a debounced save to IndexedDB (2 second delay).- Clears any pending save timeout
- Dispatches
app:invalidateCachesevent - Dispatches
app:updateBadgesevent immediately - Schedules
saveStateToDB()to run after 2 seconds
Multiple calls within 2 seconds will debounce, only saving once.
saveStateToDB
Immediately save state to IndexedDB (bypasses debounce).Resolves when save is complete
- Dispatches
stateSavedevent - Triggers cloud sync if enabled (
state.config.cfSyncSyncEnabled)
loadStateFromDB
Load state from IndexedDB.Resolves when state is loaded
- Prevents timer persistence bugs by clearing
_timerStarton new sessions - Falls back to
loadLegacyState()if no data found - Runs migrations via
runMigrations()
loadLegacyState
Migrate state from old localStorage format to IndexedDB.clearData
Reset all application data to defaults.- Shows success toast notification
- Dispatches
app:renderCurrentViewto refresh UI
runMigrations
Execute schema migrations based onstate.schemaVersion.
- v1 → v2: Add IDs to editais, migrate grupos to disciplinas
- v2 → v3: Add arquivo array, normalize frequenciaRevisao
- v3 → v4: Add ciclo support
- v4 → v5: Add planejamento support
- v6 → v7: Separate Assuntos (topics) from Aulas (lessons)
Migrations run automatically on state load. If changes are made,
scheduleSave() is called.Sync Queue
TheSyncQueue manages sequential async operations to prevent race conditions.
SyncQueue.add
Add a task to the synchronization queue.Async function to execute
Resolves when the task completes
Constants
IndexedDB database name:
'EstudoOrganizadoDB'IndexedDB schema version:
1IndexedDB object store name:
'app_state'Current application schema version:
7Events
The Store module dispatches these custom events:app:invalidateCaches: Triggered when state changes (scheduleSave)app:updateBadges: Triggered to update UI badgesstateSaved: Triggered after successful IndexedDB save