@@ -16,7 +16,7 @@ class PassedState {
1616 const rawState = this . _prepareState ( initialState ) ;
1717
1818 // 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 ) ;
2020 this . _save ( state ) ;
2121 this . _state = state ;
2222 return
@@ -84,12 +84,16 @@ class PassedState {
8484 throw new Error ( 'one of the new state and the old state is required.' ) ;
8585 }
8686
87- if ( ! newState ) {
87+ if ( ! oldState && newState ) {
88+ return newState ;
89+ }
90+
91+ if ( ! newState && oldState ) {
8892 return oldState ;
8993 }
9094
9195 let mergedState = { } ;
92- const levels = [ 'basic' , 'intermediate' , 'advanced' , 'expert ' ] ;
96+ const levels = [ 'basic' , 'intermediate' , 'advanced' , 'extreme ' ] ;
9397
9498 for ( const level of levels ) {
9599 // Initialize an empty array for merged challenges
@@ -101,13 +105,8 @@ class PassedState {
101105
102106 // Add or update challenges from the newState
103107 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 } ) ;
111110 }
112111
113112 // Set the merged challenges for the current level in the mergedState
0 commit comments