Skip to content

Commit b6e775c

Browse files
committed
refactor: add types for client VuePress plugin
1 parent b57d880 commit b6e775c

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

packages/@vuepress/core/lib/app/app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { siteData } from '@internal/siteData'
77
import appEnhancers from '@internal/app-enhancers'
88
import globalUIComponents from '@internal/global-ui'
99
import ClientComputedMixin from '@transform/ClientComputedMixin'
10-
import Store from './plugins/Store'
10+
import VuePress from './plugins/VuePress'
1111

1212
// built-in components
1313
import LoadableContent from './components/Content.vue'
@@ -32,7 +32,7 @@ if (module.hot) {
3232
Vue.config.productionTip = false
3333

3434
Vue.use(Router)
35-
Vue.use(Store, '$vuepress')
35+
Vue.use(VuePress)
3636
// mixin for exposing $site and $page
3737
Vue.mixin(dataMixin(ClientComputedMixin, siteData))
3838
// component for rendering markdown content and setting title etc.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Vue from 'Vue'
2+
3+
export declare class Store {
4+
store: Vue;
5+
6+
$get(key: string): any;
7+
8+
$set(key: string, value: any): void;
9+
10+
$emit: typeof Vue.prototype.$emit;
11+
12+
$on: typeof Vue.prototype.$on;
13+
}
14+
15+

packages/@vuepress/core/lib/app/plugins/Store.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Vue from 'vue'
22

3-
class Store {
3+
export default class Store {
44
constructor () {
55
this.store = new Vue({
66
data: {
@@ -25,11 +25,3 @@ class Store {
2525
this.store.$on(...args)
2626
}
2727
}
28-
29-
export default {
30-
install (Vue, options = '$store') {
31-
const store = new Store()
32-
Vue[options] = store
33-
Vue.prototype[options] = store
34-
}
35-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Store } from './Store';
2+
3+
declare class VuePress extends Store {
4+
5+
}
6+
7+
declare module "vue/types/vue" {
8+
interface Vue {
9+
$vuepress: Store;
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Store from './Store'
2+
3+
class VuePress extends Store {
4+
5+
}
6+
7+
export default {
8+
install (Vue) {
9+
const store = new VuePress()
10+
Vue.$vuepress = store
11+
Vue.prototype.$vuepress = store
12+
}
13+
}

0 commit comments

Comments
 (0)