There is no way I can require in a macro dynamically like I can do in Clojure, right?
No way.
Thanks. I’ll have to find the most ergonomic way to do it lacking that. 😃
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
What is the go-to library for http calls/requests in ClojureScript? Like the equivalent of axios in JS
Thanks everyone for your inputs 😄
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
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.
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.
How about https://github.com/r0man/cljs-http
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.
Thanks. I’ll skip patronizing the reader then. 😃 .
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, IIRC
We just use an internal wrapper around <http://goog.net|goog.net>.XhrIo
, but cljs-ajax looks good.
> 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:
Ah, nice!
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've ended up doing it with a custom function:
(s/def :test/array-buffer #(= (type %) js.ArrayBuffer))
I don't think there's any other feasible approach than to just check that it's a not empty ArrayBuffer
.
yeah thought about something like that. Thanks, will give it a try
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)
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}"
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
The end usecase is to see that all for a list of dictionaries, for each of the keys, the values line up with each other
(->> 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
cool cool lmk when you know more
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 🙂
more or less often than my “I know I’ll solve this with a macro” brainwaves? 😜
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"])