From 2b2061b03f7e23913cf127e1b7e48e0b99f2aedd Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 23 Feb 2017 19:11:22 +0100 Subject: [PATCH] Switch to lz-string. Pako was very slow in Chromium. --- package.json | 2 +- src/lib/persisted_state.js | 8 ++++---- yarn.lock | 14 ++++---------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 52733425..e7aa7241 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,9 @@ "babel-plugin-lodash": "^3.2.11", "diff": "^3.0.1", "karma-mocha-reporter": "^2.2.1", + "lz-string": "^1.4.4", "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", diff --git a/src/lib/persisted_state.js b/src/lib/persisted_state.js index 31ced37d..6a17ca99 100644 --- a/src/lib/persisted_state.js +++ b/src/lib/persisted_state.js @@ -1,7 +1,7 @@ import merge from 'lodash.merge' import objectPath from 'object-path' import { throttle } from 'lodash' -import { inflate, deflate } from 'pako' +import lzstring from 'lz-string' const defaultReducer = (state, paths) => ( paths.length === 0 ? state : paths.reduce((substate, path) => { @@ -36,16 +36,16 @@ const defaultStorage = (() => { })() const defaultSetState = (key, state, storage) => { - return storage.setItem(key, deflate(JSON.stringify(state), { to: 'string' })) + return storage.setItem(key, lzstring.compressToUTF16(JSON.stringify(state))) } export default function createPersistedState ({ - key = 'vuex', + key = 'vuex-lz', paths = [], getState = (key, storage) => { let value = storage.getItem(key) try { - value = inflate(value, { to: 'string' }) + value = lzstring.decompressFromUTF16(value) // inflate(value, { to: 'string' }) } catch (e) { console.log("Couldn't inflate value... Maybe upgrading") } diff --git a/yarn.lock b/yarn.lock index 4d5a5f61..92f734bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3549,6 +3549,10 @@ lru-cache@~2.6.5: version "2.6.5" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.6.5.tgz#e56d6354148ede8d7707b58d143220fd08df0fd5" +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: version "0.2.8" resolved "https://registry.yarnpkg.com/macaddress/-/macaddress-0.2.8.tgz#5904dc537c39ec6dbefeae902327135fa8511f12" @@ -4052,10 +4056,6 @@ 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" @@ -5629,12 +5629,6 @@ vue-router@^2.2.0: version "2.2.1" resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-2.2.1.tgz#b027f9fac2cf13462725e843d6dc631b6aa077f6" -vue-style-loader@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/vue-style-loader/-/vue-style-loader-1.0.0.tgz#abeb7bd0f46313083741244d3079d4f14449e049" - dependencies: - loader-utils "^0.2.7" - vue-style-loader@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/vue-style-loader/-/vue-style-loader-2.0.0.tgz#1a3bb55239ac541ee3af0301d66f16fc86786543"