[gi-docgen: 9/10] lint: remove dead code & refactor names




commit e4e083c4f1c9b6c85e0e1b7fe56f5dd03ef933ed
Author: Rom Grk <romgrk cc gmail com>
Date:   Thu Apr 1 10:51:49 2021 -0400

    lint: remove dead code & refactor names

 gidocgen/templates/basic/search.js | 60 +++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 33 deletions(-)
---
diff --git a/gidocgen/templates/basic/search.js b/gidocgen/templates/basic/search.js
index 905b019..8913f69 100644
--- a/gidocgen/templates/basic/search.js
+++ b/gidocgen/templates/basic/search.js
@@ -66,7 +66,7 @@ function onDidLoadSearchIndex(data) {
 function onDidSearch() {
     const query = refs.input.value
     if (query)
-        search(refs.input.value)
+        search(query)
     else
         hideSearchResults()
 }
@@ -123,40 +123,38 @@ function hideSearchResults() {
     removeClass(refs.main, "hidden");
 }
 
-function renderResults(results) {
-    if (results.length === 0)
-        return "No results found.";
+function renderResults(query, results) {
+    let html = "";
 
-    let output = "";
+    html += "<h1>Results for &quot;" + query + "&quot; (" + results.length + ")</h1>" +
+                "<div id=\"search-results\">"
 
-    output += "<table class=\"results\">" +
-                "<tr><th>Name</th><th>Description</th></tr>";
-
-    results.forEach(function(item) {
-        output += "<tr>" +
-                    "<td class=\"result " + item.type + "\">" +
-                      "<a href=\"" + item.href + "\"><code>" + item.text + "</code></a>" +
-                    "</td>" +
-                    "<td>" + item.summary + "</td>" +
-                  "</tr>";
-    });
+    if (results.length === 0) {
+        html += "No results found.";
+    }
+    else {
+        html += "<table class=\"results\">" +
+                  "<tr><th>Name</th><th>Description</th></tr>";
+        results.forEach(function(item) {
+            html += "<tr>" +
+                        "<td class=\"result " + item.type + "\">" +
+                        "<a href=\"" + item.href + "\"><code>" + item.text + "</code></a>" +
+                        "</td>" +
+                        "<td>" + item.summary + "</td>" +
+                    "</tr>";
+        });
+        html += "</table>";
+    }
 
-    output += "</table>";
+    html += "</div>";
 
-    return output;
+    return html;
 }
 
 function showResults(query, results) {
     window.title = "Results for: " + query;
     window.scroll({ top: 0 })
-
-    const output =
-        "<h1>Results for &quot;" + query + "&quot; (" + results.length + ")</h1>" +
-        "<div id=\"search-results\">" +
-            renderResults(results) +
-        "</div>";
-
-    refs.search.innerHTML = output;
+    refs.search.innerHTML = renderResults(query, results);
     showSearchResults(search);
 }
 
@@ -168,16 +166,12 @@ function SearchIndex(searchIndex) {
     this.meta = searchIndex.meta;
 }
 SearchIndex.prototype.searchDocs = function searchDocs(term, type) {
-    const filteredSymbols = type ? this.symbols.filter(s => s.type === type) : this.symbols;
+    const filteredSymbols = !type ?
+        this.symbols :
+        this.symbols.filter(s => s.type === type);
     const results = fzy.filter(term, filteredSymbols, doc => getTextForDocument(doc, this.meta))
     return results.map(i => i.item)
 }
-SearchIndex.prototype.getDocumentFromId = function getDocumentFromId(id) {
-    if (typeof id === "number") {
-        return this.searchIndex.symbols[id];
-    }
-    return null;
-}
 
 
 /* Search metadata selectors */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]