Skip to content

Commit 178ef19

Browse files
committed
Handle notification removal after timeout better
1 parent 8885f05 commit 178ef19

File tree

13 files changed

+46
-104
lines changed

13 files changed

+46
-104
lines changed

dist/vue-notifyjs.common.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ var Notification = {
8787
},
8888
methods: {
8989
close: function close() {
90-
this.$emit('close');
90+
this.$emit('close', this.timestamp);
9191
}
9292
},
9393
mounted: function mounted() {
@@ -168,8 +168,8 @@ var Notifications = {
168168
},
169169

170170
methods: {
171-
removeNotification: function removeNotification(index) {
172-
this.$notifications.removeNotification(index);
171+
removeNotification: function removeNotification(timestamp) {
172+
this.$notifications.removeNotification(timestamp);
173173
}
174174
},
175175
created: function created() {
@@ -194,10 +194,8 @@ var Notifications = {
194194
component: notification.component,
195195
timestamp: notification.timestamp
196196
},
197-
key: notification, on: {
198-
'close': function close() {
199-
return _this.removeNotification(index);
200-
}
197+
key: notification.timestamp.getTime(), on: {
198+
'close': _this.removeNotification
201199
}
202200
},
203201
[]
@@ -228,8 +226,13 @@ var NotificationStore = {
228226
settings: {
229227
overlap: false
230228
},
231-
removeNotification: function removeNotification(index) {
232-
this.state.splice(index, 1);
229+
removeNotification: function removeNotification(timestamp) {
230+
var indexToDelete = this.state.findIndex(function (n) {
231+
return n.timestamp === timestamp;
232+
});
233+
if (indexToDelete !== -1) {
234+
this.state.splice(indexToDelete, 1);
235+
}
233236
},
234237
addNotification: function addNotification(notification) {
235238
notification.timestamp = new Date();

dist/vue-notifyjs.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ var Notification = {
9191
},
9292
methods: {
9393
close: function close() {
94-
this.$emit('close');
94+
this.$emit('close', this.timestamp);
9595
}
9696
},
9797
mounted: function mounted() {
@@ -172,8 +172,8 @@ var Notifications = {
172172
},
173173

174174
methods: {
175-
removeNotification: function removeNotification(index) {
176-
this.$notifications.removeNotification(index);
175+
removeNotification: function removeNotification(timestamp) {
176+
this.$notifications.removeNotification(timestamp);
177177
}
178178
},
179179
created: function created() {
@@ -198,10 +198,8 @@ var Notifications = {
198198
component: notification.component,
199199
timestamp: notification.timestamp
200200
},
201-
key: notification, on: {
202-
'close': function close() {
203-
return _this.removeNotification(index);
204-
}
201+
key: notification.timestamp.getTime(), on: {
202+
'close': _this.removeNotification
205203
}
206204
},
207205
[]
@@ -232,8 +230,13 @@ var NotificationStore = {
232230
settings: {
233231
overlap: false
234232
},
235-
removeNotification: function removeNotification(index) {
236-
this.state.splice(index, 1);
233+
removeNotification: function removeNotification(timestamp) {
234+
var indexToDelete = this.state.findIndex(function (n) {
235+
return n.timestamp === timestamp;
236+
});
237+
if (indexToDelete !== -1) {
238+
this.state.splice(indexToDelete, 1);
239+
}
237240
},
238241
addNotification: function addNotification(notification) {
239242
notification.timestamp = new Date();

dist/vue-notifyjs.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)