Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just strange line in the source code #329

Open
DimaGashko opened this issue May 28, 2020 · 1 comment
Open

Just strange line in the source code #329

DimaGashko opened this issue May 28, 2020 · 1 comment
Labels
refactor Code updates that shouldn't make any user-facing change
Milestone

Comments

@DimaGashko
Copy link

I've just found one line in the source code that made me confused

https://github.com/ghosh/Micromodal/blob/master/lib/src/index.js#L106

const body = document.querySelector('body')

Why would you use querySelector to find the body element?
There's document.body to do this - shorter, faster, full support

@DimaGashko
Copy link
Author

DimaGashko commented May 28, 2020

Ok, I don't like that function at all. Too complicated to do so simple thing.
I would write so (

/** @param {'enable'|'disable'} value */
scrollBehaviour(value) {
   if (!this.config.disableScroll) return

   if (value === 'enable') {
      document.body.style.overflow = '';
   } else if (value === 'disable') {
      document.body.style.overflow = 'hidden';
   }
}
Or:
/** @param {'enable'|'disable'} value */
scrollBehaviour(value) {
   if (!this.config.disableScroll) return
   const overflow = (value === 'disable') ? 'hidden' : '';
   document.body.style.overflow = overflow;
}
Or:
/** @param {boolean} value */
function toggleScrolling(value) {
   if (!this.config.disableScroll) return
   document.body.style.overflow = (!value) ? 'hidden' : '';
}

@dkniffin dkniffin added this to the pre-1.0 milestone Mar 21, 2025
@dkniffin dkniffin added the refactor Code updates that shouldn't make any user-facing change label Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code updates that shouldn't make any user-facing change
Projects
None yet
Development

No branches or pull requests

2 participants