Fork me on GitHub
#re-frame
<
2022-03-06
>
nikolavojicic16:03:47

Can I execute events from interceptors? E.g. I want to implement loading spinner with :before (turn it on) and :after (turn it off) interceptor.

p-himik16:03:29

The whole interceptor chain is synchronous - you will not see any change in the UI even if you dispatch from an interceptor.

👍 1
p-himik16:03:40

This is probably the most useful document in this case: https://github.com/day8/re-frame/blob/master/docs/Solve-the-CPU-hog-problem.md

👍 1
nikolavojicic20:03:53

I'm trying :http-xhrio with re-frame... It's simple GET request with no params and returns JSON response:

{:http-xhrio {:method          :get
              :uri             ""
              :headers         {"Content-Type" "application/json"}
              :response-format (ajax/json-request-format {:keywords? true})
              :on-request      [,,,]
              :on-success      [,,,]
              :on-failure      [,,,]}}
This request always fails because of parsing, with response:
{:response nil
 :last-method "GET"
 :original-text "{\"version\":\"2021-11-29-SNAPSHOT\"}"
 :last-error ""
 :failure :parse
 :status-text "Cannot read properties of null (reading 'cljs$core$IFn$_invoke$arity$1')  Format should have been "
 :status 200
 :uri ""
 :debug-message "No Error"
 :last-error-code 0}
Not sure how to fix this problem, response from the backend seems fine...

nikolavojicic21:03:48

E.g. this works

(js->clj (.parse js/JSON "{\"version\":\"2021-11-29-SNAPSHOT\"}")
         :keywordize-keys true)
;=> {:version "2021-11-29-SNAPSHOT"}

p-himik21:03:29

Take a careful look at this line, word by word:

:response-format (ajax/json-request-format {:keywords? true})

❤️ 1
nikolavojicic21:03:58

Thanks, again 🙂

👍 1