Skip to content

Commit

Permalink
default and override of global-interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
mccraigmccraig committed May 22, 2023
1 parent e841e64 commit bd77075
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/a_frame/events.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@
(register-pure id handler)
(register
id
[::std-interceptors/unhandled-error-report
:a-frame.fx/do-fx
interceptors
[interceptors
(std-interceptors/fx-handler->interceptor id)])))

(defn reg-event-ctx
Expand All @@ -74,9 +72,7 @@
(register-pure id handler)
(register
id
[::std-interceptors/unhandled-error-report
:a-frame.fx/do-fx
interceptors
[interceptors
(std-interceptors/ctx-handler->interceptor id)])))

(defn clear-event
Expand Down
9 changes: 7 additions & 2 deletions src/a_frame/router.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[promisespromises.stream.transport :as stream.transport]
[a-frame.schema :as schema]
[a-frame.events :as events]
[a-frame.std-interceptors :as std-interceptors]
[taoensso.timbre :refer [debug info warn error]]))

;; use a record so we can
Expand All @@ -26,17 +27,21 @@

(mx/defn create-router :- schema/Router
[app
{_global-interceptors schema/a-frame-router-global-interceptors
{global-interceptors schema/a-frame-router-global-interceptors
#?@(:clj [executor schema/a-frame-router-executor])
buffer-size schema/a-frame-router-buffer-size
:or {buffer-size 100}
:as opts}]

(merge
(->AFrameRouter)
opts,
opts
{schema/a-frame-app-ctx app

schema/a-frame-router-global-interceptors
(or global-interceptors
std-interceptors/default-global-interceptors)

schema/a-frame-router-event-stream
#?(:clj (stream/stream buffer-size nil executor)
:cljs (stream/stream buffer-size nil))}))
Expand Down
14 changes: 14 additions & 0 deletions src/a_frame/std_interceptors.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,17 @@
[log-context-data-spec]
{::interceptor-chain/key ::set-log-context
::log-context-data log-context-data-spec})


(def unhandled-error-global-interceptors
"very minimal set of global interceptors which only handles otherwise
unhandled errors - use as global-interceptors when you don't want
any fx processed"
[::unhandled-error-report])

(def default-global-interceptors
"the default set of global-interceptors when no others are specified
at router construction -
handles unhandled errors and does all fx"
[::unhandled-error-report
:a-frame.fx/do-fx])
4 changes: 3 additions & 1 deletion test/a_frame/fx/dispatch_fx_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
(deftest dispatch-fx-test
(testing "dispatches without transitive coeffects"
(let [{event-s schema/a-frame-router-event-stream
:as router} (router/create-router test-app-ctx {})
:as router} (router/create-router
test-app-ctx
{})
out-a (atom [])

_ (events/reg-event-fx
Expand Down

0 comments on commit bd77075

Please sign in to comment.