Skip to content

Commit

Permalink
feat(storage): compress json project
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Sep 29, 2022
1 parent 68af1b6 commit 4b17e0a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/better-write-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"eslint-plugin-vue": "9.5.1",
"fast-glob": "3.2.12",
"konva": "8.3.10",
"lz-string": "1.4.4",
"node-stdlib-browser": "1.2.0",
"pathe": "0.3.8",
"prettier": "2.6.2",
Expand Down
5 changes: 3 additions & 2 deletions packages/better-write-app/src/use/storage/local.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import destr from 'destr'
import LZString from 'lz-string'
import { Maybe, ProjectObject } from 'better-write-types'
import { useToast } from 'vue-toastification'
import { useEnv } from '../env'
Expand All @@ -17,13 +18,13 @@ export const useLocalStorage = () => {
const { t } = i18n.global

const set = (obj: any, name: string) => {
localStorage.setItem(name, JSON.stringify(obj))
localStorage.setItem(name, LZString.compress(JSON.stringify(obj)))
}

const get = (name: string): Maybe<ProjectObject> => {
const item = localStorage.getItem(name)

return item ? destr(item) : undefined
return item ? destr(LZString.decompress(item)) : undefined
}

const setProject = (obj: ProjectObject) => {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8092,6 +8092,11 @@ lru_map@^0.3.3:
resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd"
integrity sha1-tcg1G5Rky9dQM1p5ZQoOwOVhGN0=

lz-string@1.4.4:
version "1.4.4"
resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.4.4.tgz#c0d8eaf36059f705796e1e344811cf4c498d3a26"
integrity sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ==

magic-string@0.25.1:
version "0.25.1"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.1.tgz#b1c248b399cd7485da0fe7385c2fc7011843266e"
Expand Down

0 comments on commit 4b17e0a

Please sign in to comment.