mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
Optimise promisifyRouteParams()
This commit is contained in:
parent
2d6ac069fd
commit
0c385f522c
@ -37,10 +37,9 @@ exports.promisifyRouteParams = function (fn) {
|
|||||||
if (Array.isArray(fn)) {
|
if (Array.isArray(fn)) {
|
||||||
return Promise.resolve(fn)
|
return Promise.resolve(fn)
|
||||||
}
|
}
|
||||||
let promise
|
|
||||||
// If routeParams[route] is a function expecting a callback
|
// If routeParams[route] is a function expecting a callback
|
||||||
if (fn.length === 1) {
|
if (fn.length === 1) {
|
||||||
promise = new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fn(function (err, routeParams) {
|
fn(function (err, routeParams) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err)
|
reject(err)
|
||||||
@ -48,9 +47,8 @@ exports.promisifyRouteParams = function (fn) {
|
|||||||
resolve(routeParams)
|
resolve(routeParams)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
promise = fn()
|
|
||||||
}
|
}
|
||||||
|
let promise = fn()
|
||||||
if (!(promise instanceof Promise)) {
|
if (!(promise instanceof Promise)) {
|
||||||
promise = Promise.resolve(promise)
|
promise = Promise.resolve(promise)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user