Skip to content

Commit

Permalink
Calculate flow interceptors earlier than user interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
kimo-k committed Jun 26, 2024
1 parent 5bd82b3 commit 30e029a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
12 changes: 12 additions & 0 deletions docs/releases/2024.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@

> The re-frame [Clojars page](https://clojars.org/re-frame/) contains dependency coordinates for Maven/deps/Lein.
## 1.4.4 (2024-06-24)

#### Changed

- Changed flows to calculate the new app-db earlier in the chain.
- Benefit: user-defined interceptors can access post-flow app-db value.
- Drawback: they can't access the value of app-db directly resulting from the event handler.
- Drawback: they can't access flow-related effects like `:reg-flow`.

- Added a :re-frame/pre-flow-db key to the context
- This way, user-defined interceptors can still access the app-db value resulting directly from the event handler.

## 1.4.3 (2024-01-25)

#### Fixed
Expand Down
12 changes: 6 additions & 6 deletions src/re_frame/alpha.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@
([id interceptors handler]
(events/register id [cofx/inject-db
fx/do-fx
flow/interceptor
flow/do-fx
std-interceptors/inject-global-interceptors
interceptors
flow/interceptor
flow/do-fx
(db-handler->interceptor handler)])))

(defn reg-event-fx
Expand Down Expand Up @@ -463,10 +463,10 @@
([id interceptors handler]
(events/register id [cofx/inject-db
fx/do-fx
flow/interceptor
flow/do-fx
std-interceptors/inject-global-interceptors
interceptors
flow/interceptor
flow/do-fx
(fx-handler->interceptor handler)])))

(defn reg-event-ctx
Expand Down Expand Up @@ -500,10 +500,10 @@
([id interceptors handler]
(events/register id [cofx/inject-db
fx/do-fx
flow/interceptor
flow/do-fx
std-interceptors/inject-global-interceptors
interceptors
flow/interceptor
flow/do-fx
(ctx-handler->interceptor handler)])))

(defn clear-event
Expand Down
12 changes: 7 additions & 5 deletions src/re_frame/flow/alpha.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@

(def interceptor
(->interceptor
{:id :flow
:after (fn [ctx]
(let [all-flows (with-cleared @flows)]
(swap! flows vary-meta dissoc ::cleared)
(reduce run ctx ((memoize topsort) all-flows))))}))
{:id :flow
:after (comp (fn [ctx]
(let [all-flows (with-cleared @flows)]
(swap! flows vary-meta dissoc ::cleared)
(reduce run ctx ((memoize topsort) all-flows))))
(fn [{{:keys [db]} :effects :as ctx}]
(assoc ctx :re-frame/pre-flow-db db)))}))

0 comments on commit 30e029a

Please sign in to comment.