Ver código fonte

enhance: update sub-editing?

rcmerci 8 meses atrás
pai
commit
c93376b98b
2 arquivos alterados com 20 adições e 18 exclusões
  1. 10 10
      src/main/frontend/hooks.cljs
  2. 10 8
      src/main/frontend/state.cljs

+ 10 - 10
src/main/frontend/hooks.cljs

@@ -66,13 +66,13 @@
 
 
 (defn use-flow-state
 (defn use-flow-state
   "Return values from `flow`, default init-value is nil"
   "Return values from `flow`, default init-value is nil"
-  [flow {:keys [init-value value-f]
-         :or {value-f identity}}]
-  (let [[value set-value!] (use-state init-value)]
-    (use-effect!
-     #(c.m/run-task*
-       (m/reduce
-        (constantly nil)
-        (m/ap (set-value! (value-f (m/?> flow))))))
-     [])
-    value))
+  ([flow] (use-flow-state nil flow))
+  ([init-value flow]
+   (let [[value set-value!] (use-state init-value)]
+     (use-effect!
+      #(c.m/run-task*
+        (m/reduce
+         (constantly nil)
+         (m/ap (set-value! (m/?> flow)))))
+      [])
+     value)))

+ 10 - 8
src/main/frontend/state.cljs

@@ -689,18 +689,18 @@ Similar to re-frame subscriptions"
   [container-block]
   [container-block]
   (reset! (:editor/editing? @state) {container-block true}))
   (reset! (:editor/editing? @state) {container-block true}))
 
 
-(defn- sub-flow
-  [flow sub-f]
-  (m/eduction (map sub-f) (dedupe) flow))
-
 (def ^:private editing-flow
 (def ^:private editing-flow
   (m/watch (:editor/editing? @state)))
   (m/watch (:editor/editing? @state)))
 
 
 (defn sub-editing?
 (defn sub-editing?
   [container-block]
   [container-block]
-  (hooks/use-flow-state
-   (sub-flow editing-flow (fn [s] (get s 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))))
 
 
 (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"
@@ -2316,7 +2316,9 @@ Similar to re-frame subscriptions"
 (defn async-query-k-flow
 (defn async-query-k-flow
   [k]
   [k]
   (let [k* (str k)]
   (let [k* (str k)]
-    (sub-flow async-query-loading-flow (fn [s] (contains? s k*)))))
+    (m/eduction
+     (map #(contains? % k*)) (dedupe)
+     async-query-loading-flow)))
 
 
 (defn clear-async-query-state!
 (defn clear-async-query-state!
   []
   []