Skip to content

Commit

Permalink
utils: cache classList.contains() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Oct 18, 2021
1 parent 8910bb7 commit 7336aae
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/js/page/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ export function readFileAsText(file) {

function transitionClassFunc({ removeClass = false } = {}) {
return (element, className = 'active', transitionClass = 'transition') => {
const hasClass = element.classList.contains(className);

if (removeClass) {
if (!element.classList.contains(className)) return Promise.resolve();
} else if (element.classList.contains(className)) return Promise.resolve();
if (!hasClass) return Promise.resolve();
} else if (hasClass) {
return Promise.resolve();
}

const transitionEnd = new Promise(resolve => {
const listener = event => {
Expand Down

0 comments on commit 7336aae

Please sign in to comment.