Skip to content

Commit cdec488

Browse files
committed
119602: Compare notifications by id to correctly update store
1 parent c38352e commit cdec488

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/app/shared/notifications/notifications-board/notifications-board.component.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010

1111
import { select, Store } from '@ngrx/store';
1212
import { BehaviorSubject, Subscription, take } from 'rxjs';
13-
import difference from 'lodash/difference';
1413

1514
import { NotificationsService } from '../notifications.service';
1615
import { AppState } from '../../../app.reducer';
@@ -23,6 +22,7 @@ import {
2322
AccessibilitySetting
2423
} from '../../../accessibility/accessibility-settings.service';
2524
import cloneDeep from 'lodash/cloneDeep';
25+
import differenceWith from 'lodash/differenceWith';
2626

2727
@Component({
2828
selector: 'ds-notifications-board',
@@ -69,13 +69,13 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
6969
this.notifications = [];
7070
} else if (state.length > this.notifications.length) {
7171
// Add
72-
const newElem = difference(state, this.notifications);
72+
const newElem = differenceWith(state, this.notifications, this.byId);
7373
newElem.forEach((notification) => {
7474
this.add(notification);
7575
});
7676
} else {
7777
// Remove
78-
const delElem = difference(this.notifications, state);
78+
const delElem = differenceWith(this.notifications, state, this.byId);
7979
delElem.forEach((notification) => {
8080
this.notifications = this.notifications.filter((item: INotification) => item.id !== notification.id);
8181

@@ -85,6 +85,9 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
8585
});
8686
}
8787

88+
private byId = (notificationA: INotification, notificationB: INotification) =>
89+
notificationA.id === notificationB.id;
90+
8891
// Add the new notification to the notification array
8992
add(item: INotification): void {
9093
const toBlock: boolean = this.block(item);

0 commit comments

Comments
 (0)