This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-06
Channels
- # announcements (3)
- # babashka (1)
- # beginners (26)
- # calva (1)
- # cider (17)
- # clj-commons (16)
- # clj-kondo (11)
- # clojure (21)
- # clojure-europe (9)
- # clojure-norway (1)
- # clojure-portugal (2)
- # clojure-spec (8)
- # clojure-uk (4)
- # clojurescript (35)
- # datomic (5)
- # emacs (9)
- # figwheel-main (15)
- # fulcro (26)
- # honeysql (1)
- # lsp (5)
- # off-topic (2)
- # polylith (1)
- # rdf (6)
- # re-frame (4)
- # reagent (15)
- # reitit (9)
- # releases (2)
- # shadow-cljs (4)
- # sql (25)
- # squint (2)
- # xtdb (7)
Which ring middleware keywordizes the keys of :headers
in the request map?
In one server that uses ring.middleware.defaults/api-defaults
they are keywords but I can't pinpoint where it happens
are you able to reproduce it locally?
(def wrapped (mid/wrap-defaults #'simple-handler mid/api-defaults))
(def server (jetty/run-jetty simple-handler
{:port 3000
:join? false}))
and when i curl "localhost:3000/foo?foo=bar"
I'm seeing the headers and params look like:
{:headers
{"accept" "*/*", "user-agent" "curl/7.79.1", "host" "localhost:3000"},
:params {:foo "bar"}}
the params are keywordized but the headers remain as stringsIf you are seeing headers keywordized, look for any uses of ring.middleware.keyword-params
in your project and see if you are pointing keyify-params
at :headers
somewhere
Yeah I tried that... I think the culprit will be aleph in the server where it's keywords. It seems that the header map reacts to both keys and strings? Knowing it wasn't the middleware I'll just adjust to using strings
Yeah now I'm super confused. The server where the headers are keywords (and upper-case keywords at that!) I don't see any middleware or manual setting doing it...
check=> (get-in req [:headers "HOST"])
"localhost:3000"
check=> (get-in req [:headers :HOST])
"localhost:3000"
check=> (get-in req [:headers :HoSt])
"localhost:3000"
the headermap doesn't have those keys, its just the way it looks it up it calls (str/lower-case (name k))
on the lookup value
Read it carefully because it has an “added” map that can lookup as normal that can shadow the actual header map. Not sure how that’s used in aleph though
using reagent, i have a leaf component that takes a single string ratom and reset!
the ratom based on user input. If i want to use the leaf component in a top component with a list of string ratom input, how do deref the top ratom and pass it down to the leaf component, so that the leaf component mutation of the ratom is reflected to the top component? code snippet in thread:
(defn text
[ratom]
[:input {:type "text"
:default-value @ratom
:on-change #(reset! ratom (.. % -target -value ))}])
(defn lister [ratom]
[:ul
(for [item @ratom]
^{:key item} [:li [text (r/atom item)]])]) ;; <-- this won't update
(defcard-rg text-card
(fn [ratom _ ] [text ratom])
(r/atom "edit me")
{:inspect-data true}
)
(defcard-rg lister-card
(fn [ratom _] [lister ratom])
(r/atom ["edit1" "edit2"])
{:inspect-data true})
I think you need to pass a cursor down
So don’t iterate on the dereferenced atom at the top level, iterate on (range (count @ratom)) and pass cursors for each index into each text component
thanks, cursor
works, even wrap
works. But i found them too heavy for changes the structure of one ratom to another, e.g. build atom of vector to atom of map and pass to child component. maybe that’s why most reagent tutorials i read use top level “global” state rather than passing triaged down atom-ish state
to child components.
Writing some code where a List is an appropriate data structure. Instead of (list foo)
, I am using (~foo)` as makeshift "list literal". Are there any surprises or gotchas to doing this?
(let [foo :foo]
`(~foo)) ; => (:foo)
Why not just '(foo)
? '(1 2 3)
is the standard list literal https://www.clojure.org/guides/learn/syntax#_literal_collections
Ah yeah.
I can't think of a surprise or gotcha, but if I were reviewing the code I'd suggest just using (list :foo)
as it's far more obvious what is going on.
The list function returns a list which is like a seq with extra stuff, syntax quote returns a seq