This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-28
Channels
- # announcements (13)
- # babashka (7)
- # beginners (35)
- # calva (23)
- # chlorine-clover (6)
- # cider (12)
- # clj-kondo (6)
- # clojure (31)
- # clojure-dev (20)
- # clojure-europe (4)
- # clojure-norway (4)
- # clojure-uk (1)
- # clojurescript (62)
- # fulcro (6)
- # google-cloud (1)
- # lsp (2)
- # malli (13)
- # meander (6)
- # music (1)
- # off-topic (19)
- # practicalli (2)
- # re-frame (7)
- # reagent (25)
- # reitit (5)
- # releases (1)
- # reveal (3)
- # shadow-cljs (90)
- # tools-build (18)
- # tools-deps (1)
given that :before
functions of the interceptor chain are run in declaration order (for example, [inter1 inter2 inter3]
will be run as (:before inter1)
, (:before inter2)
, and then (:before inter3)
), and then the :after
functions are run in reverse order (so (:after inter3)
, (:after inter2)
, and then (`:after inter1)`), in the TodoMVC example, the todo-interceptors
seem to be declared in the wrong order (see here: https://github.com/day8/re-frame/blob/7199496997cfb226311444f4402d1bda5798af60/examples/todomvc/src/todomvc/events.cljs#L78-L80)
it’s defined as (def todo-interceptors [check-spec-interceptor (path :todos) ->local-store])
, where check-spec-interceptor
and ->local-storage
are after
interceptors. if path
has both before
and after
functions, shouldn’t it come last so that the updating happens before we store anything or check the spec?
otherwise, the db
object returned from any reg-event
will be the new value of the defined path
interceptor, not the full db, and thus the wrong thing will be saved to local storage
1. check-spec-interceptor
does nothing on the :before
step
2. (path :todos)
replaces the :db
coeffect on the :before
step
3. ->local-store
does nothing on the :before
step
4. The event handler is called with the replaced :db
and returns some value
5. ->local-store
assumes that value to be the todos and stores them in the local store on the :after
step. Since it's created with after
, it returns the original context unchanged (i.e. just as the :before
step of (path :todos)
changed it)
6. (path :todos)
restores the original state of :db
while also replacing the :todos
key with the value returned from the event handler on the :after
step
7. check-spec-interceptor
checks the whole app-db on the :after
step
All seems to be correct.
thanks for the detailed breakdown. I think I have misunderstood the purpose of ->local-storage
but you cleared it up