Skip to content

Commit

Permalink
feat: Web Storage work for compliancy with latest specs
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Jul 5, 2018
1 parent 0ac2e63 commit af65187
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 48 deletions.
14 changes: 2 additions & 12 deletions build/build.transforms.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
// === work in progress ===
// To be used with babel-plugin-transform-imports
/*
[
"transform-imports", {
"quasar": {
"transform": "../../transforms.js"
}
}
]
*/
// Used with babel-plugin-transform-imports

const
glob = require('glob'),
Expand All @@ -34,7 +24,7 @@ function camelCase (name) {
}

function isExternalUtil (name) {
return !['escape-key', 'modal-fn', 'popup', 'sort', 'router-link', 'is', 'noop'].includes(name)
return !['escape-key', 'modal-fn', 'popup', 'sort', 'router-link', 'is', 'noop', 'web-storage'].includes(name)
}

function addComponents (map, theme) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quasar-framework",
"version": "0.17.0-beta.7",
"version": "0.17.0-beta.8",
"description": "Build responsive websites, PWAs, hybrid mobile apps and Electron apps, all simultaneously using same codebase",
"module": "src/index.esm.js",
"files": [
Expand Down
3 changes: 2 additions & 1 deletion src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import Loading from './plugins/loading.js'
import Notify from './plugins/notify.js'
import Platform from './plugins/platform.js'
import Screen from './plugins/screen.js'
import { LocalStorage, SessionStorage } from './plugins/web-storage.js'
import LocalStorage from './plugins/local-storage.js'
import SessionStorage from './plugins/session-storage.js'

export {
ActionSheet,
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/local-storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { onSSR, hasWebStorage } from './platform.js'
import { getEmptyStorage, getStorage } from '../utils/web-storage.js'

export default {
install ({ $q }) {
if (onSSR) {
$q.localStorage = getEmptyStorage()
return
}

if (hasWebStorage()) {
const storage = getStorage('local')
$q.localStorage = storage
Object.assign(this, storage)
}
}
}
17 changes: 17 additions & 0 deletions src/plugins/session-storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { onSSR, hasWebStorage } from './platform.js'
import { getEmptyStorage, getStorage } from '../utils/web-storage.js'

export default {
install ({ $q }) {
if (onSSR) {
$q.sessionStorage = getEmptyStorage()
return
}

if (hasWebStorage()) {
const storage = getStorage('session')
$q.sessionStorage = storage
Object.assign(this, storage)
}
}
}
36 changes: 2 additions & 34 deletions src/plugins/web-storage.js → src/utils/web-storage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { onSSR, hasWebStorage } from './platform.js'

function encode (value) {
if (Object.prototype.toString.call(value) === '[object Date]') {
return '__q_date|' + value.toUTCString()
Expand Down Expand Up @@ -67,7 +65,7 @@ function decode (value) {
}
}

function getEmptyStorage () {
export function getEmptyStorage () {
const fn = () => {}

return {
Expand All @@ -85,7 +83,7 @@ function getEmptyStorage () {
}
}

function getStorage (type) {
export function getStorage (type) {
const
webStorage = window[type + 'Storage'],
get = key => {
Expand Down Expand Up @@ -122,33 +120,3 @@ function getStorage (type) {
isEmpty: () => webStorage.length === 0
}
}

export const LocalStorage = {
install ({ $q }) {
if (onSSR) {
$q.localStorage = getEmptyStorage()
return
}

if (hasWebStorage()) {
const storage = getStorage('local')
$q.localStorage = storage
Object.assign(this, storage)
}
}
}

export const SessionStorage = {
install ({ $q }) {
if (onSSR) {
$q.sessionStorage = getEmptyStorage()
return
}

if (hasWebStorage()) {
const storage = getStorage('session')
$q.sessionStorage = storage
Object.assign(this, storage)
}
}
}

0 comments on commit af65187

Please sign in to comment.