Ver código fonte

enhance(rtc): debounce trigger-start-rtc-flow to dedupe

rcmerci 7 meses atrás
pai
commit
d83ced97ab

+ 7 - 8
src/main/frontend/common/missionary.cljs

@@ -71,14 +71,13 @@
     (let [v (m/?> par flow)]
       (m/? (f v)))))
 
-(comment
-  (defn debounce
-    [duration-ms flow]
-    (m/ap
-      (let [x (m/?< flow)]
-        (try (m/? (m/sleep duration-ms x))
-             (catch Cancelled _
-               (m/amb)))))))
+(defn debounce
+  [duration-ms flow]
+  (m/ap
+    (let [x (m/?< flow)]
+      (try (m/? (m/sleep duration-ms x))
+           (catch Cancelled _
+             (m/amb))))))
 
 (defn throttle
   [dur-ms >in]

+ 3 - 3
src/main/frontend/handler/db_based/rtc_background_tasks.cljs

@@ -66,6 +66,6 @@
  (m/reduce
   (constantly nil)
   (m/ap
-    (let [start-reason (m/?> rtc-flows/trigger-start-rtc-flow)]
-      (log/info :try-to-start-rtc (first start-reason))
-      (c.m/<? (rtc-handler/<rtc-start! (state/get-current-repo)))))))
+    (let [[start-reason repo] (m/?> rtc-flows/trigger-start-rtc-flow)]
+      (log/info :try-to-start-rtc [start-reason repo])
+      (c.m/<? (rtc-handler/<rtc-start! (or repo (state/get-current-repo))))))))

+ 12 - 10
src/main/frontend/handler/db_based/rtc_flows.cljs

@@ -90,13 +90,15 @@ conditions:
   (reset! *rtc-start-trigger repo))
 
 (def trigger-start-rtc-flow
-  (c.m/mix
-   (m/eduction
-    (keep (fn [user] (when (:email user) [:login user])))
-    flows/current-login-user-flow)
-   (m/eduction
-    (keep (fn [repo] (when repo [:graph-switch repo])))
-    flows/current-repo-flow)
-   (m/eduction
-    (keep (fn [repo] (when repo [:trigger-rtc repo])))
-    (m/watch *rtc-start-trigger))))
+  (->>
+   [(m/eduction
+     (keep (fn [user] (when (:email user) [:login])))
+     flows/current-login-user-flow)
+    (m/eduction
+     (keep (fn [repo] (when repo [:graph-switch repo])))
+     flows/current-repo-flow)
+    (m/eduction
+     (keep (fn [repo] (when repo [:trigger-rtc repo])))
+     (m/watch *rtc-start-trigger))]
+   (apply c.m/mix)
+   (c.m/debounce 200)))