forked from AkkomaGang/akkoma-fe
Compress saved state with zlib.
This commit is contained in:
parent
de986b81d5
commit
6e388c0126
3 changed files with 13 additions and 2 deletions
|
@ -19,6 +19,7 @@
|
||||||
"karma-mocha-reporter": "^2.2.1",
|
"karma-mocha-reporter": "^2.2.1",
|
||||||
"node-sass": "^3.10.1",
|
"node-sass": "^3.10.1",
|
||||||
"object-path": "^0.11.3",
|
"object-path": "^0.11.3",
|
||||||
|
"pako": "^1.0.4",
|
||||||
"sanitize-html": "^1.13.0",
|
"sanitize-html": "^1.13.0",
|
||||||
"sass-loader": "^4.0.2",
|
"sass-loader": "^4.0.2",
|
||||||
"tributejs": "^2.1.0",
|
"tributejs": "^2.1.0",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import merge from 'lodash.merge'
|
import merge from 'lodash.merge'
|
||||||
import objectPath from 'object-path'
|
import objectPath from 'object-path'
|
||||||
import { throttle } from 'lodash'
|
import { throttle } from 'lodash'
|
||||||
|
import { inflate, deflate } from 'pako'
|
||||||
|
|
||||||
const defaultReducer = (state, paths) => (
|
const defaultReducer = (state, paths) => (
|
||||||
paths.length === 0 ? state : paths.reduce((substate, path) => {
|
paths.length === 0 ? state : paths.reduce((substate, path) => {
|
||||||
|
@ -35,14 +36,19 @@ const defaultStorage = (() => {
|
||||||
})()
|
})()
|
||||||
|
|
||||||
const defaultSetState = (key, state, storage) => {
|
const defaultSetState = (key, state, storage) => {
|
||||||
return storage.setItem(key, JSON.stringify(state))
|
return storage.setItem(key, deflate(JSON.stringify(state), { to: 'string' }))
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function createPersistedState ({
|
export default function createPersistedState ({
|
||||||
key = 'vuex',
|
key = 'vuex',
|
||||||
paths = [],
|
paths = [],
|
||||||
getState = (key, storage) => {
|
getState = (key, storage) => {
|
||||||
const value = storage.getItem(key)
|
let value = storage.getItem(key)
|
||||||
|
try {
|
||||||
|
value = inflate(value, { to: 'string' })
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Couldn't inflate value... Maybe upgrading")
|
||||||
|
}
|
||||||
return value && value !== 'undefined' ? JSON.parse(value) : undefined
|
return value && value !== 'undefined' ? JSON.parse(value) : undefined
|
||||||
},
|
},
|
||||||
setState = throttle(defaultSetState, 5000),
|
setState = throttle(defaultSetState, 5000),
|
||||||
|
|
|
@ -4041,6 +4041,10 @@ pac-resolver@~1.2.1:
|
||||||
regenerator "~0.8.13"
|
regenerator "~0.8.13"
|
||||||
thunkify "~2.1.1"
|
thunkify "~2.1.1"
|
||||||
|
|
||||||
|
pako@^1.0.4:
|
||||||
|
version "1.0.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.4.tgz#412cc97c3b7ff06dc6c2557fd4f03d06f5e708d4"
|
||||||
|
|
||||||
pako@~0.2.0:
|
pako@~0.2.0:
|
||||||
version "0.2.9"
|
version "0.2.9"
|
||||||
resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"
|
resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"
|
||||||
|
|
Loading…
Reference in a new issue