From eb695fd61d97a8b4ce9de9c65b0133515d087a2c Mon Sep 17 00:00:00 2001
From: taehoon
Date: Mon, 21 Oct 2019 20:57:36 -0400
Subject: [PATCH] refactor using Set
---
src/directives/body_scroll_lock.js | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/src/directives/body_scroll_lock.js b/src/directives/body_scroll_lock.js
index d7f114b5..13a6de1c 100644
--- a/src/directives/body_scroll_lock.js
+++ b/src/directives/body_scroll_lock.js
@@ -2,18 +2,16 @@ import * as bodyScrollLock from 'body-scroll-lock'
let previousNavPaddingRight
let previousAppBgWrapperRight
-let lockerEls = []
+const lockerEls = new Set([])
const disableBodyScroll = (el) => {
const scrollBarGap = window.innerWidth - document.documentElement.clientWidth
bodyScrollLock.disableBodyScroll(el, {
reserveScrollBarGap: true
})
- if (!lockerEls.includes(el)) {
- lockerEls.push(el)
- }
+ lockerEls.add(el)
setTimeout(() => {
- if (lockerEls.length <= 1) {
+ if (lockerEls.size <= 1) {
// If previousNavPaddingRight is already set, don't set it again.
if (previousNavPaddingRight === undefined) {
const navEl = document.getElementById('nav')
@@ -32,11 +30,9 @@ const disableBodyScroll = (el) => {
}
const enableBodyScroll = (el) => {
- if (lockerEls.includes(el)) {
- lockerEls = lockerEls.filter(e => e !== el)
- }
+ lockerEls.delete(el)
setTimeout(() => {
- if (lockerEls.length === 0) {
+ if (lockerEls.size === 0) {
if (previousNavPaddingRight !== undefined) {
document.getElementById('nav').style.paddingRight = previousNavPaddingRight
// Restore previousNavPaddingRight to undefined so disableBodyScroll knows it can be set again.