From 393c36109f38573575163b5bd8572711894f7ccc Mon Sep 17 00:00:00 2001 From: KuthorX Date: Tue, 29 Jun 2021 23:48:41 +0800 Subject: [PATCH] optimize: ReSizer function --- render-process/index.tsx | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/render-process/index.tsx b/render-process/index.tsx index 031ead0..f711f35 100644 --- a/render-process/index.tsx +++ b/render-process/index.tsx @@ -96,18 +96,18 @@ export default class Main extends Component { } function doDrag(e: DragEvent) { - let calcWidth = startWidth + e.clientX - startX; - const maxValue = window.innerWidth * 0.8; - const minValue = 100; - if (calcWidth > maxValue) { - calcWidth = maxValue; - } else if (calcWidth < minValue) { - calcWidth = minValue; - } + const calcWidth = startWidth + e.clientX - startX; setWidth(calcWidth); } function setWidth(width: number) { + const maxValue = window.innerWidth * 0.8; + const minValue = 100; + if (width > maxValue) { + width = maxValue; + } else if (width < minValue) { + width = minValue; + } reSizerParent.style.width = width + "px"; sider.style.width = width + "px"; sider.style.maxWidth = width + "px"; @@ -130,14 +130,7 @@ export default class Main extends Component { }, false); window.addEventListener("resize", function() { - let currentWidth = parseInt(document.defaultView.getComputedStyle(reSizerParent).width, 10); - const maxValue = window.innerWidth * 0.8; - const minValue = 100; - if (currentWidth > maxValue) { - currentWidth = maxValue; - } else if (currentWidth < minValue) { - currentWidth = minValue; - } + const currentWidth = parseInt(document.defaultView.getComputedStyle(reSizerParent).width, 10); setWidth(currentWidth); }) }