Skip to content

Commit

Permalink
BinarCode#24 support class based notification handling
Browse files Browse the repository at this point in the history
Add Vue as peer dependency
  • Loading branch information
cristijora committed Apr 30, 2018
1 parent 2fb163b commit 6b4cbde
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
"test": "echo 'no tests!' && npm run lint",
"prepublish": "npm run build",
"lint": "xo",
"build": "bili --format cjs --format umd --compress --banner --js babel && node-sass themes/ -o themes/",
"build": "bili --external=vue --format cjs --format umd --compress --banner --js babel && node-sass themes/ -o themes/",
"build:example": "poi build",
"dev": "poi --port 5000",
"deploy": "npm run build:example && gh-pages -d example/dist"
},
"author": "cristij <[email protected]>",
"license": "MIT",
"dependencies": {},
"peerDependencies": {
"vue": "^2.2.0"
},
"devDependencies": {
"babel-preset-vue-app": "^2.0.0",
"bili": "^0.16.0-rc.2",
Expand Down
35 changes: 24 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Notifications from './Notifications.js'
import Vue from 'vue';

const NotificationStore = {
state: [], // here the notifications will be added
Expand Down Expand Up @@ -59,16 +60,28 @@ function initStore(Vue){
});
}

const NotificationsPlugin = {
install (Vue, options) {
let store = initStore(Vue);
Vue.prototype.$notify = store.notify;
Vue.prototype.$notifications = store.notificationStore;
Vue.component('Notifications', Notifications)
if(options){
NotificationStore.setOptions(options)
}
}
export const Notification = new class {
constructor(){
this.store = initStore(Vue);
}

notify(...params){
this.store.notify(params)
}

notifications(){
return this.store.notificationStore;
}
};

export default NotificationsPlugin
export default {
install (Vue, options) {
let store = initStore(Vue);
Vue.prototype.$notify = store.notify;
Vue.prototype.$notifications = store.notificationStore;
Vue.component('Notifications', Notifications);
if(options){
NotificationStore.setOptions(options)
}
}
}

0 comments on commit 6b4cbde

Please sign in to comment.