Minor consistency tweaks (#3726)

This commit is contained in:
Jonas Galvez 2018-08-15 10:23:03 -03:00 committed by Sébastien Chopin
parent f0045322c1
commit e6e8adb671
3 changed files with 25 additions and 18 deletions

View File

@ -1,6 +1,6 @@
import Vue from 'vue' import Vue from 'vue'
<% if (loading) { %>import NuxtLoading from '<%= (typeof loading === "string" ? loading : "./components/nuxt-loading.vue") %>'<% } %> <% if (loading) { %>import NuxtLoading from '<%= (typeof loading === "string" ? loading : "./components/nuxt-loading.vue") %>'<% } %>
<% css.forEach(function (c) { %> <% css.forEach((c) => { %>
import '<%= relativeToBuild(resolvePath(c.src || c)) %>' import '<%= relativeToBuild(resolvePath(c.src || c)) %>'
<% }) %> <% }) %>

View File

@ -35,7 +35,7 @@ Object.assign(Vue.config, <%= serialize(vue.config) %>)
<% if (debug || mode === 'spa') { %> <% if (debug || mode === 'spa') { %>
// Setup global Vue error handler // Setup global Vue error handler
const defaultErrorHandler = Vue.config.errorHandler const defaultErrorHandler = Vue.config.errorHandler
Vue.config.errorHandler = function (err, vm, info) { Vue.config.errorHandler = (err, vm, info) => {
const nuxtError = { const nuxtError = {
statusCode: err.statusCode || err.name || 'Whoops!', statusCode: err.statusCode || err.name || 'Whoops!',
message: err.message || err.toString() message: err.message || err.toString()
@ -489,7 +489,7 @@ function nuxtReady (_app) {
window._onNuxtLoaded(_app) window._onNuxtLoaded(_app)
} }
// Add router hooks // Add router hooks
router.afterEach(function (to, from) { router.afterEach((to, from) => {
// Wait for fixPrepatch + $data updates // Wait for fixPrepatch + $data updates
Vue.nextTick(() => _app.$nuxt.$emit('routeChanged', to, from)) Vue.nextTick(() => _app.$nuxt.$emit('routeChanged', to, from))
}) })

View File

@ -6,7 +6,7 @@ const noopData = () => ({})
// 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.browser) {
window._nuxtReadyCbs = [] window._nuxtReadyCbs = []
window.onNuxtReady = function (cb) { window.onNuxtReady = (cb) => {
window._nuxtReadyCbs.push(cb) window._nuxtReadyCbs.push(cb)
} }
} }
@ -58,8 +58,8 @@ export function sanitizeComponent(Component) {
} }
export function getMatchedComponents(route, matches = false) { export function getMatchedComponents(route, matches = false) {
return [].concat.apply([], route.matched.map(function (m, index) { return Array.prototype.concat.apply([], route.matched.map((m, index) => {
return Object.keys(m.components).map(function (key) { return Object.keys(m.components).map((key) => {
matches && matches.push(index) matches && matches.push(index)
return m.components[key] return m.components[key]
}) })
@ -67,8 +67,8 @@ export function getMatchedComponents(route, matches = false) {
} }
export function getMatchedComponentsInstances(route, matches = false) { export function getMatchedComponentsInstances(route, matches = false) {
return [].concat.apply([], route.matched.map(function (m, index) { return Array.prototype.concat.apply([], route.matched.map((m, index) => {
return Object.keys(m.instances).map(function (key) { return Object.keys(m.instances).map((key) => {
matches && matches.push(index) matches && matches.push(index)
return m.instances[key] return m.instances[key]
}) })
@ -76,8 +76,8 @@ export function getMatchedComponentsInstances(route, matches = false) {
} }
export function flatMapComponents(route, fn) { export function flatMapComponents(route, fn) {
return Array.prototype.concat.apply([], route.matched.map(function (m, index) { return Array.prototype.concat.apply([], route.matched.map((m, index) => {
return Object.keys(m.components).reduce(function (promises, key) { return Object.keys(m.components).reduce((promises, key) => {
if (m.components[key]) { if (m.components[key]) {
promises.push(fn(m.components[key], m.instances[key], m, key, index)) promises.push(fn(m.components[key], m.instances[key], m, key, index))
} else { } else {
@ -130,9 +130,12 @@ export async function setContext(app, context) {
// Only set once // Only set once
if (context.req) app.context.req = context.req if (context.req) app.context.req = context.req
if (context.res) app.context.res = context.res if (context.res) app.context.res = context.res
app.context.redirect = function (status, path, query) { app.context.redirect = (status, path, query) => {
if (!status) return if (!status) {
app.context._redirected = true // Used in middleware return
}
// Used in middleware
app.context._redirected = true
// if only 1 or 2 arguments: redirect('/') or redirect('/', { foo: 'bar' }) // if only 1 or 2 arguments: redirect('/') or redirect('/', { foo: 'bar' })
let pathType = typeof path let pathType = typeof path
if (typeof status !== 'number' && (pathType === 'undefined' || pathType === 'object')) { if (typeof status !== 'number' && (pathType === 'undefined' || pathType === 'object')) {
@ -176,10 +179,14 @@ export async function setContext(app, context) {
app.context._redirected = false app.context._redirected = false
app.context._errored = false app.context._errored = false
app.context.isHMR = !!context.isHMR app.context.isHMR = !!context.isHMR
if (context.route) app.context.route = await getRouteData(context.route) if (context.route) {
app.context.route = await getRouteData(context.route)
}
app.context.params = app.context.route.params || {} app.context.params = app.context.route.params || {}
app.context.query = app.context.route.query || {} app.context.query = app.context.route.query || {}
if (context.from) app.context.from = await getRouteData(context.from) if (context.from) {
app.context.from = await getRouteData(context.from)
}
} }
export function middlewareSeries(promises, appContext) { export function middlewareSeries(promises, appContext) {
@ -227,7 +234,7 @@ export function getLocation(base, mode) {
} }
export function urlJoin() { export function urlJoin() {
return [].slice.call(arguments).join('/').replace(/\/+/g, '/') return Array.prototype.slice.call(arguments).join('/').replace(/\/+/g, '/')
} }
// Imported from path-to-regexp // Imported from path-to-regexp
@ -352,7 +359,7 @@ function parse(str, options) {
* @return {string} * @return {string}
*/ */
function encodeURIComponentPretty(str) { function encodeURIComponentPretty(str) {
return encodeURI(str).replace(/[\/?#]/g, function (c) { return encodeURI(str).replace(/[\/?#]/g, (c) => {
return '%' + c.charCodeAt(0).toString(16).toUpperCase() return '%' + c.charCodeAt(0).toString(16).toUpperCase()
}) })
} }
@ -364,7 +371,7 @@ function encodeURIComponentPretty(str) {
* @return {string} * @return {string}
*/ */
function encodeAsterisk(str) { function encodeAsterisk(str) {
return encodeURI(str).replace(/[?#]/g, function (c) { return encodeURI(str).replace(/[?#]/g, (c) => {
return '%' + c.charCodeAt(0).toString(16).toUpperCase() return '%' + c.charCodeAt(0).toString(16).toUpperCase()
}) })
} }