This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-17
Channels
- # announcements (45)
- # asami (30)
- # babashka (96)
- # beginners (24)
- # calva (43)
- # chlorine-clover (3)
- # cider (10)
- # clj-kondo (45)
- # cljdoc (10)
- # cljs-dev (2)
- # clojars (5)
- # clojure (139)
- # clojure-australia (5)
- # clojure-europe (53)
- # clojure-filipino (1)
- # clojure-germany (27)
- # clojure-nl (4)
- # clojure-provo (7)
- # clojure-serbia (6)
- # clojure-spain (1)
- # clojure-uk (8)
- # clojuredesign-podcast (8)
- # clojurescript (76)
- # code-reviews (6)
- # conjure (4)
- # core-async (1)
- # cursive (73)
- # data-oriented-programming (2)
- # data-science (3)
- # deps-new (4)
- # depstar (7)
- # docker (16)
- # duct (7)
- # events (1)
- # fulcro (13)
- # girouette (1)
- # graphql (4)
- # honeysql (11)
- # jobs (2)
- # joker (1)
- # kaocha (4)
- # leiningen (5)
- # malli (11)
- # off-topic (14)
- # other-languages (1)
- # pedestal (4)
- # practicalli (1)
- # re-frame (5)
- # reagent (3)
- # releases (2)
- # remote-jobs (7)
- # shadow-cljs (12)
- # sql (24)
- # startup-in-a-month (2)
- # tools-deps (99)
- # vim (8)
- # vscode (1)
- # xtdb (28)
What exactly do you want to achieve? It's likely that a solution is on the surface, so you won't have to spend too much time.
Thanks for caring! I wrote this macro yesterday that is like let
and then also taps the bindings. For debugging purposes. It’s reasonably ergonomic to use in Clojure. But in ClojureScript it becomes a bit clunky. Still easier than manually putting together the thing to be tapped, but anyway. Would like it to be easier to use. Here’s the macro: https://github.com/PEZ/taplet
If your CLJC file contains only macros then it can be just CLJ - that reader conditional at the ns
form can just be removed.
Apart from that, I'm still not sure what you want to achieve. What do you want to require
conditionally?
Ah, immediately after writing this I realized that switching from CLJC to CLJ will make your users use :require-macros
. Right, CLJC is better in this case. Or just a combination of CLJ and CLJS where the CLJS file has nothing but the ns
form.
CLJC or CLJ+CLJS is a matter of taste probably. I think CLJC signals that it is a feature targeted at both.
What I want to achieve… The README of the repo only targets CLJ usage. The CLJS howto is a bit clunky, since needs to be put in the ns
form, so I held off writing that part until I had investigated the options some.
Ah, you meant requiring taplet
itself, I see.
Honestly, I wouldn't change anything in your README. By the time anyone decides to use tap>
, IMO they should already know their target platform more or less. I.e. in this case they should be able to convert that (require '[...])
form to an appropriate section in their ns
form themselves, in their head.
Otherwise, you'll also have to make distinctions between flavors of platforms. E.g. (require '[...])
in self-hosted CLJS is (or should be) perfectly fine.
What is the go-to library for http calls/requests in ClojureScript? Like the equivalent of axios in JS
I think cljs-Ajax is the most active lib for that: https://github.com/JulianBirch/cljs-ajax
For extremely simple use cases tho I’ve gotten away with simply interop’ing with js/fetch
Very uninformed question but isn't ajax no longer really used (at least in the JS world). What might I be ignorant to here :x ?
Was thinking http-kit might be the standard but seems to just be for clojure https://github.com/http-kit/http-kit
AJAX is still used. Well, mostly its "AJ" part, but still. I can't imagine it going anywhere in our lifetime.
Perhaps, you meant that JS has introduced the new fetch
API that is supposed to replace XMLHttpRequest
. But the fetch
API is still AJAX. And XMLHttpRequest
is not going anywhere any time soon either.
I honestly just use fetch
🤷
Is there a particular feature set your looking for?
> fetch
will not let you cancel a request if you need to
I believe this changed recently with https://developers.google.com/web/updates/2017/09/abortable-fetch :thumbsup:
Has anyone used figwheel and solved the "loading 100 files for 5 minutes on refresh" issue?
like if on initial load everything was concatenated together that would solve everything
I have a map that looks like this {:filename "filename" :zip-file zipfile} where zipfile is a file read in with .readAsArrayBuffer I want to validate this map with cljs.spec.alpha. How can I do that? I'm unsure how to handle the zip file
I don't think there's any other feasible approach than to just check that it's a not empty ArrayBuffer
.
I've ended up doing it with a custom function:
(s/def :test/array-buffer #(= (type %) js.ArrayBuffer))
does anyone know the best way to go about checking in a list of dictionaries if some of the key values match up (i.e. if I have [{:a 3, :d 4}, {:a 2, :d 4}, {:a 4, d: 4}], I want to do something like return true since all the values for key d is 4)
Think you want to use every?
(every? #(= 4 (:d %1)) list-of-maps)
assuming you know the value to check for ahead of time
if you just wanted to know if the same key across the maps have the same value (regardless of what it is), you could do something more like
I’m more trying to see that values match rather than if they equal something specific
(->> list-of-maps (map :d) (set) (count) (= 1))
ah, so just do all the maps in the list have the same keys and values?
(let [m (first list-of-maps)]
(every? #(= m %1) (rest list-of-maps)))
sorry if I'm still misunderstanding 🙂
no worries, I’m actually trying to clarify my own usecase really quickly but this is definitely really helpful
I have a set of maps to maintain, and do occasionally need an order on it. So I had the (semi-?) bright idea of using metadata like ^{:pos 1}
. But I also have to serialize the set into browser localstorage. I’ve been using edn so far, and it seems that edn/read-string
will pull the metadata back in OK but … what should I use to make the edn string? Seems (pr-str ,,,)
isn’t cutting it
oh wait nvm … just rubber-ducked it for myself:
user=> (binding [*print-meta* true] (pr-str ^{:foo 1} {:bar 2}))
"^{:foo 1} {:bar 2}"
hah, well, after all that I entirely forgot that stashing the positions in metadata would make it invisible to reagent, so no re-renders on position changes. So much for my first “I know I’ll solve that problem with metadata” brainwave.
a large percentage of those end badly :)
If you can use a ordered sequencel/list/vector rather than a set, you'll get your ordering guarantees, but I have no idea whether the feature in reagent you are trying to use supports that.
I'm sure you already considered and rejected that for some perfectly valid reason. Just call me captain obvious 🙂
yeah, I just wanted to be clever and hold them as a set for easy membership checks but honestly it’s 10-12 maps and I can just trivially turn them into a set when I need to.
yeah, I just wanted to be clever and hold them as a set for easy membership checks but honestly it’s 10-12 maps and I can just trivially turn them into a set when I need to.
for whatever reason, a slurped file containing
[:p "foo"]
is not rendering with hiccup with
(html (slurp "page"))
where html is :refer’d hiccup; it works fine with
(html [:p "foo"])
thoughts?slurp returns a string
in code, [:p "foo"]
is a vector
try:
(type (slurp "page))
vs (type [:p "foo"])
you probably want something like:
(with-open [rdr ( "page")
pb-rdr (java.io.PushbackReader. rdr)]
(clojure.edn/read pb-rdr))
but there are several ways to read an edn file depending on the exact semantics required
thanks! string and vector respectively… it balks at a conversion of the string to a vector via vec, however.
It’s not technically an edn file.
well, you need some way to parse the file. what type of file is it?
throws
[ is not a valid element name.
check (prn (vec (slurp "page")))
in this case, no type, just a plain file.
does the file contain edn?
if it contains edn, then clojure.edn/read
should work
it doesn’t.
just the plain vector.
just
[:html [:p "hello"]]
which
(prn (vec (slurp "page")))
turned into
[\[ \: \h \t \m \l \space \[ \: \p \space \" \h \e \l \l \o \" \] \]]
and when it’s fed into hiccup, it complains that
[ is not a valid element name.
the above code with the edn reader should work
ok, I can give that a go.
you'll probably need to require:
(require '
'clojure.edn)
seems to be available, but that throws
java.lang.String cannot be cast to java.io.PushbackReader
so weird. basically, I just can’t coerce the file into a proper vector, it seems.
are you copied the code correctly?
for eg.:
(with-open [rdr ( "deps.edn")
pb-rdr (java.io.PushbackReader. rdr)]
(clojure.edn/read pb-rdr))
This works for meanother way to read edn data from a file is (read-string (slurp "page"))
although it will cause issues for some edge cases