Skip to content

Commit

Permalink
119602: Fix compares
Browse files Browse the repository at this point in the history
  • Loading branch information
AAwouters committed Nov 29, 2024
1 parent c38352e commit 56d8276
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {

import { select, Store } from '@ngrx/store';
import { BehaviorSubject, Subscription, take } from 'rxjs';
import difference from 'lodash/difference';

import { NotificationsService } from '../notifications.service';
import { AppState } from '../../../app.reducer';
import { notificationsStateSelector } from '../selectors';
Expand All @@ -23,6 +21,7 @@ import {
AccessibilitySetting
} from '../../../accessibility/accessibility-settings.service';
import cloneDeep from 'lodash/cloneDeep';
import differenceWith from 'lodash/differenceWith';

@Component({
selector: 'ds-notifications-board',
Expand Down Expand Up @@ -69,13 +68,13 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
this.notifications = [];
} else if (state.length > this.notifications.length) {
// Add
const newElem = difference(state, this.notifications);
const newElem = differenceWith(state, this.notifications, this.toCheck);
newElem.forEach((notification) => {
this.add(notification);
});
} else {
// Remove
const delElem = difference(this.notifications, state);
const delElem = differenceWith(this.notifications, state, this.toCheck);
delElem.forEach((notification) => {
this.notifications = this.notifications.filter((item: INotification) => item.id !== notification.id);

Expand Down Expand Up @@ -117,16 +116,15 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
}

private block(item: INotification): boolean {
const toCheck = item.html ? this.checkHtml : this.checkStandard;
this.notifications.forEach((notification) => {
if (toCheck(notification, item)) {
if (this.toCheck(notification, item)) {
return true;
}
});

if (this.notifications.length > 0) {
this.notifications.forEach((notification) => {
if (toCheck(notification, item)) {
if (this.toCheck(notification, item)) {
return true;
}
});
Expand All @@ -138,9 +136,17 @@ export class NotificationsBoardComponent implements OnInit, OnDestroy {
} else {
return false;
}
return toCheck(comp, item);
return this.toCheck(comp, item);
}

private toCheck = (checker: INotification, item: INotification) => {
if (item.html) {
return this.checkHtml(checker, item);
} else {
return this.checkStandard(checker, item);
}
};

private checkStandard(checker: INotification, item: INotification): boolean {
return checker.type === item.type && checker.title === item.title && checker.content === item.content;
}
Expand Down

0 comments on commit 56d8276

Please sign in to comment.