add lz compression to localstorage state

This commit is contained in:
2017-02-20 13:41:17 -07:00
parent df20bab9fb
commit 1335180377
3 changed files with 16 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate';
import lz from 'lz-string';
import authentication from './authentication';
@@ -13,7 +14,16 @@ const store = new Vuex.Store({
authentication,
},
plugins: [
createPersistedState(),
createPersistedState({
getState(key) {
const state = lz.decompress(window.localStorage.getItem(key));
return JSON.parse(state);
},
setState(key, state) {
const stateJSON = JSON.stringify(state);
return window.localStorage.setItem(key, lz.compress(stateJSON));
},
}),
],
});