Browse Source

fix: both pages and blocks indices default to an empty array

Tienson Qin 4 years ago
parent
commit
10314b1117
2 changed files with 9 additions and 5 deletions
  1. 3 0
      externs.js
  2. 6 5
      src/main/frontend/search.cljs

+ 3 - 0
externs.js

@@ -47,3 +47,6 @@ dummy.createWritable = function() {};
 dummy.write = function() {};
 dummy.close = function() {};
 dummy.values = function() {};
+// Do we really need those?
+dummy.filter = function() {};
+dummy.concat = function() {};

+ 6 - 5
src/main/frontend/search.cljs

@@ -48,9 +48,8 @@
                      (remove string/blank?)
                      (map (fn [p] {:name p}))
                      (bean/->js))]
-      (when (seq pages)
-        (swap! indices assoc-in [repo :pages] pages)
-        pages))))
+      (swap! indices assoc-in [repo :pages] pages)
+      pages)))
 
 ;; TODO: persist indices to indexeddb, it'll be better if the future db
 ;; can has the direct fuzzy search support.
@@ -222,7 +221,8 @@
                                          (set))]
             (swap! search-db/indices update-in [repo :pages]
                    (fn [pages]
-                     (let [pages (.filter pages (fn [page]
+                     (let [pages (or pages (array))
+                           pages (.filter pages (fn [page]
                                                   (not (contains? pages-to-remove-set
                                                                   (string/lower-case (gobj/get page "name"))))))]
                        (.concat pages (bean/->js pages-to-add)))))))
@@ -241,6 +241,7 @@
                                           (set))]
             (swap! search-db/indices update-in [repo :blocks]
                    (fn [blocks]
-                     (let [blocks (.filter blocks (fn [block]
+                     (let [blocks (or blocks (array))
+                           blocks (.filter blocks (fn [block]
                                                     (not (contains? blocks-to-remove-set (gobj/get block "id")))))]
                        (.concat blocks (bean/->js blocks-to-add)))))))))))