Skip to content

Commit

Permalink
Handle notification removal after timeout better
Browse files Browse the repository at this point in the history
  • Loading branch information
cristijora committed Jul 13, 2017
1 parent 8885f05 commit 178ef19
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 104 deletions.
21 changes: 12 additions & 9 deletions dist/vue-notifyjs.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var Notification = {
},
methods: {
close: function close() {
this.$emit('close');
this.$emit('close', this.timestamp);
}
},
mounted: function mounted() {
Expand Down Expand Up @@ -168,8 +168,8 @@ var Notifications = {
},

methods: {
removeNotification: function removeNotification(index) {
this.$notifications.removeNotification(index);
removeNotification: function removeNotification(timestamp) {
this.$notifications.removeNotification(timestamp);
}
},
created: function created() {
Expand All @@ -194,10 +194,8 @@ var Notifications = {
component: notification.component,
timestamp: notification.timestamp
},
key: notification, on: {
'close': function close() {
return _this.removeNotification(index);
}
key: notification.timestamp.getTime(), on: {
'close': _this.removeNotification
}
},
[]
Expand Down Expand Up @@ -228,8 +226,13 @@ var NotificationStore = {
settings: {
overlap: false
},
removeNotification: function removeNotification(index) {
this.state.splice(index, 1);
removeNotification: function removeNotification(timestamp) {
var indexToDelete = this.state.findIndex(function (n) {
return n.timestamp === timestamp;
});
if (indexToDelete !== -1) {
this.state.splice(indexToDelete, 1);
}
},
addNotification: function addNotification(notification) {
notification.timestamp = new Date();
Expand Down
21 changes: 12 additions & 9 deletions dist/vue-notifyjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var Notification = {
},
methods: {
close: function close() {
this.$emit('close');
this.$emit('close', this.timestamp);
}
},
mounted: function mounted() {
Expand Down Expand Up @@ -172,8 +172,8 @@ var Notifications = {
},

methods: {
removeNotification: function removeNotification(index) {
this.$notifications.removeNotification(index);
removeNotification: function removeNotification(timestamp) {
this.$notifications.removeNotification(timestamp);
}
},
created: function created() {
Expand All @@ -198,10 +198,8 @@ var Notifications = {
component: notification.component,
timestamp: notification.timestamp
},
key: notification, on: {
'close': function close() {
return _this.removeNotification(index);
}
key: notification.timestamp.getTime(), on: {
'close': _this.removeNotification
}
},
[]
Expand Down Expand Up @@ -232,8 +230,13 @@ var NotificationStore = {
settings: {
overlap: false
},
removeNotification: function removeNotification(index) {
this.state.splice(index, 1);
removeNotification: function removeNotification(timestamp) {
var indexToDelete = this.state.findIndex(function (n) {
return n.timestamp === timestamp;
});
if (indexToDelete !== -1) {
this.state.splice(indexToDelete, 1);
}
},
addNotification: function addNotification(notification) {
notification.timestamp = new Date();
Expand Down
2 changes: 1 addition & 1 deletion dist/vue-notifyjs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 178ef19

Please sign in to comment.