clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
pez 2021-03-17T09:48:50.001Z

There is no way I can require in a macro dynamically like I can do in Clojure, right?

p-himik 2021-03-17T09:57:13.001100Z

No way.

pez 2021-03-17T10:45:43.001800Z

Thanks. I’ll have to find the most ergonomic way to do it lacking that. 😃

p-himik 2021-03-17T12:58:21.002Z

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.

pez 2021-03-17T13:04:44.002200Z

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

zackteo 2021-03-17T13:36:47.004500Z

What is the go-to library for http calls/requests in ClojureScript? Like the equivalent of axios in JS

zackteo 2021-03-20T01:14:38.128200Z

Thanks everyone for your inputs 😄

cjsauer 2021-03-17T13:45:32.006500Z

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

✅ 1
zackteo 2021-03-17T13:48:34.006800Z

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 ?

zackteo 2021-03-17T13:49:00.007Z

Was thinking http-kit might be the standard but seems to just be for clojure https://github.com/http-kit/http-kit

p-himik 2021-03-17T13:49:48.007300Z

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?

p-himik 2021-03-17T13:51:24.007600Z

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.

p-himik 2021-03-17T14:02:06.007800Z

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.

vanelsas 2021-03-17T14:14:29.008Z

How about https://github.com/r0man/cljs-http

pez 2021-03-17T14:24:06.008300Z

CLJC or CLJ+CLJS is a matter of taste probably. I think CLJC signals that it is a feature targeted at both.

pez 2021-03-17T14:26:26.008500Z

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.

p-himik 2021-03-17T14:30:23.008700Z

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.

pez 2021-03-17T14:32:55.008900Z

Thanks. I’ll skip patronizing the reader then. 😃 .

athomasoriginal 2021-03-17T14:49:01.009300Z

I honestly just use fetch 🤷

athomasoriginal 2021-03-17T14:49:25.009500Z

Is there a particular feature set your looking for?

isak 2021-03-17T14:50:40.009700Z

fetch will not let you cancel a request if you need to, IIRC

isak 2021-03-17T14:52:15.009900Z

We just use an internal wrapper around <http://goog.net|goog.net>.XhrIo , but cljs-ajax looks good.

athomasoriginal 2021-03-17T15:01:08.010100Z

> 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:

isak 2021-03-17T15:18:37.010400Z

Ah, nice!

emccue 2021-03-17T15:25:43.011100Z

Has anyone used figwheel and solved the "loading 100 files for 5 minutes on refresh" issue?

emccue 2021-03-17T15:29:01.011600Z

like if on initial load everything was concatenated together that would solve everything

vanelsas 2021-03-17T16:27:07.014Z

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

vanelsas 2021-03-18T13:14:10.041200Z

I've ended up doing it with a custom function:

(s/def :test/array-buffer #(= (type %) js.ArrayBuffer))

👍 1
p-himik 2021-03-17T17:04:54.014700Z

I don't think there's any other feasible approach than to just check that it's a not empty ArrayBuffer.

vanelsas 2021-03-17T17:11:04.014900Z

yeah thought about something like that. Thanks, will give it a try

Aaron Goh 2021-03-17T20:45:42.016800Z

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)

rgm 2021-03-17T20:54:48.018Z

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

rgm 2021-03-17T20:55:16.018400Z

oh wait nvm … just rubber-ducked it for myself:

user=&gt; (binding [*print-meta* true] (pr-str ^{:foo 1} {:bar 2}))
"^{:foo 1} {:bar 2}"

localshred 2021-03-17T21:08:45.018500Z

Think you want to use every?

(every? #(= 4 (:d %1)) list-of-maps)

localshred 2021-03-17T21:09:53.018700Z

assuming you know the value to check for ahead of time

localshred 2021-03-17T21:10:30.018900Z

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

Aaron Goh 2021-03-17T21:10:48.019100Z

I’m more trying to see that values match rather than if they equal something specific

Aaron Goh 2021-03-17T21:11:15.019300Z

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

localshred 2021-03-17T21:12:15.019500Z

(-&gt;&gt; list-of-maps (map :d) (set) (count) (= 1))

localshred 2021-03-17T21:13:53.019800Z

ah, so just do all the maps in the list have the same keys and values?

localshred 2021-03-17T21:15:29.020Z

(let [m (first list-of-maps)]
  (every? #(= m %1) (rest list-of-maps)))

localshred 2021-03-17T21:17:59.020200Z

sorry if I'm still misunderstanding 🙂

Aaron Goh 2021-03-17T21:18:26.020400Z

no worries, I’m actually trying to clarify my own usecase really quickly but this is definitely really helpful

localshred 2021-03-17T21:18:53.020800Z

cool cool lmk when you know more

👌 1
rgm 2021-03-17T21:36:54.022500Z

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.

alexmiller 2021-03-17T21:40:04.022700Z

a large percentage of those end badly :)

2021-03-17T21:59:36.023700Z

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.

2021-03-17T22:00:38.023800Z

I'm sure you already considered and rejected that for some perfectly valid reason. Just call me captain obvious 🙂

rgm 2021-03-17T22:29:22.024100Z

more or less often than my “I know I’ll solve this with a macro” brainwaves? 😜

macrobartfast 2021-03-17T23:50:58.027400Z

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?

phronmophobic 2021-03-17T23:54:45.027500Z

slurp returns a string in code, [:p "foo"] is a vector

phronmophobic 2021-03-17T23:55:13.027700Z

try: (type (slurp "page)) vs (type [:p "foo"])