@@ -16,7 +16,7 @@ class PassedState {
16
16
const rawState = this . _prepareState ( initialState ) ;
17
17
18
18
// check new state and old state whether is undefined or not. and merge the new state to the old state.
19
- const state = this . _checkAndMerge ( currentState , rawState ) ;
19
+ const state = this . _checkAndMerge ( JSON . parse ( currentState ) , rawState ) ;
20
20
this . _save ( state ) ;
21
21
this . _state = state ;
22
22
return
@@ -84,12 +84,16 @@ class PassedState {
84
84
throw new Error ( 'one of the new state and the old state is required.' ) ;
85
85
}
86
86
87
- if ( ! newState ) {
87
+ if ( ! oldState && newState ) {
88
+ return newState ;
89
+ }
90
+
91
+ if ( ! newState && oldState ) {
88
92
return oldState ;
89
93
}
90
94
91
95
let mergedState = { } ;
92
- const levels = [ 'basic' , 'intermediate' , 'advanced' , 'expert ' ] ;
96
+ const levels = [ 'basic' , 'intermediate' , 'advanced' , 'extreme ' ] ;
93
97
94
98
for ( const level of levels ) {
95
99
// Initialize an empty array for merged challenges
@@ -101,13 +105,8 @@ class PassedState {
101
105
102
106
// Add or update challenges from the newState
103
107
for ( const [ name , newChallenge ] of newChallengesMap . entries ( ) ) {
104
- mergedChallenges . push ( { ...newChallenge , passed : oldChallengesMap . get ( name ) ?. passed } ) ;
105
- oldChallengesMap . delete ( name ) ; // Remove the challenge from oldChallengesMap since it's updated
106
- }
107
-
108
- // Add remaining challenges from the oldState that are not updated (not present in newState)
109
- for ( const oldChallenge of oldChallengesMap . values ( ) ) {
110
- mergedChallenges . push ( oldChallenge ) ;
108
+ let hasPassed = oldChallengesMap . get ( name ) ?. passed || newChallenge . passed ;
109
+ mergedChallenges . push ( { ...newChallenge , passed : hasPassed } ) ;
111
110
}
112
111
113
112
// Set the merged challenges for the current level in the mergedState
0 commit comments