Skip to content

Commit 30e029a

Browse files
committed
Calculate flow interceptors earlier than user interceptors
1 parent 5bd82b3 commit 30e029a

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

docs/releases/2024.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66

77
> The re-frame [Clojars page](https://clojars.org/re-frame/) contains dependency coordinates for Maven/deps/Lein.
88
9+
## 1.4.4 (2024-06-24)
10+
11+
#### Changed
12+
13+
- Changed flows to calculate the new app-db earlier in the chain.
14+
- Benefit: user-defined interceptors can access post-flow app-db value.
15+
- Drawback: they can't access the value of app-db directly resulting from the event handler.
16+
- Drawback: they can't access flow-related effects like `:reg-flow`.
17+
18+
- Added a :re-frame/pre-flow-db key to the context
19+
- This way, user-defined interceptors can still access the app-db value resulting directly from the event handler.
20+
921
## 1.4.3 (2024-01-25)
1022

1123
#### Fixed

src/re_frame/alpha.cljc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,10 @@
423423
([id interceptors handler]
424424
(events/register id [cofx/inject-db
425425
fx/do-fx
426-
flow/interceptor
427-
flow/do-fx
428426
std-interceptors/inject-global-interceptors
429427
interceptors
428+
flow/interceptor
429+
flow/do-fx
430430
(db-handler->interceptor handler)])))
431431

432432
(defn reg-event-fx
@@ -463,10 +463,10 @@
463463
([id interceptors handler]
464464
(events/register id [cofx/inject-db
465465
fx/do-fx
466-
flow/interceptor
467-
flow/do-fx
468466
std-interceptors/inject-global-interceptors
469467
interceptors
468+
flow/interceptor
469+
flow/do-fx
470470
(fx-handler->interceptor handler)])))
471471

472472
(defn reg-event-ctx
@@ -500,10 +500,10 @@
500500
([id interceptors handler]
501501
(events/register id [cofx/inject-db
502502
fx/do-fx
503-
flow/interceptor
504-
flow/do-fx
505503
std-interceptors/inject-global-interceptors
506504
interceptors
505+
flow/interceptor
506+
flow/do-fx
507507
(ctx-handler->interceptor handler)])))
508508

509509
(defn clear-event

src/re_frame/flow/alpha.cljc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@
165165

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

0 commit comments

Comments
 (0)