Skip to content

Commit 3990335

Browse files
authored
Merge pull request #7 from gor181/programmatically-remove-notifications
Support programmatic removal of notifications close #6
2 parents b255e23 + 77fea13 commit 3990335

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

dist/react-notification-system-redux.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ var Notifications = (function (_React$Component) {
136136

137137
var notifications = nextProps.notifications;
138138

139+
var notificationIds = notifications.map(function (notification) {
140+
return notification.uid;
141+
});
142+
143+
// Get all active notifications from react-notification-system
144+
/// and remove all where uid is not found in the reducer
145+
(this.system().state.notifications || []).forEach(function (notification) {
146+
if (notificationIds.indexOf(notification.uid) < 0) {
147+
_this.system().removeNotification(notification.uid);
148+
}
149+
});
150+
139151
notifications.forEach(function (notification) {
140152
_this.system().addNotification(_extends({}, notification, {
141153
onRemove: function onRemove() {

dist/react-notification-system-redux.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.

lib/notifications.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ var Notifications = (function (_React$Component) {
5757

5858
var notifications = nextProps.notifications;
5959

60+
var notificationIds = notifications.map(function (notification) {
61+
return notification.uid;
62+
});
63+
64+
// Get all active notifications from react-notification-system
65+
/// and remove all where uid is not found in the reducer
66+
(this.system().state.notifications || []).forEach(function (notification) {
67+
if (notificationIds.indexOf(notification.uid) < 0) {
68+
_this.system().removeNotification(notification.uid);
69+
}
70+
});
71+
6072
notifications.forEach(function (notification) {
6173
_this.system().addNotification(_extends({}, notification, {
6274
onRemove: function onRemove() {

src/notifications.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ class Notifications extends React.Component {
1313

1414
componentWillReceiveProps(nextProps) {
1515
const {notifications} = nextProps;
16+
const notificationIds = notifications.map(notification => notification.uid);
17+
18+
// Get all active notifications from react-notification-system
19+
/// and remove all where uid is not found in the reducer
20+
(this.system().state.notifications || []).forEach(notification => {
21+
if (notificationIds.indexOf(notification.uid) < 0) {
22+
this.system().removeNotification(notification.uid);
23+
}
24+
});
1625

1726
notifications.forEach(notification => {
1827
this.system().addNotification({

0 commit comments

Comments
 (0)