This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-07
Channels
- # announcements (2)
- # babashka (38)
- # beginners (38)
- # calva (4)
- # cider (1)
- # clj-kondo (43)
- # clojure (50)
- # clojure-dev (39)
- # clojure-europe (4)
- # clojure-spec (4)
- # clojure-uk (2)
- # conjure (6)
- # core-async (5)
- # core-typed (3)
- # data-science (2)
- # datomic (6)
- # depstar (4)
- # emacs (1)
- # events (2)
- # fulcro (4)
- # jobs-discuss (4)
- # luminus (1)
- # off-topic (5)
- # re-frame (14)
- # shadow-cljs (8)
- # sql (8)
- # tools-deps (22)
@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)))
Nice! One issue though - your code removes and appends the interceptor. It doesn't preserve the order.
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)
(do
(rf/clear-global-interceptor)
(doseq [i existing-interceptors]
(rf/reg-global-interceptor
(if (= (:id i) (:id interceptor))
interceptor
i))))
(rf/reg-global-interceptor interceptor))))
rf/reg-global-interceptor))
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.
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.
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.
You do it the same way as you do with JS. Just use ClojureScript's JS interop https://cljs.info/cheatsheet/
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. https://github.com/day8/re-frame-http-fx). The process of creating formdata and passing it onto the body of the POST is the same though.