Skip to content

Commit

Permalink
Close item by id (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolawan authored and euvl committed Oct 20, 2019
1 parent 0fcb1b2 commit 71b4daf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const Component = {
},
mounted () {
events.$on('add', this.addItem);
events.$on('close', this.closeItem);
},
computed: {
actualWidth () {
Expand Down Expand Up @@ -227,14 +228,15 @@ const Component = {
? event.speed
: this.speed
const ignoreDuplicates = typeof event.ignoreDuplicates === 'boolean'
? event.ignoreDuplicates
: this.ignoreDuplicates
let { title, text, type, data } = event
let { title, text, type, data, id, ignoreDuplicates } = event
const ignoreDuplicates = typeof ignoreDuplicates === 'boolean'
? ignoreDuplicates
: this.ignoreDuplicates
const item = {
id: Id(),
id: id || Id(),
title,
text,
type,
Expand Down Expand Up @@ -280,6 +282,10 @@ const Component = {
}
},
closeItem (id) {
this.destroyById(id)
},
notifyClass (item) {
return [
'vue-notification-template',
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const Notify = {
}
}

notify.close = function (id) {
events.$emit('close', id)
}

const name = args.name || 'notify'

Vue.prototype['$' + name] = notify
Expand Down

0 comments on commit 71b4daf

Please sign in to comment.