Skip to content

Commit

Permalink
Use null instead of empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWr committed May 23, 2024
1 parent 628e64f commit 1f671bd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/scriptlets/trusted-click-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ export function trustedClickElement(
return true;
}

if (!parsedCookies[cookieKey]) {
return false;
}

return valueMatch.test(parsedCookies[cookieKey] || '');
});
});
Expand Down Expand Up @@ -261,7 +265,7 @@ export function trustedClickElement(
* - always know on what index corresponding element should be put
* - prevent selectors from being queried multiple times
*/
let selectorsSequence = selectors
let selectorsSequence: Array<string | null> = selectors
.split(SELECTORS_DELIMITER)
.map((selector) => selector.trim());

Expand Down Expand Up @@ -343,11 +347,13 @@ export function trustedClickElement(

// selectorsSequence should be modified after the loop to not break loop indexation
selectorsSequence = selectorsSequence.map((selector) => {
return fulfilledSelectors.includes(selector) ? '' : selector;
return selector && fulfilledSelectors.includes(selector)
? null
: selector;
});

// Disconnect observer after finding all elements
const allSelectorsFulfilled = selectorsSequence.every((selector) => selector === '');
const allSelectorsFulfilled = selectorsSequence.every((selector) => selector === null);
if (allSelectorsFulfilled) {
observer.disconnect();
}
Expand Down

0 comments on commit 1f671bd

Please sign in to comment.