Skip to content

Commit

Permalink
Fix reg-global-interceptor code reloading
Browse files Browse the repository at this point in the history
Fixes #655
  • Loading branch information
superstructor committed Nov 11, 2020
1 parent e713705 commit 5fa28a2
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/re_frame/settings.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,31 @@
[]
(:loaded? @store))

(defn -replace-global-interceptor
[global-interceptors interceptor]
(reduce
(fn [ret existing-interceptor]
(if (= (:id interceptor)
(:id existing-interceptor))
(do
(when interop/debug-enabled?
(when (not (loaded?))
(console :warn "re-frame: replacing duplicate global interceptor id: " (:id interceptor))))
(conj ret interceptor))
(conj ret existing-interceptor)))
interop/empty-queue
global-interceptors))

(defn reg-global-interceptor
[{:keys [id] :as interceptor}]
(swap! store update :global-interceptors
(fn [global-interceptors]
(let [ids (map :id global-interceptors)]
(when interop/debug-enabled?
(when (and (not (loaded?)) (some #{id} ids))
(console :warn "re-frame: duplicate global interceptor id: " id)))
(conj global-interceptors interceptor)))))
(if (some #{id} ids)
;; If the id already exists we replace it in-place to maintain the ordering of
;; global interceptors esp during hot-code reloading in development.
(-replace-global-interceptor global-interceptors interceptor)
(conj global-interceptors interceptor))))))

(defn get-global-interceptors
[]
Expand Down

0 comments on commit 5fa28a2

Please sign in to comment.