Skip to content

Commit 65a2741

Browse files
committed
refactor: integrate isLayoutExists and isPageExists
1 parent 4641f35 commit 65a2741

File tree

7 files changed

+17
-35
lines changed

7 files changed

+17
-35
lines changed

packages/@vuepress/core/lib/client/components/Content.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default {
88
},
99
render (h) {
1010
const pageKey = this.pageKey || this.$parent.$page.key
11-
if (this.$vuepress.isPageExists(pageKey)) {
11+
if (this.$hasComponent(pageKey)) {
1212
return h(pageKey)
1313
}
1414
return h('')

packages/@vuepress/core/lib/client/components/GlobalLayout.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
computed: {
88
layout () {
99
if (this.$page.path) {
10-
if (this.$vuepress.isLayoutExists(this.$page.frontmatter.layout)) {
10+
if (this.$hasComponent(this.$page.frontmatter.layout)) {
1111
return this.$page.frontmatter.layout
1212
}
1313
return 'Layout'
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import Vue from 'Vue'
22

33
export declare class Store {
4-
store: Vue;
4+
store: Vue
55

6-
$get(key: string): any;
6+
$get(key: string): any
77

8-
$set(key: string, value: any): void;
8+
$set(key: string, value: any): void
99

10-
$emit: typeof Vue.prototype.$emit;
10+
$emit: typeof Vue.prototype.$emit
1111

12-
$on: typeof Vue.prototype.$on;
12+
$on: typeof Vue.prototype.$on
1313
}
14-
15-
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import { Store } from './Store';
2-
import { AsyncComponent } from 'vue'
1+
import { Store } from './Store'
32

4-
declare class VuePress extends Store {
5-
isPageExists (pageKey: string): boolean;
6-
7-
isLayoutExists (pageKey: string): boolean;
8-
}
9-
10-
declare module "vue/types/vue" {
3+
declare module 'vue/types/vue' {
114
export interface Vue {
12-
$vuepress: VuePress;
5+
$vuepress: Store
6+
$hasComponent (key: string): boolean
137
}
148
}
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Vue from 'vue'
21
import Store from './Store'
32

43
// TODO: reuse this function in shared-utils
@@ -14,20 +13,11 @@ function cached (fn) {
1413

1514
const pascalize = cached((str = '') => str.replace(/(^|-)\w/g, s => s.slice(-1).toUpperCase()))
1615

17-
class VuePress extends Store {
18-
isPageExists (pageKey) {
19-
return Boolean(Vue.component(pascalize(pageKey)))
20-
}
21-
22-
isLayoutExists (layout) {
23-
return Boolean(Vue.component(pascalize(layout)))
24-
}
25-
}
26-
2716
export default {
2817
install (Vue) {
29-
const ins = new VuePress()
30-
Vue.$vuepress = ins
31-
Vue.prototype.$vuepress = ins
18+
const vuepress = new Store()
19+
Vue.$vuepress = vuepress
20+
Vue.prototype.$vuepress = vuepress
21+
Vue.prototype.$hasComponent = key => Boolean(Vue.component(pascalize(key)))
3222
}
3323
}

packages/docs/docs/theme/option-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default {
111111
computed: {
112112
layout () {
113113
if (this.$page.path) {
114-
if (this.$vuepress.isLayoutExists(this.$frontmatter.layout)) {
114+
if (this.$hasComponent(this.$frontmatter.layout)) {
115115
return this.$frontmatter.layout
116116
}
117117
return 'Layout'

packages/docs/docs/zh/theme/option-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default {
111111
computed: {
112112
layout () {
113113
if (this.$page.path) {
114-
if (this.$vuepress.isLayoutExists(this.$frontmatter.layout)) {
114+
if (this.$hasComponent(this.$frontmatter.layout)) {
115115
return this.$frontmatter.layout
116116
}
117117
return 'Layout'

0 commit comments

Comments
 (0)