Browse Source

fix: clear interval to avoid multiple intervals on dev mode

Code modifications will trigger :will-mount again which results in
multiple intervals.
Tienson Qin 1 year ago
parent
commit
efc083afab
1 changed files with 6 additions and 2 deletions
  1. 6 2
      src/main/frontend/components/header.cljs

+ 6 - 2
src/main/frontend/components/header.cljs

@@ -69,8 +69,12 @@
                               (if (= :open (:rtc-state @(:rtc/state @state/state)))
                                 (rtc-handler/<rtc-get-users-info)
                                 (when @*interval (js/clearInterval @*interval))))
-                            5000)))
-                 state)}
+                            5000))
+                   (assoc state ::interval *interval)))
+   :will-unmount (fn [state]
+                   (when-let [interval @(::interval state)]
+                     (js/clearInterval interval))
+                   state)}
   []
   (let [rtc-graph-id (ldb/get-graph-rtc-uuid (db/get-db))
         online-users (->> (get (state/sub :rtc/users-info) (state/get-current-repo))