mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +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)) {
|
||||
return Promise.resolve(fn)
|
||||
}
|
||||
let promise
|
||||
// If routeParams[route] is a function expecting a callback
|
||||
if (fn.length === 1) {
|
||||
promise = new Promise((resolve, reject) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fn(function (err, routeParams) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
@ -48,9 +47,8 @@ exports.promisifyRouteParams = function (fn) {
|
||||
resolve(routeParams)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
promise = fn()
|
||||
}
|
||||
let promise = fn()
|
||||
if (!(promise instanceof Promise)) {
|
||||
promise = Promise.resolve(promise)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user