Skip to content

Commit

Permalink
fix: both pages and blocks indices default to an empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Dec 13, 2020
1 parent 4662281 commit 10314b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {};
11 changes: 6 additions & 5 deletions src/main/frontend/search.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)))))))
Expand All @@ -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)))))))))))

0 comments on commit 10314b1

Please sign in to comment.