Skip to content

Commit 2fb163b

Browse files
committed
Simplify plugin initialization
SSR support
1 parent 4dc60c9 commit 2fb163b

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

src/index.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,33 @@ const NotificationStore = {
4242
clear() {
4343
this.state = []
4444
}
45+
};
46+
47+
function initStore(Vue){
48+
return new Vue({
49+
data(){
50+
return {
51+
notificationStore: NotificationStore
52+
}
53+
},
54+
methods: {
55+
notify(notification) {
56+
this.notificationStore.notify(notification);
57+
}
58+
}
59+
});
4560
}
4661

4762
const NotificationsPlugin = {
4863
install (Vue, options) {
49-
Vue.mixin({
50-
data(){
51-
return {
52-
notificationStore: NotificationStore
53-
}
54-
},
55-
methods: {
56-
notify(notification) {
57-
this.notificationStore.notify(notification);
58-
}
59-
}
60-
})
61-
Object.defineProperty(Vue.prototype, '$notify', {
62-
get () {
63-
return this.$root.notify
64-
}
65-
})
66-
Object.defineProperty(Vue.prototype, '$notifications', {
67-
get () {
68-
return this.$root.notificationStore
69-
}
70-
})
64+
let store = initStore(Vue);
65+
Vue.prototype.$notify = store.notify;
66+
Vue.prototype.$notifications = store.notificationStore;
7167
Vue.component('Notifications', Notifications)
7268
if(options){
7369
NotificationStore.setOptions(options)
7470
}
7571
}
76-
}
72+
};
7773

7874
export default NotificationsPlugin

0 commit comments

Comments
 (0)