refactor: replace rum/use-memo

This commit is contained in:
rcmerci
2025-01-07 16:08:59 +08:00
parent fd0bc933e9
commit 5d8f176537
3 changed files with 5 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
[clojure.string :as string]
[frontend.context.i18n :refer [t]]
[frontend.handler.notification :as notification]
[frontend.hooks :as hooks]
[frontend.modules.shortcut.config :as shortcut-config]
[frontend.modules.shortcut.core :as shortcut]
[frontend.modules.shortcut.data-helper :as dh]
@@ -212,7 +213,7 @@
[current-binding set-current-binding!] (rum/use-state (or user-binding binding))
[key-conflicts set-key-conflicts!] (rum/use-state nil)
handler-id (rum/use-memo #(dh/get-group k))
handler-id (hooks/use-memo #(dh/get-group k))
dirty? (not= (or user-binding binding) current-binding)
keypressed? (not= "" keystroke)
save-keystroke-fn!

View File

@@ -9,6 +9,7 @@
[frontend.extensions.lightbox :as lightbox]
[frontend.extensions.video.youtube :as youtube]
[frontend.handler.notification :as notification]
[frontend.hooks :as hooks]
[frontend.modules.shortcut.config :as shortcut-config]
[frontend.rum :as r]
[frontend.search :as search]
@@ -532,7 +533,7 @@
(set-active-pane-state! next-state))
[scrolled?, set-scrolled!] (rum/use-state false)
on-scroll (rum/use-memo #(util/debounce (fn [^js e] (set-scrolled! (not (< (.. e -target -scrollTop) 10)))) 100) [])]
on-scroll (hooks/use-memo #(util/debounce 100 (fn [^js e] (set-scrolled! (not (< (.. e -target -scrollTop) 10))))))]
;; load handbooks
(rum/use-effect!

View File

@@ -5,7 +5,7 @@
[rum.core :as rum]))
(defn- safe-dep
"js/React use `js/Object.is` to compare dep-value and its previous value.
"js/React uses `js/Object.is` to compare dep-value and its previous value.
Some cljs built-in types(keyword, symbol, uuid) would not be identical, even they are value-equal"
[dep]
(if (contains? #{"string" "number" "boolean" "null"} (goog/typeOf dep))