Added "installed" flag and removed Object.defineProperty

This commit is contained in:
euvl
2017-06-21 20:19:04 +01:00
parent b6c596b514
commit 375ae806ae
4 changed files with 22 additions and 30 deletions

View File

@@ -1,31 +1,30 @@
import Modal from './Modal.vue'
const Plugin = {
install(Vue, options = {}) {
if (!this.hasOwnProperty("event")) {
this.event = new Vue()
install (Vue, options = {}) {
if (this.installed) {
return
}
this.installed = true
this.event = new Vue()
const $modal = {
show(name, params) {
show (name, params) {
Plugin.event.$emit('toggle', name, true, params)
},
hide(name, params) {
hide (name, params) {
Plugin.event.$emit('toggle', name, false, params)
},
toggle(name, params) {
toggle (name, params) {
Plugin.event.$emit('toggle', name, undefined, params)
}
}
Object.defineProperty(Vue.prototype, '$modal', {
get: () => $modal
})
Vue.prototype.$modal = $modal
Vue.component('modal', Modal)
return null
}
}