Skip to content
Snippets Groups Projects
Commit 6e388c01 authored by lain's avatar lain
Browse files

Compress saved state with zlib.

parent de986b81
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@
"karma-mocha-reporter": "^2.2.1",
"node-sass": "^3.10.1",
"object-path": "^0.11.3",
"pako": "^1.0.4",
"sanitize-html": "^1.13.0",
"sass-loader": "^4.0.2",
"tributejs": "^2.1.0",
......
import merge from 'lodash.merge'
import objectPath from 'object-path'
import { throttle } from 'lodash'
import { inflate, deflate } from 'pako'
const defaultReducer = (state, paths) => (
paths.length === 0 ? state : paths.reduce((substate, path) => {
......@@ -35,14 +36,19 @@ const defaultStorage = (() => {
})()
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 ({
key = 'vuex',
paths = [],
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
},
setState = throttle(defaultSetState, 5000),
......
......@@ -4041,6 +4041,10 @@ pac-resolver@~1.2.1:
regenerator "~0.8.13"
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:
version "0.2.9"
resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment