Browse Source

enhance: sub-editing? add use-memo, use-callback

rcmerci 9 tháng trước cách đây
mục cha
commit
17ef19325a
1 tập tin đã thay đổi với 12 bổ sung7 xóa
  1. 12 7
      src/main/frontend/state.cljs

+ 12 - 7
src/main/frontend/state.cljs

@@ -694,13 +694,18 @@ Similar to re-frame subscriptions"
 
 
 (defn sub-editing?
 (defn sub-editing?
   [container-block]
   [container-block]
-  (let [checkf (fn [s] (boolean (get s container-block)))
-        init-value (checkf @(:editor/editing? @state))]
-    (hooks/use-flow-state
-     init-value
-     (m/eduction
-      (map checkf) (drop-while #(= % init-value)) (dedupe)
-      editing-flow))))
+  (let [checkf (hooks/use-callback
+                (fn [s] (boolean (get s container-block)))
+                [container-block])
+        init-value (checkf @(:editor/editing? @state))
+        flow (hooks/use-memo
+              #(m/eduction
+                (map checkf)
+                (dedupe)
+                (drop-while (fn [x] (identical? x init-value)))
+                editing-flow)
+              [init-value])]
+    (hooks/use-flow-state init-value flow)))
 
 
 (defn sub-config
 (defn sub-config
   "Sub equivalent to get-config which should handle all sub user-config access"
   "Sub equivalent to get-config which should handle all sub user-config access"