Skip to content

Commit

Permalink
fix(vuex): cache edited state, closes #956
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Apr 5, 2019
1 parent 6e503bf commit 92aa8ca
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/backend/vuex.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class VuexBackend {
index,
snapshot: this.getStoreSnapshot()
})
this.cacheStateSnapshot(index, true)
}

/**
Expand All @@ -205,7 +206,11 @@ class VuexBackend {

resetSnapshotCache () {
this.stateSnapshotCache = [
{ index: -1, state: this.baseStateSnapshot }
{
index: -1,
state: this.baseStateSnapshot,
permanent: true
}
]
}

Expand Down Expand Up @@ -489,17 +494,25 @@ class VuexBackend {
return result
}

cacheStateSnapshot (index) {
cacheStateSnapshot (index, permanent = false) {
this.removeCachedStateSnapshot(index)
this.stateSnapshotCache.push({
index,
state: clone(this.store.state)
state: clone(this.store.state),
permanent
})
// Delete old cached snapshots
if (this.stateSnapshotCache.length > SharedData.cacheVuexSnapshotsLimit) {
this.stateSnapshotCache.splice(1, 1)
if (this.stateSnapshotCache.filter(s => !s.permanent).length > SharedData.cacheVuexSnapshotsLimit) {
const i = this.stateSnapshotCache.findIndex(s => !s.permanent)
if (i !== -1) this.stateSnapshotCache.splice(i, 1)
}
}

removeCachedStateSnapshot (index) {
const i = this.stateSnapshotCache.findIndex(s => s.idex === index)
if (i !== -1) this.stateSnapshotCache.splice(i, 1)
}

/**
* Get the serialized state and getters from the store
*/
Expand Down

0 comments on commit 92aa8ca

Please sign in to comment.