Fork me on GitHub
#re-frame
<
2021-12-28
>
Noah Bogart14:12:32

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)

Noah Bogart14:12:57

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?

Noah Bogart14:12:20

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

p-himik14:12:14

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.

Noah Bogart14:12:12

thanks for the detailed breakdown. I think I have misunderstood the purpose of ->local-storage but you cleared it up

👍 1
roelof19:12:57

Anyone a hint how to solve this warning

p-himik19:12:26

That's a question for #calva, not #re-frame