Skip to content

Commit 6b4cbde

Browse files
committed
BinarCode#24 support class based notification handling
Add Vue as peer dependency
1 parent 2fb163b commit 6b4cbde

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@
2121
"test": "echo 'no tests!' && npm run lint",
2222
"prepublish": "npm run build",
2323
"lint": "xo",
24-
"build": "bili --format cjs --format umd --compress --banner --js babel && node-sass themes/ -o themes/",
24+
"build": "bili --external=vue --format cjs --format umd --compress --banner --js babel && node-sass themes/ -o themes/",
2525
"build:example": "poi build",
2626
"dev": "poi --port 5000",
2727
"deploy": "npm run build:example && gh-pages -d example/dist"
2828
},
2929
"author": "cristij <[email protected]>",
3030
"license": "MIT",
3131
"dependencies": {},
32+
"peerDependencies": {
33+
"vue": "^2.2.0"
34+
},
3235
"devDependencies": {
3336
"babel-preset-vue-app": "^2.0.0",
3437
"bili": "^0.16.0-rc.2",

src/index.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Notifications from './Notifications.js'
2+
import Vue from 'vue';
23

34
const NotificationStore = {
45
state: [], // here the notifications will be added
@@ -59,16 +60,28 @@ function initStore(Vue){
5960
});
6061
}
6162

62-
const NotificationsPlugin = {
63-
install (Vue, options) {
64-
let store = initStore(Vue);
65-
Vue.prototype.$notify = store.notify;
66-
Vue.prototype.$notifications = store.notificationStore;
67-
Vue.component('Notifications', Notifications)
68-
if(options){
69-
NotificationStore.setOptions(options)
70-
}
71-
}
63+
export const Notification = new class {
64+
constructor(){
65+
this.store = initStore(Vue);
66+
}
67+
68+
notify(...params){
69+
this.store.notify(params)
70+
}
71+
72+
notifications(){
73+
return this.store.notificationStore;
74+
}
7275
};
7376

74-
export default NotificationsPlugin
77+
export default {
78+
install (Vue, options) {
79+
let store = initStore(Vue);
80+
Vue.prototype.$notify = store.notify;
81+
Vue.prototype.$notifications = store.notificationStore;
82+
Vue.component('Notifications', Notifications);
83+
if(options){
84+
NotificationStore.setOptions(options)
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)