From 5c602ab16f1f5e46bee5f44cec15860f785039ee Mon Sep 17 00:00:00 2001
From: Aiden Bai <aiden.bai05@gmail.com>
Date: Mon, 02 May 2022 16:04:36 +0000
Subject: [PATCH] Add clarification comments

---
 assets/js/search.js        |    1 +
 assets/js/graph.js         |    6 +++---
 layouts/partials/head.html |    3 +++
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/assets/js/graph.js b/assets/js/graph.js
index 939fd99..99ecf54 100644
--- a/assets/js/graph.js
+++ b/assets/js/graph.js
@@ -16,9 +16,8 @@
     ...new Set(links.flatMap((link) => [link.source, link.target])),
   ];
 
-  // links is mutated by d3
-  // we want to use links later on, so we make a copy and pass
-  // that one to d3
+  // Links is mutated by d3. We want to use links later on, so we make a copy and pass that one to d3
+  // Note: shallow cloning does not work because it copies over references from the original array
   const copyLinks = JSON.parse(JSON.stringify(links));
 
   const neighbours = new Set();
@@ -176,6 +175,7 @@
     .attr('fill', color)
     .style('cursor', 'pointer')
     .on('click', (_, d) => {
+      // SPA navigation
       window.navigate(
         new URL(`${baseUrl}${decodeURI(d.id).replace(/\s+/g, '-')}/`),
         '.singlePage'
diff --git a/assets/js/search.js b/assets/js/search.js
index 212b2c7..fcf7917 100644
--- a/assets/js/search.js
+++ b/assets/js/search.js
@@ -145,6 +145,7 @@
   };
 
   const redir = (id, term) => {
+    // SPA navigation
     window.navigate(
       new URL(
         `${BASE_URL.slice(0, -1)}${id}#:~:text=${encodeURIComponent(term)}/`
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 772153a..ea67a00 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -57,9 +57,12 @@
   </script>
   <script type="module">
     import { router, navigate } from "https://unpkg.com/million/dist/router.mjs";
+    // SPA navigation for access later
     window.navigate = navigate;
+    // We only mutate document.title and content within .singlePage element
     router(".singlePage");
     const callback = () => {
+      // requestAnimationFrame()
       const draw = () => {
         const container = document.getElementById("graph-container");
         // retry if the graph is not ready

--
Gitblit v1.10.0