I have a list of events. They are html elements. The premium events have a data attribute in their parent element: data-premium-event.
I need to separate the events in two lists:
- a list of premium events
- a list of regular (non-premium) events
I then show oder hide them using the logic in handleVisibleEvents. The method works correctly but I would like to refactor it while it has a high cognitive complexity.
this.nrOfRegularEventsDisplayed = 0;
this.nrOfPremiumEventsDisplayed = 0;
this.regularEventsToShow = [];
this.premiumEventsToShow = [];
this.refreshActiveCategoryTags();
const events = toArray(this.elements['event']);
if (events) {
if (this.loadEventsButton) {
show(this.loadEventsButton);
}
events.forEach((event) => {
if (event.dataset.eventTags.includes(this.activeCategory.dataset.categoryTag)) {
if (event.parentElement.getAttribute('data-premium-event') !== null) {
this.premiumEventsToShow.push(event);
} else {
this.regularEventsToShow.push(event);
}
} else {
hide(event.parentElement);
}
});
this.handleVisibleEvents(TagsFilteringOverview.VISIBLE_EVENTS, false);
}
show
the loadEventsButton only ifevents
evaluates totrue
? \$\endgroup\$