Browse Source

Remove more unused fns

Gabriel Horner 4 years ago
parent
commit
b3ee61b1ca

+ 5 - 1
.carve/config.edn

@@ -1,5 +1,9 @@
 {:paths ["src/main" "src/electron" "src/test"]
  :api-namespaces [
                   ;; Ignore b/c too many false positives
-                  frontend.db]
+                  frontend.db
+                  ;; Used for debugging
+                  frontend.db.debug
+                  ;; namespace fns are lazily loaded
+                  frontend.extensions.age-encryption]
  :report {:format :ignore}}

+ 12 - 44
.carve/ignore

@@ -5,7 +5,6 @@ electron.core/stop
 ;; repl fn
 electron.search/query
 frontend.blob/blob
-frontend.components.sidebar/nav-item
 frontend.components.svg/arrow-left
 frontend.components.svg/arrow-right
 frontend.components.svg/big-arrow-right
@@ -48,62 +47,31 @@ frontend.components.svg/icon-editor
 frontend.components.svg/icon-cli
 frontend.components.svg/settings
 frontend.components.svg/arrow-expand
-frontend.config/git-repo-status-secs
-frontend.config/get-subscript
-frontend.config/get-superscript
-frontend.config/properties-wrapper
-frontend.config/get-file-format
-frontend.config/default-empty-block
-frontend.config/with-code-wrapper
-frontend.context.i18n/use-tongue
+;; Used by shadow-cljs
 frontend.core/stop
-frontend.date/ISO-string
-frontend.date/get-local-date-time-string
-frontend.date/get-month-last-day
-frontend.date/int->local-time
-frontend.db.debug/qb
-frontend.db.debug/check-left-id-conflicts
-frontend.db.debug/block-uuid-nil?
-frontend.db.model/get-file-by-path
-frontend.db.model/get-page-ids-by-names
-frontend.db.model/remove-children!
 frontend.db.model/with-children-refs
-frontend.db.model/db-graph?
-frontend.db.model/remove-all-aliases!
 frontend.db.model/get-latest-changed-pages
-frontend.db.model/remove-orphaned-pages!
-frontend.db.outliner/save-block
-frontend.db.outliner/remove-non-existed-refs!
-frontend.db.react/add-rules-to-inputs
+;; For repl
 frontend.db.utils/q
+;; For debugging
 frontend.debug/defn
 frontend.debug/print
+;; Left as an example
 frontend.diff/diffs
-frontend.diff/get-patches
-frontend.diff/apply-patches!
-frontend.extensions.age-encryption/keygen
-frontend.extensions.age-encryption/encrypt-with-x25519
-frontend.extensions.age-encryption/decrypt-with-x25519
-frontend.extensions.age-encryption/encrypt-with-user-passphrase
-frontend.extensions.age-encryption/decrypt-with-user-passphrase
+;; Lazily loaded
 frontend.extensions.code/editor
-frontend.extensions.excalidraw/*bounding-width
+;; Lazily loaded
 frontend.extensions.excalidraw/draw
-frontend.extensions.graph/reset-graph!
-frontend.extensions.graph.pixi/*dark?
-frontend.extensions.pdf.assets/*asset-uploading?
+;; Referenced in TODO
 frontend.extensions.pdf.utils/get-page-bounding
-frontend.extensions.pdf.utils/gen-id
+;; For repl
 frontend.extensions.zotero.api/item
+;; For repl
 frontend.external.roam/reset-state!
-frontend.format.block/extract-title
-frontend.format.block/hiccup-block?
-frontend.format.block/definition-list-block?
-frontend.format.block/src-block?
+;; For repl
 frontend.format.mldoc/ast-export-markdown
+;; Protocol fn wrapper that could be used
 frontend.fs/readdir
-frontend.git/log
-frontend.git/pull
 frontend.git/commit-non-empty
 frontend.git/add-commit
 frontend.git/find-common-base
@@ -212,5 +180,5 @@ frontend.util.cursor/move-cursor-to-beginning
 frontend.util.pool/terminate-parser-pool!
 frontend.util.property/goto-properties-beginning
 frontend.util.property/add-page-properties
+;; Used by shadow
 frontend.worker.parser/init
-frontend.react/auto-clean-state

+ 0 - 14
src/main/frontend/components/sidebar.cljs

@@ -34,20 +34,6 @@
             [frontend.mobile.util :as mobile-util]
             [frontend.handler.mobile.swipe :as swipe]))
 
-(defn nav-item
-  [title href svg-d _active? close-modal-fn]
-  [:a.mb-1.group.flex.items-center.pl-4.py-2.text-base.leading-6.font-medium.hover:text-gray-200.transition.ease-in-out.duration-150.nav-item
-   {:href href
-    :on-click close-modal-fn}
-   [:svg.mr-4.h-6.w-6.group-hover:text-gray-200.group-focus:text-gray-200.transition.ease-in-out.duration-150
-    {:viewBox "0 0 24 24", :fill "none", :stroke "currentColor"}
-    [:path
-     {:d svg-d
-      :stroke-width "2"
-      :stroke-linejoin "round"
-      :stroke-linecap "round"}]]
-   title])
-
 (rum/defc nav-content-item
   [name {:keys [class]} child]
 

+ 0 - 47
src/main/frontend/config.cljs

@@ -60,10 +60,6 @@
   []
   (or 10 (get-in @state/state [:config :git-push-secs])))
 
-(defn git-repo-status-secs
-  []
-  (or 10 (get-in @state/state [:config :git-push-secs])))
-
 (defn text-formats
   []
   (let [config-formats (some->> (get-in @state/state [:config :text-formats])
@@ -185,14 +181,6 @@
       "`"
       "")))
 
-(defn get-subscript
-  [_format]
-  "_")
-
-(defn get-superscript
-  [_format]
-  "^")
-
 (defn get-empty-link-and-forward-pos
   [format]
   (case format
@@ -235,13 +223,6 @@
      (+ 3 (count label))]
     ["" 0]))
 
-(defn properties-wrapper
-  [format]
-  (case format
-    :markdown
-    "---\n\n---"
-    ""))
-
 (defn properties-wrapper-pattern
   [format]
   (case format
@@ -256,34 +237,6 @@
     "md"
     (name format)))
 
-(defn get-file-format
-  [extension]
-  (case (keyword extension)
-    :markdown
-    :markdown
-    :md
-    :markdown
-    (keyword extension)))
-
-(defn default-empty-block
-  ([format]
-   (default-empty-block format 2))
-  ([format n]
-   (let [block-pattern (get-block-pattern format)]
-     (apply str (repeat n block-pattern)))))
-
-(defn with-code-wrapper
-  [format mode code]
-  (let [mode (if-not (string/blank? mode)
-               (str mode " ")
-               "")]
-    (case format
-      :markdown
-      (util/format "```%s\n%s\n```" mode code)
-      :org
-      (util/format "#+BEGIN_SRC%s\n%s\n#+END_SRC" mode code)
-      code)))
-
 (defonce default-journals-directory "journals")
 (defonce default-pages-directory "pages")
 (defonce default-draw-directory "draws")

+ 0 - 6
src/main/frontend/context/i18n.cljs

@@ -38,9 +38,3 @@
       :ok)
     (rum/bind-context [*tongue-context* [t preferred-language set-preferred-language]]
                       children)))
-
-(rum/defc use-tongue []
-  (rum/with-context [value *tongue-context*]
-    (if (nil? value)
-      (throw "use-i18n must be used within a i18n-provider")
-      value)))

+ 0 - 18
src/main/frontend/date.cljs

@@ -77,14 +77,6 @@
     (catch js/Error _e
       nil)))
 
-(defn ISO-string
-  []
-  (.toISOString (js/Date.)))
-
-(defn get-local-date-time-string
-  []
-  (get-date-time-string (tl/local-now)))
-
 (def custom-formatter-2 (tf/formatter "yyyy-MM-dd-HH-mm-ss"))
 (defn get-date-time-string-2 []
   (tf/unparse custom-formatter-2 (tl/local-now)))
@@ -145,12 +137,6 @@
   []
   (journal-name (t/minus (t/today) (t/days 1))))
 
-(defn get-month-last-day
-  []
-  (let [today (js/Date.)
-        date (js/Date. (.getFullYear today) (inc (.getMonth today)) 0)]
-    (.getDate date)))
-
 (defn ymd
   ([]
    (ymd (js/Date.)))
@@ -249,10 +235,6 @@
   [journal-title]
   (journal-title-> journal-title format))
 
-(defn int->local-time
-  [n]
-  (get-date-time-string (t/to-default-time-zone (tc/from-long n))))
-
 (defn int->local-time-2
   [n]
   (tf/unparse

+ 0 - 49
src/main/frontend/db/model.cljs

@@ -272,12 +272,6 @@
       conn)
      (flatten))))
 
-(defn get-file-by-path
-  [file-path]
-  (when-let [repo (state/get-current-repo)]
-    (when-let [conn (conn/get-conn repo)]
-      (d/pull conn '[*] [:file/path file-path]))))
-
 (defn get-custom-css
   []
   (when-let [repo (state/get-current-repo)]
@@ -351,16 +345,6 @@
      (->> (db-utils/pull-many repo '[:block/name] ids)
           (map :block/name)))))
 
-(defn get-page-ids-by-names
-  ([names]
-   (get-page-ids-by-names (state/get-current-repo) names))
-  ([repo names]
-   (when repo
-     (let [lookup-refs (map (fn [name]
-                              [:block/name (util/page-name-sanity-lc name)]) names)]
-       (->> (db-utils/pull-many repo '[:db/id] lookup-refs)
-            (mapv :db/id))))))
-
 (defn get-page-alias-names
   [repo page-name]
   (let [alias-ids (page-alias-set repo page-name)]
@@ -936,15 +920,6 @@
                                db-utils/seq-flatten)]
       (mapv (fn [page] [page (get-page-alias repo page)]) mentioned-pages))))
 
-(defn remove-children!
-  [blocks]
-  (let [parents (->> (mapcat :block/parent blocks)
-                     (map :db/id)
-                     (set))]
-    (if (seq parents)
-      (filter (fn [block] (contains? parents (:db/id block))) blocks)
-      blocks)))
-
 (defn has-children?
   ([block-id]
    (has-children? (state/get-current-repo) block-id))
@@ -1227,11 +1202,6 @@
   [repo]
   (db-utils/get-key-value repo :db/type))
 
-(defn db-graph?
-  "Is current graph a database graph instead of a graph on plain-text files?"
-  []
-  (= :database (get-db-type (state/get-current-repo))))
-
 (defn get-public-pages
   [db]
   (-> (d/q
@@ -1436,19 +1406,6 @@
     (when (seq pages)
       (mapv (fn [page] [:db.fn/retractEntity [:block/name page]]) (map util/page-name-sanity-lc pages)))))
 
-(defn remove-all-aliases!
-  [repo]
-  (let [page-ids (->>
-                  (d/q '[:find ?e
-                         :where
-                         [?e :block/alias]]
-                       (conn/get-conn repo))
-                  (apply concat)
-                  (distinct))
-        tx-data (map (fn [page-id] [:db/retract page-id :block/alias]) page-ids)]
-    (when (seq tx-data)
-      (db-utils/transact! repo tx-data))))
-
 (defn set-file-content!
   [repo path content]
   (when (and repo path)
@@ -1571,12 +1528,6 @@
                         (remove nil?))]
     orphaned-pages))
 
-(defn remove-orphaned-pages!
-  ([repo] (remove-orphaned-pages! repo (get-orphaned-pages {})))
-  ([repo orphaned-pages]
-   (let [transaction (mapv (fn [page] [:db/retractEntity (:db/id page)]) orphaned-pages)]
-     (db-utils/transact! repo transaction))))
-
 (defn get-block-last-direct-child
   [db-id]
   (when-let [block (db-utils/entity db-id)]

+ 1 - 16
src/main/frontend/db/outliner.cljs

@@ -1,8 +1,5 @@
 (ns frontend.db.outliner
-  (:require [datascript.core :as d]
-            [frontend.db :as db]
-            [frontend.db.utils :as db-utils]
-            [frontend.util :as util]))
+  (:require [datascript.core :as d]))
 
 (defn get-by-id
   [conn id]
@@ -28,14 +25,6 @@
     :where
     [?a :block/parent ?id]])
 
-(defn save-block
-  [conn block-m]
-  (let [tx (-> (dissoc block-m :block/children :block/level :block/meta)
-             (util/remove-nils))
-        block-id (:block/uuid block-m)]
-    (d/transact! conn [tx])
-    (db-utils/pull [:block/uuid block-id])))
-
 (defn del-block
   [conn id-or-look-ref]
   (d/transact! conn [[:db.fn/retractEntity id-or-look-ref]]))
@@ -53,7 +42,3 @@
                  [?a :block/journal? true]]
                @conn)]
     (flatten r)))
-
-(defn remove-non-existed-refs!
-  [refs]
-  (filter db/entity refs))

+ 1 - 6
src/main/frontend/db/react.cljs

@@ -12,8 +12,7 @@
             [frontend.db.utils :as db-utils]
             [frontend.state :as state]
             [frontend.util :as util :refer [react]]
-            [frontend.util.marker :as marker]
-            [frontend.db.rules :as rules]))
+            [frontend.util.marker :as marker]))
 
 ;; Query atom of map of Key ([repo q inputs]) -> atom
 ;; TODO: replace with LRUCache, only keep the latest 20 or 50 items?
@@ -136,10 +135,6 @@
          (set! (.-state result-atom) result)
          (add-q! k nil nil result-atom identity identity identity))))))
 
-(defn add-rules-to-inputs
-  [inputs]
-  (conj (vec inputs) rules/rules))
-
 (defn q
   [repo k {:keys [use-cache? transform-fn query-fn inputs-fn disable-reactive?]
            :or {use-cache? true

+ 0 - 11
src/main/frontend/diff.cljs

@@ -20,17 +20,6 @@
   [s1 s2]
   (.diff_main dmp s1 s2 true))
 
-(defn get-patches
-  [s1 s2 diffs]
-  (.patch_make dmp s1 s2 diffs))
-
-(defn apply-patches!
-  [text patches]
-  (if (seq patches)
-    (let [result (.patch_apply dmp patches text)]
-      (nth result 0))
-    text))
-
 (def inline-special-chars
   #{\* \_ \/ \` \+ \^ \~ \$})
 

+ 0 - 2
src/main/frontend/extensions/excalidraw.cljs

@@ -27,8 +27,6 @@
          (util/format "Could not load this invalid excalidraw file")
          :error)))))
 
-(defonce *bounding-width (atom nil))
-
 (defn- update-draw-content-width
   [state]
   (let [el ^js (rum/dom-node state)

+ 0 - 4
src/main/frontend/extensions/graph.cljs

@@ -44,10 +44,6 @@
         (.unhoverNode ^js graph node)
         (route-handler/redirect-to-page! page-name)))))
 
-(defn reset-graph!
-  [^js graph]
-  (.resetView graph))
-
 (rum/defcs graph-2d <
   (rum/local nil :ref)
   {:did-update pixi/render!

+ 0 - 2
src/main/frontend/extensions/graph/pixi.cljs

@@ -97,8 +97,6 @@
     (reset! *graph-instance nil)
     (reset! *simulation nil)))
 
-(defonce *dark? (atom nil))
-
 (defn- update-position!
   [node obj]
   (.updatePosition node #js {:x (.-x obj)

+ 0 - 2
src/main/frontend/extensions/pdf/assets.cljs

@@ -14,8 +14,6 @@
             [reitit.frontend.easy :as rfe]
             [rum.core :as rum]))
 
-(defonce *asset-uploading? (atom false))
-
 (defn hls-file?
   [filename]
   (and filename (string? filename) (string/starts-with? filename "hls__")))

+ 0 - 4
src/main/frontend/extensions/pdf/utils.cljs

@@ -113,10 +113,6 @@
   (when (sequential? its)
     (mapv #(if (map? %) % (bean/->clj %)) its)))
 
-(defn gen-id []
-  (str (.toString (js/Date.now) 36)
-       (.. (js/Math.random) (toString 36) (substr 2 4))))
-
 (defn gen-uuid []
   (front-db/new-block-id))
 

+ 0 - 24
src/main/frontend/format/block.cljs

@@ -136,38 +136,18 @@
                (util/uuid-string? block-id))
       block-id)))
 
-;; FIXME:
-(defn extract-title
-  [block]
-  (-> (:title (second block))
-      first
-      second))
-
 (defn paragraph-block?
   [block]
   (and
    (vector? block)
    (= "Paragraph" (first block))))
 
-(defn hiccup-block?
-  [block]
-  (and
-   (vector? block)
-   (= "Hiccup" (first block))))
-
 (defn timestamp-block?
   [block]
   (and
    (vector? block)
    (= "Timestamp" (first block))))
 
-(defn definition-list-block?
-  [block]
-  (and
-   (vector? block)
-   (= "List" (first block))
-   (:name (first (second block)))))
-
 ;; TODO: we should move this to mldoc
 (defn extract-properties
   [properties]
@@ -418,10 +398,6 @@
                                 [:block/name (util/page-name-sanity-lc tag)])) tags))
     block))
 
-(defn src-block?
-  [block]
-  (some (fn [x] (and (vector? x) (= "Src" (first x)))) (:body block)))
-
 (defn- get-block-content
   [utf8-content block format block-content]
   (let [meta (:meta block)

+ 0 - 14
src/main/frontend/git.cljs

@@ -65,20 +65,6 @@
   (js/window.workerThread.checkout (config/get-repo-dir repo-url)
                                    (state/get-default-branch repo-url)))
 
-(defn log
-  [repo-url depth]
-  (js/window.workerThread.log (config/get-repo-dir repo-url)
-                              (state/get-default-branch repo-url)
-                              depth))
-
-(defn pull
-  [repo-url token]
-  (js/window.workerThread.pull (config/get-repo-dir repo-url)
-                               (get-cors-proxy repo-url)
-                               (state/get-default-branch repo-url)
-                               (get-username)
-                               token))
-
 (defn add
   [repo-url file]
   (when js/window.git

+ 0 - 7
src/test/frontend/react.cljc

@@ -67,10 +67,3 @@
           [key & body]
           `(binding [*with-key* ~key]
              ~@body)))
-
-#?(:clj (defmacro auto-clean-state
-          [& body]
-          `(do (reset! react-components {})
-               (let [result# ~@body]
-                 (reset! react-components {})
-                 result#))))