refactor: always use process.client instead of process.browser (#3910)

This commit is contained in:
Clark Du 2018-09-19 10:00:23 +01:00 committed by Pooya Parsa
parent 1c34651baa
commit 411bb1904e
6 changed files with 8 additions and 8 deletions

View File

@ -13,7 +13,7 @@
</template> </template>
<script> <script>
const Cookie = process.browser ? require('js-cookie') : undefined const Cookie = process.client ? require('js-cookie') : undefined
export default { export default {
methods: { methods: {

View File

@ -15,7 +15,7 @@
</template> </template>
<script> <script>
const Cookie = process.browser ? require('js-cookie') : undefined const Cookie = process.client ? require('js-cookie') : undefined
export default { export default {
middleware: 'notAuthenticated', middleware: 'notAuthenticated',

View File

@ -7,7 +7,7 @@
<script> <script>
let miniToastr let miniToastr
if (process.browser) { if (process.client) {
miniToastr = require('mini-toastr') miniToastr = require('mini-toastr')
} }

View File

@ -117,7 +117,7 @@ export default {
worker.terminate() worker.terminate()
}, },
createWorkers () { createWorkers () {
if (process.browser) { if (process.client) {
for(let i = 0, len = navigator.hardwareConcurrency || 1; i < len; i++) { for(let i = 0, len = navigator.hardwareConcurrency || 1; i < len; i++) {
this.workers.push(this.$worker.createWorker()) this.workers.push(this.$worker.createWorker())
} }

View File

@ -52,7 +52,7 @@ async function createApp (ssrContext) {
<% if (mode === 'universal') { %> <% if (mode === 'universal') { %>
// Fix SSR caveat https://github.com/nuxt/nuxt.js/issues/3757#issuecomment-414689141 // Fix SSR caveat https://github.com/nuxt/nuxt.js/issues/3757#issuecomment-414689141
const registerModule = store.registerModule const registerModule = store.registerModule
store.registerModule = (path, rawModule, options) => registerModule.call(store, path, rawModule, Object.assign({ preserveState: process.browser }, options)) store.registerModule = (path, rawModule, options) => registerModule.call(store, path, rawModule, Object.assign({ preserveState: process.client }, options))
<% } %> <% } %>
<% } %> <% } %>
@ -151,7 +151,7 @@ async function createApp (ssrContext) {
} }
<% if (store) { %> <% if (store) { %>
if (process.browser) { if (process.client) {
// Replace store state before plugins execution // Replace store state before plugins execution
if (window.__NUXT__ && window.__NUXT__.state) { if (window.__NUXT__ && window.__NUXT__.state) {
store.replaceState(window.__NUXT__.state) store.replaceState(window.__NUXT__.state)
@ -163,7 +163,7 @@ async function createApp (ssrContext) {
<% plugins.filter(p => p.ssr).forEach((plugin) => { %> <% plugins.filter(p => p.ssr).forEach((plugin) => { %>
if (typeof <%= plugin.name %> === 'function') await <%= plugin.name %>(app.context, inject)<% }) %> if (typeof <%= plugin.name %> === 'function') await <%= plugin.name %>(app.context, inject)<% }) %>
<% if (plugins.filter(p => !p.ssr).length) { %> <% if (plugins.filter(p => !p.ssr).length) { %>
if (process.browser) { <% plugins.filter((p) => !p.ssr).forEach((plugin) => { %> if (process.client) { <% plugins.filter((p) => !p.ssr).forEach((plugin) => { %>
if (typeof <%= plugin.name %> === 'function') await <%= plugin.name %>(app.context, inject)<% }) %> if (typeof <%= plugin.name %> === 'function') await <%= plugin.name %>(app.context, inject)<% }) %>
}<% } %> }<% } %>

View File

@ -4,7 +4,7 @@ const noopData = () => ({})
// window.onNuxtReady(() => console.log('Ready')) hook // window.onNuxtReady(() => console.log('Ready')) hook
// Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading) // Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading)
if (process.browser) { if (process.client) {
window._nuxtReadyCbs = [] window._nuxtReadyCbs = []
window.onNuxtReady = (cb) => { window.onNuxtReady = (cb) => {
window._nuxtReadyCbs.push(cb) window._nuxtReadyCbs.push(cb)