Skip to content

Commit

Permalink
Use core uuid fns where possible
Browse files Browse the repository at this point in the history
No need for medley or personal util fns when core fns
are available. Also upgraded nbb-logseq to be 1.11.X cljs compatible

- uuid is the same as medley/uuid
- random-uuid is the same as medley/random-uuid
- uuid-string? and uuid is the same as parse-uuid
  • Loading branch information
logseq-cldwalker authored and tiensonqin committed May 19, 2022
1 parent fec0b75 commit 6f68d98
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 98 deletions.
3 changes: 2 additions & 1 deletion .clj-kondo/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
object
;; TODO: Remove parse-* when https://github.com/clj-kondo/clj-kondo/issues/1694 is done
parse-long
parse-double]}
parse-double
parse-uuid]}
;; TODO:lint: Remove node-path excludes once we have a cleaner api
:unresolved-var {:exclude [frontend.util/node-path.basename
frontend.util/node-path.dirname
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "static/electron.js",
"devDependencies": {
"@capacitor/cli": "3.2.2",
"@logseq/nbb-logseq": "^0.3.99",
"@logseq/nbb-logseq": "^0.5.103",
"@playwright/test": "^1.19.2",
"@tailwindcss/ui": "0.7.2",
"@types/gulp": "^4.0.7",
Expand Down
14 changes: 4 additions & 10 deletions src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,8 @@
(rum/defc block-reference < rum/reactive
db-mixins/query
[config id label]
(when (and
(not (string/blank? id))
(util/uuid-string? id))
(let [block-id (uuid id)
block (db/pull-block block-id)
(when-let [block-id (parse-uuid id)]
(let [block (db/pull-block block-id)
block-type (keyword (get-in block [:block/properties :ls-type]))
hl-type (get-in block [:block/properties :hl-type])
repo (state/get-current-repo)]
Expand Down Expand Up @@ -1104,10 +1101,7 @@
(when-let [s (-> (string/replace a "((" "")
(string/replace "))" "")
string/trim)]
(when-let [id (and s
(let [s (string/trim s)]
(and (util/uuid-string? s)
(uuid s))))]
(when-let [id (some-> s string/trim parse-uuid)]
(block-embed (assoc config :link-depth (inc link-depth)) id)))

:else ;TODO: maybe collections?
Expand Down Expand Up @@ -2817,7 +2811,7 @@
:else
(let [language (if (contains? #{"edn" "clj" "cljc" "cljs"} language) "clojure" language)]
(if (:slide? config)
(highlight/highlight (str (medley/random-uuid))
(highlight/highlight (str (random-uuid))
{:class (str "language-" language)
:data-lang language}
code)
Expand Down
4 changes: 2 additions & 2 deletions src/main/frontend/components/content.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,13 @@
e
(custom-context-menu-content))

(and block-id (util/uuid-string? block-id))
(and block-id (parse-uuid block-id))
(let [block (.closest target ".ls-block")]
(when block
(util/select-highlight! [block]))
(common-handler/show-custom-context-menu!
e
(block-context-menu-content target (cljs.core/uuid block-id))))
(block-context-menu-content target (uuid block-id))))

:else
nil))))))
Expand Down
8 changes: 4 additions & 4 deletions src/main/frontend/components/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
(when page-e
(let [page-name (or (:block/name page-e)
(str (:block/uuid page-e)))
block? (util/uuid-string? page-name)
block-id (and block? (uuid page-name))
block-id (parse-uuid page-name)
block? (boolean block-id)
page-blocks (get-blocks repo page-name block-id)]
(if (empty? page-blocks)
(dummy-block page-name)
Expand Down Expand Up @@ -317,8 +317,8 @@
(let [current-repo (state/sub :git/current-repo)
repo (or repo current-repo)
page-name (util/page-name-sanity-lc path-page-name)
block? (util/uuid-string? page-name)
block-id (and block? (uuid page-name))
block-id (parse-uuid page-name)
block? (boolean block-id)
format (let [page (if block-id
(:block/name (:block/page (db/entity [:block/uuid block-id])))
page-name)]
Expand Down
3 changes: 1 addition & 2 deletions src/main/frontend/components/reference.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@
default-collapsed? (>= (count refed-blocks-ids) threshold)
filters-atom (get state ::filters)
filter-state (rum/react filters-atom)
block? (util/uuid-string? page-name)
block-id (and block? (uuid page-name))
block-id (parse-uuid page-name)
page-name (string/lower-case page-name)
journal? (date/valid-journal-title? (string/capitalize page-name))
scheduled-or-deadlines (when (and journal?
Expand Down
5 changes: 2 additions & 3 deletions src/main/frontend/db/debug.cljs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
(ns frontend.db.debug
(:require [medley.core :as medley]
[frontend.db.utils :as db-utils]
(:require [frontend.db.utils :as db-utils]
[frontend.db :as db]
[datascript.core :as d]
[frontend.util :as util]))

;; shortcut for query a block with string ref
(defn qb
[string-id]
(db-utils/pull [:block/uuid (medley/uuid string-id)]))
(db-utils/pull [:block/uuid (uuid string-id)]))

(defn check-left-id-conflicts
[]
Expand Down
9 changes: 4 additions & 5 deletions src/main/frontend/db/model.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,8 @@

(defn get-page
[page-name]
(if (util/uuid-string? page-name)
(db-utils/entity [:block/uuid (uuid page-name)])
(if-let [id (parse-uuid page-name)]
(db-utils/entity [:block/uuid id])
(db-utils/entity [:block/name (util/page-name-sanity-lc page-name)])))

(defn get-redirect-page-name
Expand Down Expand Up @@ -1225,9 +1225,8 @@

(defn get-referenced-blocks-ids
[page-name-or-block-uuid]
(if (util/uuid-string? (str page-name-or-block-uuid))
(let [id (uuid page-name-or-block-uuid)]
(get-block-referenced-blocks-ids id))
(if-let [id (parse-uuid (str page-name-or-block-uuid))]
(get-block-referenced-blocks-ids id)
(get-page-referenced-blocks-ids page-name-or-block-uuid)))

(defn get-matched-blocks
Expand Down
5 changes: 2 additions & 3 deletions src/main/frontend/external/roam.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:require [cljs-bean.core :as bean]
[frontend.external.protocol :as protocol]
[frontend.date :as date]
[medley.core :as medley]
[clojure.walk :as walk]
[clojure.string :as string]
[frontend.util :as util]
Expand Down Expand Up @@ -61,7 +60,7 @@
(set))]
(reset! all-refed-uids uids)
(doseq [uid uids]
(swap! uid->uuid assoc uid (medley/random-uuid))))))
(swap! uid->uuid assoc uid (random-uuid))))))

(defn transform
[text]
Expand All @@ -76,7 +75,7 @@
(defn child->text
[{:keys [uid string children]} level]
(when-not (and (get @uid->uuid uid) uid)
(swap! uid->uuid assoc uid (medley/random-uuid)))
(swap! uid->uuid assoc uid (random-uuid)))
(let [children-text (children->text children (inc level))
level-pattern (str (apply str (repeat level "\t"))
(if (zero? level)
Expand Down
37 changes: 13 additions & 24 deletions src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
[goog.dom.classes :as gdom-classes]
[goog.object :as gobj]
[lambdaisland.glogi :as log]
[medley.core :as medley]
[promesa.core :as p]
[frontend.util.keycode :as keycode]
[logseq.graph-parser.util :as gp-util]
Expand Down Expand Up @@ -256,10 +255,9 @@

(defn- another-block-with-same-id-exists?
[current-id block-id]
(and (string? block-id)
(util/uuid-string? block-id)
(not= current-id (cljs.core/uuid block-id))
(db/entity [:block/uuid (cljs.core/uuid block-id)])))
(when-let [id (and (string? block-id) (parse-uuid block-id))]
(and (not= current-id id)
(db/entity [:block/uuid id]))))

(defn- attach-page-properties-if-exists!
[block]
Expand Down Expand Up @@ -481,14 +479,9 @@
(defn- block-self-alone-when-insert?
[config uuid]
(let [current-page (state/get-current-page)
block-id (or
(and (:id config)
(util/uuid-string? (:id config))
(:id config))
(and current-page
(util/uuid-string? current-page)
current-page))]
(= uuid (and block-id (medley/uuid block-id)))))
block-id (or (some-> (:id config) parse-uuid)
(some-> current-page parse-uuid))]
(= uuid block-id)))

(defn insert-new-block-before-block-aux!
[config block _value {:keys [ok-handler]}]
Expand Down Expand Up @@ -1175,10 +1168,7 @@
[]
(if (state/editing?)
(let [page (state/get-current-page)
block-id (and
(string? page)
(util/uuid-string? page)
(medley/uuid page))]
block-id (and (string? page) (parse-uuid page))]
(when block-id
(let [block-parent (db/get-block-parent block-id)]
(if-let [id (and
Expand Down Expand Up @@ -2042,8 +2032,8 @@
(defn- last-top-level-child?
[{:keys [id]} current-node]
(when id
(when-let [entity (if (util/uuid-string? (str id))
(db/entity [:block/uuid (uuid id)])
(when-let [entity (if-let [id' (parse-uuid (str id))]
(db/entity [:block/uuid id'])
(db/entity [:block/name (util/page-name-sanity-lc id)]))]
(= (:block/uuid entity) (tree/-get-parent-id current-node)))))

Expand Down Expand Up @@ -3110,7 +3100,7 @@
(when-let [block-id (some-> (state/get-selection-blocks)
first
(dom/attr "blockid")
medley/uuid)]
uuid)]
(util/stop e)
(let [block {:block/uuid block-id}
block-id (-> (state/get-selection-blocks)
Expand Down Expand Up @@ -3222,8 +3212,7 @@
:or {collapse? false expanded? false incremental? true root-block nil}}]
(when-let [page (or (state/get-current-page)
(date/today))]
(let [block? (util/uuid-string? page)
block-id (or root-block (and block? (uuid page)))
(let [block-id (or root-block (parse-uuid page))
blocks (if block-id
(db/get-block-and-children (state/get-current-repo) block-id)
(db/get-page-blocks-no-cache page))
Expand Down Expand Up @@ -3320,7 +3309,7 @@
(->> (get-selected-blocks)
(map (fn [dom]
(-> (dom/attr dom "blockid")
medley/uuid
uuid
expand-block!)))
doall)
(and clear-selection? (clear-selection!)))
Expand Down Expand Up @@ -3353,7 +3342,7 @@
(->> (get-selected-blocks)
(map (fn [dom]
(-> (dom/attr dom "blockid")
medley/uuid
uuid
collapse-block!)))
doall)
(and clear-selection? (clear-selection!)))
Expand Down
3 changes: 1 addition & 2 deletions src/main/frontend/handler/route.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
[frontend.state :as state]
[logseq.graph-parser.text :as text]
[frontend.util :as util]
[medley.core :as medley]
[reitit.frontend.easy :as rfe]))

(defn redirect!
Expand Down Expand Up @@ -80,7 +79,7 @@
(let [name (:name path-params)
block? (util/uuid-string? name)]
(if block?
(if-let [block (db/entity [:block/uuid (medley/uuid name)])]
(if-let [block (db/entity [:block/uuid (uuid name)])]
(let [content (text/remove-level-spaces (:block/content block)
(:block/format block) (config/get-block-pattern (:block/format block)))]
(if (> (count content) 48)
Expand Down
5 changes: 2 additions & 3 deletions src/main/frontend/modules/outliner/tree.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns frontend.modules.outliner.tree
(:require [frontend.db :as db]
[frontend.util :as util]
[clojure.string :as string]
[frontend.state :as state]))

Expand Down Expand Up @@ -45,8 +44,8 @@
(defn- get-root-and-page
[repo root-id]
(if (string? root-id)
(if (util/uuid-string? root-id)
[false (db/entity repo [:block/uuid (uuid root-id)])]
(if-let [id (parse-uuid root-id)]
[false (db/entity repo [:block/uuid id])]
[true (db/entity repo [:block/name (string/lower-case root-id)])])
[false root-id]))

Expand Down
5 changes: 2 additions & 3 deletions src/main/frontend/modules/shortcut/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
[frontend.util :as util]
[goog.events :as events]
[goog.ui.KeyboardShortcutHandler.EventType :as EventType]
[lambdaisland.glogi :as log]
[medley.core :as medley])
[lambdaisland.glogi :as log])
(:import [goog.events KeyCodes KeyHandler KeyNames]
[goog.ui KeyboardShortcutHandler]))

Expand Down Expand Up @@ -117,7 +116,7 @@
dispatch-fn (get shortcut-map (keyword (.-identifier e)))]
;; trigger fn
(when dispatch-fn (dispatch-fn e))))
install-id (medley/random-uuid)
install-id (random-uuid)
data {install-id
{:group handler-id
:dispatch-fn f
Expand Down
Loading

0 comments on commit 6f68d98

Please sign in to comment.