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

@@ -18,6 +18,7 @@
"loopback": "^3.0.0", "loopback": "^3.0.0",
"loopback-boot": "^2.6.5", "loopback-boot": "^2.6.5",
"loopback-component-explorer": "^4.0.0", "loopback-component-explorer": "^4.0.0",
"lz-string": "^1.4.4",
"strong-error-handler": "^1.0.1", "strong-error-handler": "^1.0.1",
"vue": "^2.1.10", "vue": "^2.1.10",
"vue-router": "^2.2.0", "vue-router": "^2.2.0",

View File

@@ -1,6 +1,7 @@
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate'; import createPersistedState from 'vuex-persistedstate';
import lz from 'lz-string';
import authentication from './authentication'; import authentication from './authentication';
@@ -13,7 +14,16 @@ const store = new Vuex.Store({
authentication, authentication,
}, },
plugins: [ 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));
},
}),
], ],
}); });

View File

@@ -3616,6 +3616,10 @@ lru-cache@^4.0.1:
pseudomap "^1.0.1" pseudomap "^1.0.1"
yallist "^2.0.0" yallist "^2.0.0"
lz-string@^1.4.4:
version "1.4.4"
resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.4.4.tgz#c0d8eaf36059f705796e1e344811cf4c498d3a26"
macaddress@^0.2.8: macaddress@^0.2.8:
version "0.2.8" version "0.2.8"
resolved "https://registry.yarnpkg.com/macaddress/-/macaddress-0.2.8.tgz#5904dc537c39ec6dbefeae902327135fa8511f12" resolved "https://registry.yarnpkg.com/macaddress/-/macaddress-0.2.8.tgz#5904dc537c39ec6dbefeae902327135fa8511f12"