@@ -179,6 +179,7 @@ class VuexBackend {
179
179
index,
180
180
snapshot : this . getStoreSnapshot ( )
181
181
} )
182
+ this . cacheStateSnapshot ( index , true )
182
183
}
183
184
184
185
/**
@@ -205,7 +206,11 @@ class VuexBackend {
205
206
206
207
resetSnapshotCache ( ) {
207
208
this . stateSnapshotCache = [
208
- { index : - 1 , state : this . baseStateSnapshot }
209
+ {
210
+ index : - 1 ,
211
+ state : this . baseStateSnapshot ,
212
+ permanent : true
213
+ }
209
214
]
210
215
}
211
216
@@ -489,17 +494,25 @@ class VuexBackend {
489
494
return result
490
495
}
491
496
492
- cacheStateSnapshot ( index ) {
497
+ cacheStateSnapshot ( index , permanent = false ) {
498
+ this . removeCachedStateSnapshot ( index )
493
499
this . stateSnapshotCache . push ( {
494
500
index,
495
- state : clone ( this . store . state )
501
+ state : clone ( this . store . state ) ,
502
+ permanent
496
503
} )
497
504
// Delete old cached snapshots
498
- if ( this . stateSnapshotCache . length > SharedData . cacheVuexSnapshotsLimit ) {
499
- this . stateSnapshotCache . splice ( 1 , 1 )
505
+ if ( this . stateSnapshotCache . filter ( s => ! s . permanent ) . length > SharedData . cacheVuexSnapshotsLimit ) {
506
+ const i = this . stateSnapshotCache . findIndex ( s => ! s . permanent )
507
+ if ( i !== - 1 ) this . stateSnapshotCache . splice ( i , 1 )
500
508
}
501
509
}
502
510
511
+ removeCachedStateSnapshot ( index ) {
512
+ const i = this . stateSnapshotCache . findIndex ( s => s . idex === index )
513
+ if ( i !== - 1 ) this . stateSnapshotCache . splice ( i , 1 )
514
+ }
515
+
503
516
/**
504
517
* Get the serialized state and getters from the store
505
518
*/
0 commit comments