Skip to content

Commit

Permalink
feat($core): support async enhanceApp (close vuejs#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Dec 9, 2019
1 parent c2bd6de commit aa37a27
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
12 changes: 6 additions & 6 deletions packages/@vuepress/core/lib/client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Vue.prototype.$withBase = function (path) {
}
}

export function createApp (isServer) {
export async function createApp (isServer) {
const routerBase = typeof window !== 'undefined' && window.__VUEPRESS_ROUTER_BASE__
? window.__VUEPRESS_ROUTER_BASE__
: (siteData.routerBase || siteData.base)
Expand Down Expand Up @@ -90,11 +90,11 @@ export function createApp (isServer) {
const options = {}

try {
appEnhancers.forEach(enhancer => {
if (typeof enhancer === 'function') {
enhancer({ Vue, options, router, siteData, isServer })
}
})
await Promise.all(
appEnhancers
.filter(enhancer => typeof enhancer === 'function')
.map(enhancer => enhancer({ Vue, options, router, siteData, isServer }))
)
} catch (e) {
console.error(e)
}
Expand Down
8 changes: 4 additions & 4 deletions packages/@vuepress/core/lib/client/clientEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import { createApp } from './app'

const { app, router } = createApp(false /* isServer */)

window.__VUEPRESS__ = {
version: VUEPRESS_VERSION,
hash: LAST_COMMIT_HASH
}

router.onReady(() => {
app.$mount('#app')
createApp(false /* isServer */).then(({ app, router }) => {
router.onReady(() => {
app.$mount('#app')
})
})
17 changes: 9 additions & 8 deletions packages/@vuepress/core/lib/client/serverEntry.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { createApp } from './app'

export default context => new Promise((resolve, reject) => {
const { app, router } = createApp(true /* isServer */)
const { url } = context
const { fullPath } = router.resolve(url).route
createApp(true /* isServer */).then(({ app, router }) => {
const { url } = context
const { fullPath } = router.resolve(url).route

if (fullPath !== url) {
return reject({ url: fullPath })
}
if (fullPath !== url) {
return reject({ url: fullPath })
}

router.push(url)
router.onReady(() => resolve(app))
router.push(url)
router.onReady(() => resolve(app))
})
})

0 comments on commit aa37a27

Please sign in to comment.