Lucy Wang 2020-11-07T02:21:27.290400Z

@p-himik I just found that yesterday and wrote a custom version of reg-global-interceptor to work around that

(ns demo
  (:require [re-frame.core :as rf]
            [re-frame.settings :as rf.settings]))

(defn safe-reg-global-interceptor
  "rf/reg-global-interceptor appends instead of replacing. This wrapper
  function ensures replacing the existing global interceptor with the
  same id, if any."
  [{:keys [id] :as interceptor}]
  (let [global-interceptors (rf.settings/get-global-interceptors)]
    (->> global-interceptors
         (remove #(= (:id %) id))
         ;; global-interceptors is a queue
         (into (empty global-interceptors))
         (swap! rf.settings/store assoc :global-interceptors))
    (rf/reg-global-interceptor interceptor)))

p-himik 2020-11-10T00:30:11.299500Z


p-himik 2020-11-11T10:52:05.300100Z

And it was fixed rather quickly. :)

p-himik 2020-11-07T06:12:09.290600Z

Nice! One issue though - your code removes and appends the interceptor. It doesn't preserve the order.

p-himik 2020-11-07T06:12:44.290800Z

Here's what I've come up with (didn't test it that well but seems to work just fine):

(def reg-global-interceptor
  (if re-frame.interop/debug-enabled?
    (fn [interceptor]
      (let [existing-interceptors (re-frame.settings/get-global-interceptors)]
        (if (some #(= (:id %) (:id interceptor)) existing-interceptors)
            (doseq [i existing-interceptors]
                (if (= (:id i) (:id interceptor))
          (rf/reg-global-interceptor interceptor))))

bastilla 2020-11-07T19:38:52.292700Z

Hi there. Can anyone point my to a blog entry / article / whatever with code snippets on how to upload a file to a server? Would greatly appreciate it. (As so often I fail utterly in finding actual / official docs on clojure libs.

bastilla 2020-11-08T09:44:39.293400Z

Hey @p-himik Thanks for responding! Well, yes and no. I know but not from the top of my head. I need to look up the details. I am pretty sure I could implement it in plain JS in like 15 minutes. And I am sure could do it in Python in like 15 minutes - and I don't know Python - since it's easy to find the docs.

uosl 2020-11-08T10:47:11.293700Z

You do it the same way as you do with JS. Just use ClojureScript's JS interop

uosl 2020-11-08T10:52:59.294Z

Only difference is with re-frame, you'd probably have the fetch function (i.e. the HTTP POST) as an effect called from an event handler (ex. The process of creating formdata and passing it onto the body of the POST is the same though.

uosl 2020-11-08T11:10:17.294300Z

And yes, you won't be able to search for specific problems and find snippets ready for copy-and-paste with Clojure, as you can with the mainstream languages. You're kind of on your own to put the pieces together, but don't worry as this is a skill you'll get better at with practice!

bastilla 2020-11-08T12:36:53.294500Z

thanks so far guys. I'll post my solution.

p-himik 2020-11-08T13:51:38.294800Z

I use re-frame-http-fx and in the :body parameter I put a manually created js/FormData.

bastilla 2020-11-07T19:40:53.292900Z

What I found so far on re-frame is not going into details. Just superficial stuff with lots of text but little of documentation and actual code snippets.

p-himik 2020-11-07T20:41:00.293200Z

I assume you mean HTTP POST. Do you know how to upload files using vanilla JS?