-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathstate.js
More file actions
45 lines (37 loc) · 1.32 KB
/
state.js
File metadata and controls
45 lines (37 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Lightweight App State Management
*/
window.appState = {
currentStep: 1, // 1, 2, 3, or 'celebration'
isMusicPlaying: false,
loveValue: 100,
// Listeners for state changes
listeners: [],
subscribe(callback) {
this.listeners.push(callback);
},
setState(newState) {
const oldState = { ...this };
Object.assign(this, newState);
// Notify listeners of the change
this.listeners.forEach(callback => callback(this, oldState));
}
};
// UI Reaction logic
window.appState.subscribe((state, oldState) => {
// Handle step changes
if (state.currentStep !== oldState.currentStep) {
document.querySelectorAll('.question-section, .celebration').forEach(el => el.classList.add('hidden'));
if (state.currentStep === 'celebration') {
document.getElementById('celebration').classList.remove('hidden');
} else {
document.getElementById(`question${state.currentStep}`).classList.remove('hidden');
}
}
// Handle music state
const musicToggle = document.getElementById('musicToggle');
if (musicToggle) {
const config = window.VALENTINE_CONFIG;
musicToggle.textContent = state.isMusicPlaying ? config.music.stopText : config.music.startText;
}
});