Skip to content

refactor($core): inject root mixins to root component and make LayoutDistributor functional #1231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/@vuepress/core/lib/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { routes } from '@internal/routes'
import { siteData } from '@internal/siteData'
import appEnhancers from '@internal/app-enhancers'
import globalUIComponents from '@internal/global-ui'
import rootMixins from '@internal/root-mixins'
import ClientComputedMixin from '@transform/ClientComputedMixin'
import VuePress from './plugins/VuePress'
import { injectComponentOption } from '@app/util'

// built-in components
import Content from './components/Content.js'
Expand Down Expand Up @@ -97,6 +99,8 @@ export function createApp (isServer) {
console.error(e)
}

injectComponentOption(options, 'mixins', rootMixins)

const app = new Vue(
Object.assign(options, {
router,
Expand Down
19 changes: 19 additions & 0 deletions packages/@vuepress/core/lib/app/components/LayoutDistributor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Vue from 'vue'
import { getLayoutAsyncComponent } from '../util'

Vue.component('Layout', getLayoutAsyncComponent('Layout'))
Vue.component('NotFound', getLayoutAsyncComponent('NotFound'))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to move these two Vue.component() lines to app.js.

What do you think about that? @ulivz


export default {
functional: true,

render (h, { parent }) {
if (parent.$page.path) {
if (getLayoutAsyncComponent(parent.$page.frontmatter.layout)) {
return h(parent.$page.frontmatter.layout)
}
return h('Layout')
}
return h('NotFound')
}
}
25 changes: 0 additions & 25 deletions packages/@vuepress/core/lib/app/components/LayoutDistributor.vue

This file was deleted.

1 change: 1 addition & 0 deletions packages/@vuepress/core/lib/app/root-mixins/updateMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default {

methods: {
updateMeta () {
if (typeof document === 'undefined') return
document.title = this.$title
document.documentElement.lang = this.$lang
const userMeta = this.$page.frontmatter.meta || []
Expand Down
7 changes: 2 additions & 5 deletions packages/@vuepress/core/lib/internal-plugins/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ module.exports = (options, ctx) => ({
*/
function importCode () {
return `
import { injectComponentOption, ensureAsyncComponentsLoaded } from '@app/util'
import rootMixins from '@internal/root-mixins'
import { ensureAsyncComponentsLoaded } from '@app/util'
import layoutComponents from '@internal/layout-components'
import pageComponents from '@internal/page-components'
import LayoutDistributor from '@app/components/LayoutDistributor.vue'

injectComponentOption(LayoutDistributor, 'mixins', rootMixins)
import LayoutDistributor from '@app/components/LayoutDistributor'
`
}

Expand Down
8 changes: 4 additions & 4 deletions packages/@vuepress/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
"postcss-loader": "^2.1.5",
"toml": "^2.3.3",
"url-loader": "^1.0.1",
"vue": "^2.5.16",
"vue-loader": "^15.2.4",
"vue": "^2.5.22",
"vue-loader": "^15.6.0",
"vue-router": "^3.0.2",
"vue-server-renderer": "^2.5.16",
"vue-template-compiler": "^2.5.16",
"vue-server-renderer": "^2.5.22",
"vue-template-compiler": "^2.5.22",
"vuepress-html-webpack-plugin": "^3.2.0",
"webpack": "^4.8.1",
"webpack-chain": "^4.6.0",
Expand Down
1 change: 1 addition & 0 deletions packages/docs/docs/.vuepress/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const gotIt = {
export default {
methods: {
notice () {
if (!this.$toasted) return
setTimeout(() => {
this.$notification = this.$toasted.show(notification[this.$localePath], {
containerClass: 'compatibility-notification',
Expand Down
84 changes: 57 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1288,18 +1288,18 @@
babel-plugin-transform-vue-jsx "^4.0.1"
core-js "^2.5.7"

"@vue/component-compiler-utils@^2.0.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@vue/component-compiler-utils/-/component-compiler-utils-2.1.0.tgz#8331eadc8acdbc35aace5a61d2153e6f6434bfe2"
"@vue/component-compiler-utils@^2.4.0":
version "2.5.0"
resolved "https://registry.yarnpkg.com/@vue/component-compiler-utils/-/component-compiler-utils-2.5.0.tgz#411846d582d393f701f747517ddd29275ce64ca4"
dependencies:
consolidate "^0.15.1"
hash-sum "^1.0.2"
lru-cache "^4.1.2"
merge-source-map "^1.1.0"
postcss "^6.0.20"
postcss-selector-parser "^3.1.1"
prettier "^1.13.7"
source-map "^0.5.6"
postcss "^7.0.7"
postcss-selector-parser "^5.0.0"
prettier "1.13.7"
source-map "^0.7.3"
vue-template-es2015-compiler "^1.6.0"

"@vue/test-utils@^1.0.0-beta.16":
Expand Down Expand Up @@ -2494,6 +2494,14 @@ chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.3
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
dependencies:
ansi-styles "^3.2.1"
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

chardet@^0.4.0:
version "0.4.2"
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"
Expand Down Expand Up @@ -3251,6 +3259,10 @@ cssesc@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-0.1.0.tgz#c814903e45623371a0477b40109aaafbeeaddbb4"

cssesc@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-2.0.0.tgz#3b13bd1bb1cb36e1bcb5a4dcd27f54c5dcb35703"

cssnano@^3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/cssnano/-/cssnano-3.10.0.tgz#4f38f6cea2b9b17fa01490f23f1dc68ea65c1c38"
Expand Down Expand Up @@ -3612,7 +3624,7 @@ dot-prop@^3.0.0:
dependencies:
is-obj "^1.0.0"

dot-prop@^4.1.0, dot-prop@^4.1.1, dot-prop@^4.2.0:
dot-prop@^4.1.0, dot-prop@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.0.tgz#1f19e0c2e1aa0e32797c49799f2837ac6af69c57"
dependencies:
Expand Down Expand Up @@ -7963,11 +7975,11 @@ postcss-selector-parser@^2.0.0, postcss-selector-parser@^2.2.2:
indexes-of "^1.0.1"
uniq "^1.0.1"

postcss-selector-parser@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/postcss-selector-parser/-/postcss-selector-parser-3.1.1.tgz#4f875f4afb0c96573d5cf4d74011aee250a7e865"
postcss-selector-parser@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/postcss-selector-parser/-/postcss-selector-parser-5.0.0.tgz#249044356697b33b64f1a8f7c80922dddee7195c"
dependencies:
dot-prop "^4.1.1"
cssesc "^2.0.0"
indexes-of "^1.0.1"
uniq "^1.0.1"

Expand Down Expand Up @@ -8009,7 +8021,7 @@ postcss@^5.0.10, postcss@^5.0.11, postcss@^5.0.12, postcss@^5.0.13, postcss@^5.0
source-map "^0.5.6"
supports-color "^3.2.3"

postcss@^6.0.0, postcss@^6.0.17, postcss@^6.0.20:
postcss@^6.0.0, postcss@^6.0.17:
version "6.0.23"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.23.tgz#61c82cc328ac60e677645f979054eb98bc0e3324"
dependencies:
Expand All @@ -8025,6 +8037,14 @@ postcss@^6.0.1:
source-map "^0.6.1"
supports-color "^5.4.0"

postcss@^7.0.7:
version "7.0.14"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.14.tgz#4527ed6b1ca0d82c53ce5ec1a2041c2346bbd6e5"
dependencies:
chalk "^2.4.2"
source-map "^0.6.1"
supports-color "^6.1.0"

prelude-ls@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
Expand All @@ -8037,7 +8057,7 @@ preserve@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"

prettier@^1.13.7:
[email protected]:
version "1.13.7"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.7.tgz#850f3b8af784a49a6ea2d2eaa7ed1428a34b7281"

Expand Down Expand Up @@ -9001,6 +9021,10 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"

source-map@^0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"

spdx-correct@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.0.0.tgz#05a5b4d7153a195bc92c3c425b69f3b2a9524c82"
Expand Down Expand Up @@ -9273,6 +9297,12 @@ supports-color@^5.3.0, supports-color@^5.4.0:
dependencies:
has-flag "^3.0.0"

supports-color@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3"
dependencies:
has-flag "^3.0.0"

svgo@^0.7.0:
version "0.7.2"
resolved "https://registry.yarnpkg.com/svgo/-/svgo-0.7.2.tgz#9f5772413952135c6fefbf40afe6a4faa88b4bb5"
Expand Down Expand Up @@ -9909,11 +9939,11 @@ vue-jest@^2.6.0:
tsconfig "^7.0.0"
vue-template-es2015-compiler "^1.6.0"

vue-loader@^15.2.4:
version "15.2.6"
resolved "https://registry.yarnpkg.com/vue-loader/-/vue-loader-15.2.6.tgz#4ad4e56a0ca1fd89ebc4220f9e3bd4723097b397"
vue-loader@^15.6.0:
version "15.6.0"
resolved "https://registry.yarnpkg.com/vue-loader/-/vue-loader-15.6.0.tgz#c78916dc4f994b1559056d4a1cb92fa0b00e42bf"
dependencies:
"@vue/component-compiler-utils" "^2.0.0"
"@vue/component-compiler-utils" "^2.4.0"
hash-sum "^1.0.2"
loader-utils "^1.1.0"
vue-hot-reload-api "^2.3.0"
Expand All @@ -9923,9 +9953,9 @@ vue-router@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.2.tgz#dedc67afe6c4e2bc25682c8b1c2a8c0d7c7e56be"

vue-server-renderer@^2.5.16:
version "2.5.16"
resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.16.tgz#279ef8e37e502a0de3a9ae30758cc04a472eaac0"
vue-server-renderer@^2.5.22:
version "2.5.22"
resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.22.tgz#f119efef289c865adc22fda0ae7595299bedbdcf"
dependencies:
chalk "^1.1.3"
hash-sum "^1.0.2"
Expand All @@ -9943,9 +9973,9 @@ vue-style-loader@^4.1.0:
hash-sum "^1.0.2"
loader-utils "^1.0.2"

vue-template-compiler@^2.5.16:
version "2.5.16"
resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.16.tgz#93b48570e56c720cdf3f051cc15287c26fbd04cb"
vue-template-compiler@^2.5.22:
version "2.5.22"
resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.22.tgz#c3d3c02c65f1908205c4fbd3b0ef579e51239955"
dependencies:
de-indent "^1.0.2"
he "^1.1.0"
Expand All @@ -9958,9 +9988,9 @@ vue-toasted@^1.1.25:
version "1.1.25"
resolved "https://registry.yarnpkg.com/vue-toasted/-/vue-toasted-1.1.25.tgz#27b1f40866d98f8bf817722869f3d97f7c0d4db1"

vue@^2.5.16:
version "2.5.16"
resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.16.tgz#07edb75e8412aaeed871ebafa99f4672584a0085"
vue@^2.5.22:
version "2.5.22"
resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.22.tgz#3bf88041af08b8539c37b268b70ca79245e9cc30"

vuepress-html-webpack-plugin@^3.2.0:
version "3.2.0"
Expand Down