Skip to content

Commit c3a4123

Browse files
committed
refactor mathces function to be a pure function
1 parent 5f76199 commit c3a4123

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

core/src/global-ad-events.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ function globalAdEvents(
2828
slotName?: string,
2929
) {
3030
const parsedStatus = Array.isArray(status) ? status : [status];
31-
const matches = (event: AdEventCustomEvent) => {
32-
const statusMatch = parsedStatus.includes(event.detail.name);
31+
32+
const matches = (
33+
event: AdEventCustomEvent,
34+
statusList: AdvertStatus[],
35+
slotName?: string,
36+
) => {
37+
const statusMatch = statusList.includes(event.detail.name);
3338
const slotMatch = !slotName || event.detail.slotName === slotName;
3439
return statusMatch && slotMatch;
3540
};
@@ -49,13 +54,13 @@ function globalAdEvents(
4954
if (!isCustomEvent(e)) {
5055
return;
5156
}
52-
if (matches(e)) {
57+
if (matches(e, parsedStatus, slotName)) {
5358
listenerHandler(e);
5459
}
5560
};
5661

5762
eventHistory.forEach((historyEvent) => {
58-
if (matches(historyEvent)) {
63+
if (matches(historyEvent, parsedStatus, slotName)) {
5964
listenerHandler(historyEvent);
6065
}
6166
});

0 commit comments

Comments
 (0)