Skip to content

Commit

Permalink
feat: SSR updates on Quasar plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Jun 14, 2018
1 parent fca914a commit 340fcb7
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 49 deletions.
4 changes: 1 addition & 3 deletions src/ie-compat/ie.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable no-extend-native */

(function (window) {
if (window === void 0) { return }

typeof window !== 'undefined' && (function (window) {
try {
new MouseEvent('test') // eslint-disable-line no-new, no-use-before-define
return
Expand Down
2 changes: 1 addition & 1 deletion src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function (_Vue, opts = {}) {
if (opts.plugins) {
Object.keys(opts.plugins).forEach(key => {
const p = opts.plugins[key]
if (typeof p.install === 'function') {
if (typeof p.install === 'function' && p !== Platform) {
p.install({ $q, Vue: _Vue, cfg })
}
})
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/action-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import modalFn from '../utils/modal-fn'

export default {
install ({ $q, Vue }) {
if (this.__installed) { return }
this.__installed = true

this.create = $q.actionSheet = modalFn(QActionSheet, Vue)
}
}
9 changes: 3 additions & 6 deletions src/plugins/addressbar-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ function setColor (hexColor) {

export default {
install ({ $q, Vue }) {
if (this.__installed) { return }
this.__installed = true

this.set = Platform.is.mobile && !isSSR && (
this.set = !isSSR && Platform.is.mobile && (
Platform.is.cordova ||
Platform.is.winphone || Platform.is.safari ||
Platform.is.webkit || Platform.is.vivaldi
Expand All @@ -59,8 +56,8 @@ export default {
ready(() => {
const val = hexColor || getBrand('primary')

if (Platform.is.cordova) {
window.StatusBar && window.StatusBar.backgroundColorByHexString(val)
if (Platform.is.cordova && window.StatusBar) {
window.StatusBar.backgroundColorByHexString(val)
}
else {
setColor(val)
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/app-fullscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ export default {
},

install ({ $q, Vue }) {
if (this.__installed) { return }
this.__installed = true

$q.fullscreen = this

if (isSSR) { return }
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/app-visibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ export default {
appVisible: false,

install ({ $q, Vue }) {
if (this.__installed) { return }
this.__installed = true

if (isSSR) {
this.appVisible = $q.appVisible = true
return
Expand Down
5 changes: 1 addition & 4 deletions src/plugins/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ export default {
remove,
all: () => get(),

install ({ $q, cfg }) {
if (this.__installed) { return }
this.__installed = true

install ({ $q }) {
if (!isSSR) {
$q.cookies = this
}
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import modalFn from '../utils/modal-fn'

export default {
install ({ $q, Vue }) {
if (this.__installed) { return }
this.__installed = true

this.create = $q.dialog = modalFn(QDialog, Vue)
}
}
3 changes: 0 additions & 3 deletions src/plugins/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ export default {

__Vue: null,
install ({ $q, Vue, cfg: { loading } }) {
if (this.__installed) { return }
this.__installed = true

loading && this.setDefaults(loading)

$q.loading = this
Expand Down
11 changes: 6 additions & 5 deletions src/plugins/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,14 @@ export default {
},

install (args) {
if (this.__installed) { return }
this.__installed = true

if (!isSSR) {
init.call(this, args)
if (isSSR) {
args.$q.notify = () => {}
args.$q.notify.setDefaults = () => {}
return
}

init.call(this, args)

args.cfg.notify && this.setDefaults(args.cfg.notify)

args.$q.notify = this.create.bind(this)
Expand Down
9 changes: 3 additions & 6 deletions src/plugins/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ export function ssrGetPlatform (ssr) {

const Platform = {
install ({ $q, cfg }) {
if (this.__installed) { return }
this.__installed = true

if (isSSR) {
Platform.is = Platform.has = Platform.within = {}
return
Expand All @@ -205,12 +202,12 @@ const Platform = {
webStorage = false
}

Platform.is = getPlatform()
Platform.has = {
this.is = getPlatform()
this.has = {
touch: (() => !!('ontouchstart' in document.documentElement) || window.navigator.msMaxTouchPoints > 0)(),
webStorage
}
Platform.within = {
this.within = {
iframe: window.self !== window.top
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export default {
lg: true,

install ({ $q, Vue }) {
if (this.__installed) { return }
this.__installed = true

if (isSSR) {
$q.screen = this
this.setSizes = this.setDebounce = () => {}
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/web-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ function getStorage (type) {

export const LocalStorage = {
install ({ $q }) {
if (this.__installed) { return }
this.__installed = true

if (!isSSR && $q.platform.has.webStorage) {
const storage = getStorage('local')
$q.localStorage = storage
Expand All @@ -141,9 +138,6 @@ export const LocalStorage = {

export const SessionStorage = {
install ({ $q }) {
if (this.__installed) { return }
this.__installed = true

if (!isSSR && $q.platform.has.webStorage) {
const storage = getStorage('session')
$q.sessionStorage = storage
Expand Down

0 comments on commit 340fcb7

Please sign in to comment.