Skip to content

Commit

Permalink
feat: Simplify WebStorage logic when on SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Sep 11, 2018
1 parent 02177d1 commit 44608e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 38 deletions.
26 changes: 7 additions & 19 deletions src/plugins/local-storage.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import { onSSR, hasWebStorage } from './platform.js'
import { isSSR, hasWebStorage } from './platform.js'
import { getEmptyStorage, getStorage } from '../utils/web-storage.js'

export default {
install ({ $q, queues }) {
const assignStorage = storage => {
$q.localStorage = storage
Object.assign(this, storage)
}
install ({ $q }) {
const storage = isSSR || !hasWebStorage
? getEmptyStorage()
: getStorage('local')

const clientInit = () => {
if (hasWebStorage()) {
assignStorage(getStorage('local'))
}
}

if (onSSR) {
assignStorage(getEmptyStorage())
queues.takeover.push(clientInit)
return
}

clientInit()
$q.localStorage = storage
Object.assign(this, storage)
}
}
26 changes: 7 additions & 19 deletions src/plugins/session-storage.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import { onSSR, hasWebStorage } from './platform.js'
import { isSSR, hasWebStorage } from './platform.js'
import { getEmptyStorage, getStorage } from '../utils/web-storage.js'

export default {
install ({ $q, queues }) {
const assignStorage = storage => {
$q.sessionStorage = storage
Object.assign(this, storage)
}
install ({ $q }) {
const storage = isSSR || !hasWebStorage
? getEmptyStorage()
: getStorage('session')

const clientInit = () => {
if (hasWebStorage()) {
assignStorage(getStorage('session'))
}
}

if (onSSR) {
assignStorage(getEmptyStorage())
queues.takeover.push(clientInit)
return
}

clientInit()
$q.localStorage = storage
Object.assign(this, storage)
}
}

0 comments on commit 44608e4

Please sign in to comment.