This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-28
Channels
- # aleph (4)
- # announcements (5)
- # babashka (28)
- # babashka-sci-dev (13)
- # beginners (63)
- # calva (76)
- # cider (113)
- # clara (7)
- # clj-kondo (42)
- # cljdoc (1)
- # clojure (170)
- # clojure-europe (20)
- # clojure-nl (17)
- # clojure-norway (3)
- # clojure-spec (12)
- # clojure-sweden (1)
- # clojure-uk (6)
- # clojurescript (55)
- # clojureverse-ops (1)
- # consulting (1)
- # core-async (9)
- # cursive (16)
- # data-science (1)
- # datascript (8)
- # datomic (27)
- # emacs (14)
- # events (1)
- # fulcro (10)
- # graphql (9)
- # gratitude (1)
- # jobs (6)
- # jobs-discuss (5)
- # leiningen (10)
- # lsp (35)
- # missionary (4)
- # nextjournal (9)
- # off-topic (46)
- # pathom (15)
- # pedestal (5)
- # polylith (37)
- # portal (15)
- # re-frame (22)
- # reagent (4)
- # reitit (5)
- # reveal (18)
- # shadow-cljs (20)
- # tools-deps (7)
- # xtdb (10)
Reagent's reagent.core/children
does not support functional component now. As reagent.core/current-component
returns mocking object, I write a helper function like below:
(defn get-children [^js this]
(if (.-props this)
(reagent.core/children this)
(when-some [v (.-argv this)]
(reagent.impl.component/extract-children v))))
Can I safely use it for functional component? for example
(defmacro nest-children []
`(some->> (reagent.core/current-component)
(get-children)
(into [:<>])))
(defn fn-comp [{:keys [prop1]}]
[:div
(str "Prop1 is " prop1)
(nest-children)])
(defn demo []
[:f> fn-comp
{:prop1 "hello"}
[:span "world"]
[:span "foo"]
[:span "bar"]])
It seems work for simple tests.You might get better answers in #reagent But also, I wouldn't use a macro for that, it's an unnecessary complication.
Thanks. I want to avoid macro, too. however, nest-children
doesn't work when I turn it to a function.
sorry for asking so much but why does my degree tag get not updated when I choose a output type. Code so far : https://github.com/RoelofWobben/clojure-temp-converter
oke this seems to work
(defn update-output [_]
(gdom/setTextContent degree get-output-temp))
but now the new degree is added to degree here instead of changing thingsNever mind , got it working with
(defn update-output [_]
(gdom/setTextContent degree (get-output-temp)))
`
as always ... verify what you think you are working with. hint (input-target)
is incorrect
Hello, clojurescript expects me to quote dest-ns
in (ns publics dest-ns)
line 3, which is kind of complicated to do:
(defmacro export-library-cljc! [dest-ns exclude-symbols]
`(do
[email protected](for [[intern-name] (ns-publics dest-ns)]
(when-not (contains? exclude-symbols (symbol (str intern-name)))
`(do
~(when (contains? (ns-interns 'clojure.core) (symbol (str intern-name)))
`(ns-unmap *ns* (symbol ~(str intern-name))))
~`(defalias ~(symbol (str dest-ns "/" intern-name))))))))
The macro is working perfectly in clojure, can someone explain?Clojure 1.10.0
user=> (doc ns-publics)
-------------------------
clojure.core/ns-publics
([ns])
Returns a map of the public intern mappings for the namespace.
but
ClojureScript 1.10.879
cljs.user=> (doc ns-publics)
-------------------------
cljs.core/ns-publics
([quoted-ns])
Macro
Returns a map of the public intern mappings for the namespace.
In CLJ, it's a function. In CLJS, it's a macro. Why exactly this difference exists, I don't know. Probably due to how some things in CLJS simply don't exist in run time, like vars.Oh, I see. Which means it'll be already quoted in clojure but not in clojurescript.
Thank you
Your conclusion is the other way around - it will be quoted in CLJS since it's a macro.
Fortunately for your implementation, the CLJ version of ns-publics
also accepts a symbol. So you can just use a symbol there at all times. Might still be tricky given that one is an fn and the other is a macro.
Yeah, quite tricky
again a question about react keys I see now this error :
template.cljs:413 Warning: Every element in a seq should have a unique :key: ([learn_cljs.weather.temperature {:label "Today", :value nil}] [learn_cljs.weather.temperature {:label "Tomorrow", :value nil}])
(in )
Can I solve this with this :
^{key 'today'}{:label "Today", :value nil}]
if not, please give me the right answer . This is bugging me for several daysHave you gone through the links I provided before? One of them was with an example from the Reagent's website.
The warning clearly mentions
([learn_cljs.weather.temperature {:label "Today", :value nil}]
[learn_cljs.weather.temperature {:label "Tomorrow", :value nil}])
It talks about every element in the seq, and an element of that seq would be each Hiccup vector.
I did it here
(defn title []
[:h1 (:title @app-state)])
(defn temperature [temp]
[:div {:class "temperature"}
[:div {:class "value"}
(:value temp)]
[:h2 (:label temp)]])
(defn postal-code []
[:div {:class "postal-code"}
[:h3 "Enter your postal code"]
[:input {:type "text"
:placeholder "Postal Code"
:value (:postal-code @app-state)
:on-change #(swap! app-state assoc :postal-code (-> % .-target .-value))}]
[:button {:on-click get-coordinates} "Go" ]])
(defn app []
[:div {:class "app"}
[title]
[:div {:class "temperatures"}
(for [temp (vals (:temperatures @app-state))]
^ {key [temperature temp]}[temperature temp])]
[postal-code]])
the part that the error message is talking about looks like this
(defonce app-state (r/atom {:title "WhichWeather"
:latitude 0
:longitude 0
:postal-code ""
:temperatures {:today {:label "Today"
:value nil}
:tomorrow {:label "Tomorrow"
:value nil}}}))
In your code, that seq above is generated with this code:
(for [temp (vals (:temperatures @app-state))]
[temperature temp])
A key in React represents an identifier for an element within its parent element - unique within the scope of that parent. It needs to remain stable, it can't be just the index.
In your case, such a stable identifier seems to simply be the key in the :temperatures
map.
Here's a solution for your particular case:
(for [[temp-id temp] (:temperatures @app-state)]
^{:key temp-id}
[temperature temp])
But given that: • Maps are inherently unordered • You just have two items in that map here's how I'd rewrite it:
(let [{:keys [today tomorrow]} (:temperatures @app-state)]
[temperature today]
[temperature tomorrow])
The code doesn't even need :key
anymore.> the part that the error message is talking about looks like this
The error you posted in the main channel clearly doesn't talk about that defonce
at all. Why do you think the definition of your app-state
is relevant here?
That's just the value of temp
. It doesn't talk about your actual code, it only talks about the value it receives. It's a run-time warning, not a compile-time one - it doesn't check your code, it only checks the values.
(defn app []
[:div {:class "app"}
[title]
[:div {:class "temperatures"}
(for [temp (vals (:temperatures @app-state))]
^ {key temp}[temperature temp])]
[postal-code]])
Use my code. Confirm that it results on no warnings. Then go through the React documentation on keys while keeping my code in mind, along with the fact that ^{:key x}
in front of a Hiccup vector results in assigning a React key to the resulting React element.
BTW that ^{...}
construct just assigns metadata. So ^{...} [...]
is sugar for (with-meta [...] {...})
. And Reagent uses :key
metadata to assign keys to React elements.
so this instead of the for loop
(let [{:keys [today tomorrow]} (:temperatures @app-state)]
[temperature today]
[temperature tomorrow])
hmm, this breaks the layout
(defn app []
[:div {:class "app"}
[title]
[:div {:class "temperatures"}
(let [{:keys [today tomorrow]} (:temperatures @app-state)]
[temperature today]
[temperature tomorrow])]
[postal-code]])
No, I meant the loop, given that it's the only one of the two code examples I provided that still needs the :key
.
The layout breakage is surprising, given that the resulting markup should be exactly the same.
The ClojureScript website has a selection of materials: https://clojurescript.org/community/resources
I do not see why mu right blue area is not updated here : https://github.com/RoelofWobben/clojure-temp-converter