From 0b309b2a98ed0ca14e5fdd81aead1ca8a5884c13 Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Thu, 10 Mar 2022 20:43:40 +1100
Subject: Add throttling for resizing. Add array-creation helper functions.

---
 src/components/TileTree.vue | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

(limited to 'src/components/TileTree.vue')

diff --git a/src/components/TileTree.vue b/src/components/TileTree.vue
index 65201c5..68e180d 100644
--- a/src/components/TileTree.vue
+++ b/src/components/TileTree.vue
@@ -20,6 +20,7 @@ export default {
 			tree: this.initTree(tol, 1),
 			width: document.documentElement.clientWidth,
 			height: document.documentElement.clientHeight,
+			resizeThrottled: false,
 		}
 	},
 	methods: {
@@ -43,9 +44,14 @@ export default {
 			return tree;
 		},
 		onResize(){
-			this.width = document.documentElement.clientWidth;
-			this.height = document.documentElement.clientHeight;
-			this.tryLayout(); //use best-effort collapsing-layout?
+			if (!this.resizeThrottled){
+				this.width = document.documentElement.clientWidth;
+				this.height = document.documentElement.clientHeight;
+				this.tryLayout(); //use best-effort collapsing-layout?
+				//prevent re-triggering until after a delay
+				this.resizeThrottled = true;
+				setTimeout(() => {this.resizeThrottled = false;}, 100);
+			}
 		},
 		onInnerTileClicked(nodeList){
 			//nodeList holds an array of tree-objects, from the clicked-on-tile's tree-object upward
-- 
cgit v1.2.3

