This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-04
Channels
- # announcements (5)
- # aws (12)
- # beginners (76)
- # boot (29)
- # cider (24)
- # circleci (9)
- # clojure (64)
- # clojure-dev (27)
- # clojure-europe (3)
- # clojure-houston (1)
- # clojure-italy (33)
- # clojure-nl (19)
- # clojure-poland (1)
- # clojure-spec (6)
- # clojure-uk (20)
- # clojurescript (103)
- # clojutre (1)
- # code-reviews (60)
- # cursive (76)
- # data-science (20)
- # datomic (20)
- # duct (58)
- # figwheel-main (4)
- # fulcro (36)
- # graphql (6)
- # kaocha (4)
- # onyx (1)
- # pathom (15)
- # quil (3)
- # re-frame (15)
- # reagent (15)
- # reitit (9)
- # remote-jobs (2)
- # rewrite-clj (16)
- # ring-swagger (7)
- # shadow-cljs (132)
- # spacemacs (12)
- # sql (5)
- # vim (9)
- # xtdb (12)
- # yada (4)
It depends on what you’re rendering. And I’m assuming reagent is turning your hiccup into react elements
So I found the source of the issue https://github.com/mui-org/material-ui/blob/89687f38cae750650555772ba4d821c9084d8dfc/packages/material-ui/src/useMediaQuery/useMediaQuery.js#L23 now, Reagent is not compatible with useEffect , right?
Hey, Is there anyone knowing the rationale of the js/{namespace}
? How many js things that we can use via it? I have seen the docs http://cljs.github.io/api/syntax/js-namespace, But it doesn't include this.
I’m not sure the question. js/whatever
just allows you to access the js global object.
I guess to answer your question: You can access anything that you could have accessed in JS directly. (e.g. $
for jquery, ReactDOM.render
, _.*
for lodash, etc etc etc)
@ag reagent components themselves can't use hooks but regular JS functions components can. did you maybe turn them into classes via the reagent/adapt-react-class
or something?
How can we debug the macro
in ClojureScript
? It doesn't work for repl
because of its feauture. And I really confuse with the following code:
(defmacro promise->
[promise & body]
`(.catch
(-> ~promise
~@(map (fn [expr] (list '.then expr)) body))
(fn [error#]
(prn "Promise rejected " {:error error#}))))
What's the evalution
of the macro
expression? Why the exec sequence if promise.then(body-first.then(...))
?macroexpand
(macroexpand '(some form, remember the quote))
-> will output the s-expressions after macros have been applied
I've never had trouble macroexpanding in cljs repl (mostly use figwheel)
how do you guys keep your reagent components code readable? everytime i'm using map to create lists out of data it gets unreadable extremely quickly... any tips? or maybe some helpers i'm missing?
yea i do, but then if i need to provide some props to my-comp
it turns into
(map #(vec [my-comp {:foo "bar} %]) my-things)
and now if these props get bigger, or if my-things
isn't that simple and i need to
(map #(vec [my-comp (first %)]) my-things)
or something it gets uglyU can always use for
I sometimes find for
can be more readable than map
but then you need a doall
so
swings and roundabouts 😄
@danieleneal Sure about that? Both for
and map
are lazy, so the need for doall
should be independent of that
oh yeah 😄
Is there a way to check the type of something without importing/requiring it’s constructor? In my particular case the constructors reside in different modules based on node/browser so requiring it in shared code is more tricky (afaik only possible with Shadow CLJS)
oh hrm - that reminds me there is a detail thing that's unlikely to change - I wouldn't do it in a lib - but for app maybe ok
yeah, types need to be printable so that string is on a "static" field of the type - you can see this if you look at the implementation of deftype
hey! im trying to use expound with clojurescript, but setting ` (set! s/explain-out expound/printer)` doesn't seem to do anything.. any ideas?
might depend what repl / clojure version you are using
@lkowarschick Yes, it may depend on the environment and what you are trying to do with expound https://github.com/bhb/expound/blob/master/doc/compatibility.md
the compatibility chart says it should be compatible. how would that thing:
clj -Srepro -Sdeps '{:deps {expound {:mvn/version "0.7.2"} org.clojure/test.check {:mvn/version "0.9.0"} org.clojure/clojurescript {:mvn/version "1.10.520"}}}' -e "(require '[expound.alpha :as expound]) (set! clojure.spec.alpha/*explain-out* expound.alpha/printer)" -m cljs.main -re node
be achieved with lein/shadow-cljs?
With lein
, I wonder if you could use injections
? Not sure
https://github.com/technomancy/leiningen/blob/301d802eb1c4574c9094780aa6aff845ee14f2f9/sample.project.clj#L182
As for shadow-cljs, I haven’t used it so I can’t say
That said, that step should only be necessary if you are trying to get expound errors when using macros.
Do you see expound messages if you do something like the following?
(set! s/*explain-out* expound/printer)
(s/explain (s/coll-of int?) [1 2 "3"])
(I’m just trying to figure out how you are using spec in this case)For instance, this gives me an expound error:
cljs.user=> (require '[clojure.spec.alpha :as s])
nil
cljs.user=> (require '[expound.alpha :as expound])
nil
cljs.user=> (set! s/*explain-out* expound/printer)
#object[expound$alpha$printer]
cljs.user=> (require '[clojure.spec.test.alpha :as st])
nil
cljs.user=> (s/fdef add :args (s/cat :x int? :y int?))
cljs.user/add
cljs.user=> (defn add [x y] (+ x y))
#'cljs.user/add
cljs.user=> (st/instrument)
cljs.user=> (add 1 "2")
i just copied yours and it didnt work haha also, your simple example doesn't seem to work outside of the repl (so regularly within the code)
Interesting, but you are seeing a spec error when calling your simple function, just not an expound error?
I wonder if the issue is this one: https://github.com/bhb/expound/issues/152
Huh, that’s weird, outside of a REPL I thought recent versions of CLJS were not formatting spec errors. In any case, I suspect either
a) somehow the printer is not getting set (perhaps this code is not called before the simple function is called)
b) the environment (not sure if you’re using lein-cljsbuild or shadow-cljs) is adding some wrapper code that prints specs and that is not using the current value of s/*explain-out*
.
If you can push a repo with repros the issue, I can take a look but it’s hard to say over slack since there are a lot of environment-specific variables
Yeah, the thing that formats the spec output is environment specific - different for different repls, etc
An interesting question was posted on Reddit https://www.reddit.com/r/Clojure/comments/cznbno/are_functions_returning_a_vector_of_constants/
(defn primes []
[2 3 5 7])
(identical? (primes) (primes))
true
Why is it returning true?well, in clojure constant collections are created at initialisation time just once rather than at runtime, I imagine clojurescript has a similar optimisation
mmm, I don't think so, at least not in self hosted cljs
Nice. Wonder if ClojureScript should be on par with Clojure here? cc @dnolen
pretty sure there's a ticket for this, we in fact already do this for keywords/symbols
I would like to see some performance tests since this may affect startup performance
hi guys, why we don't have "walk" of clojure in clojurescript http://clojuredocs.org/clojure.walk/walk , or do we have ? how can i change every value of my map
You can actually require clojure.walk in CLJS, no problem.
I will change an values of an incoming json to keywords like {"id", ":my-id"}
to {"id", :my-id}
Hmm, usually people are looking for keywordize keys
but shouldn’t be too hard…
Something like this:
(require '[clojure.walk :as walk])
(defn keywordize-values
[m]
(let [stringify (fn [[k v]]
(let [v (if (string? v)
(if (= \: (first v))
(keyword (subs v 1))
(keyword v))
v)]
[k v]))]
(walk/postwalk (fn [x]
(if (map? x)
(into {} (map stringify x))
x))
m)))
(keywordize-values {"id" ":my-id"
"sub" {"id" ":my-other-id"}})
=> {"id" :my-id, "sub" {"id" :my-other-id}}
(def sample {:a ":rabbit"
:b "bird"
:c ":zebra"
:d 5})
(defn keyword-str [val]
(if (string? val)
(if (= (subs val 0 1) ":")
(keyword (replace-first val ":" ""))
val)
val))
(defn keywordize-map [m]
(zipmap
(keys m)
(map keyword-str (vals m))))
Yeah, I basically looked up the source code for clojure.walk/keywordize-keys
and adapted it to convert the values instead.
:thumbsup:
there' s a ticket out there to genericize some of that stuff to open it up more
> generally for any function that is collection -> collection, the collection should be the first arg. What about map, filter, reduce, etc...?
those are sequence -> sequence
where the sequence goes last
if you want to vote, https://ask.clojure.org/index.php/4287/add-function-transform-keys-to-clojure-walk is a good place