clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
djblue 2020-09-28T05:12:29.108700Z

https://github.com/djblue/portal might also be a solution

javahippie 2020-09-28T06:01:37.111700Z

I am walking my first babysteps with Clojurescript and have a little issue adapting. For a start, I wanted to write a small frontend for the Hackernews API. The API offers a method to retrieve the IDs of the latest posts, afterwards I can fetch each post with a separate API Call. My current solution looks like this:

p-himik 2020-09-28T07:25:24.112200Z

I don't see anything wrong with the code. Just a few notes: - You're using the same name response for different things in different functions - post and id are mixed, which makes it a bit harder to understand (i.e. first-posts is actually first-posts-ids) - go uses a thread pool that's limited to 8 threads. Using it for IO may lead to unpleasant consequences in some cases

πŸ‘ 1
p-himik 2020-09-28T07:25:55.112400Z

Regarding the last point: http://danboykis.com/posts/things-i-wish-i-knew-about-core-async/

p-himik 2020-09-28T07:32:23.112700Z

Or I guess I might be wrong about it - after all, http/get is itself async. I'm not that proficient with clojure.core.async. :)

javahippie 2020-09-28T08:11:29.112900Z

I believe http/get is using core.async, I was suprised by this, too, at first, but it makes sense. Thanks for your remarks, you are right about the namings!

javahippie 2020-09-28T08:12:10.113200Z

And the linked blog is bookmarked for lunch, thx πŸ˜‰

javahippie 2020-09-28T06:04:07.112Z

This feels clunky for me, but I am not able to put my finger on it. I am using Rum for the components, so the list of posts reacts on the state change in the atom. The application works, but I am pretty sure that this could be done better.

Stas Makarov 2020-09-28T09:26:40.114100Z

short version: Where should I add namespaces to keywords in API response maps in cljs SPA? And should I do that in the first place or just use unnaspaced keywords (and forget about clojure spec on frontend)? longer version: I'm trying out spec in my small cljs reagent app. I stumbled on a problem that API responses gotten via cljs-ajax doesn't namespace keywords in maps ( https://github.com/JulianBirch/cljs-ajax/blob/master/src/ajax/json.cljc#L33 ) As I understand there's no elegant way to redefine behavior of read-json-native in cljs-ajax (cljs-http too). And the only way to do this is to add namespaces in my app code with something like that:

(map->nsmap {:a 1 :b 2} (create-ns 'my.new.ns))
=> #:my.new.ns{:a 1, :b 2}
;;  <https://stackoverflow.com/a/43722784/1856086>  
Also I'm considering switch to httpurr, as it gives more control on decoding function. But maybe I'm missing something here? What's your experience of namespaced keywords's usage in cljs apps?

alpox 2020-09-28T09:43:29.115900Z

@jehaby I am using cljs-ajax through http-xhrio from re-frame and namespaced keywords worked almost out of the box with these options:

{:http-xhrio {:method :get
                 :response-format (http/json-response-format {:keywords? true})
                 :uri &lt;uri&gt;
                 :on-failure [:common/set-error]}})

Stas Makarov 2020-09-28T09:51:17.116Z

thanks! I'll take a look.

p-himik 2020-09-28T10:30:26.116200Z

The solution above doesn't add namespaces by itself. It creates namespaced keywords iff the response has keys like "a/b". I.e. keys that would create namespaced keywords if passed to keyword.

p-himik 2020-09-28T10:30:44.116400Z

{:keywords? true} just translates every key with keyword, that's it.

p-himik 2020-09-28T10:31:38.116600Z

@jehaby If you want to add your own namespaces, you will have to either transform the received data in your code directly or write your own response handler - just like read-json-native, only with an extra :namespace option or something like that.

Stas Makarov 2020-09-28T10:33:58.116900Z

Thank you!

vncz 2020-09-28T15:44:02.123500Z

Is there a quick and dirty way to see how ClojureScript would compile to JavaScript a regular function without having to set up a full project?

p-himik 2020-09-28T15:45:58.123700Z

http://app.klipse.tech/

vncz 2020-09-28T15:46:41.123900Z

Oh fantastic!

vncz 2020-09-28T15:47:51.124100Z

@p-himik cljs.core.PersistentVector do you know where are these structures defined in JavaScript?

vncz 2020-09-28T16:05:06.124700Z

but that ain't javascript; where are the collections effectively implemented in JavaScript @victorbjelkholm429?

p-himik 2020-09-28T16:09:54.124900Z

Impossible to tell, depends on many factors. You will have to compile a small CLJS file that uses PersistentVector and see what the code is.

vncz 2020-09-28T16:20:01.125100Z

That's what I did, and I can't find it. Example:

p-himik 2020-09-28T16:43:04.125400Z

What's the example? :)

oliver 2020-09-28T20:23:18.132400Z

Hey guys, I'm having a weird problem here and lacking the Node.js-knowledge to solve it, When revisiting a project after a pause of about 3 weeks I was surprised that suddenly shadow-cljs tells me a dependency is missing: The required JS dependency "querystring" is not available, it was required by "node_modules/url/url.js". The module is installed under node_modules however, and npm install --save url succeeds but doesn't change a anything. I might also mention that at first shadow-cljs complained about a missing dependency needed for nodemailer (which is not even used by the frontend part of my app that I'm trying to compile here, but only by the backend which worked just fine) Any ideas on what to do next?

thheller 2020-09-28T20:31:22.132900Z

@services npm install shadow-cljs in your project.

βœ”οΈ 1
oliver 2020-09-28T20:33:55.133500Z

Thank you so much… this probably saved me a lot of time!

oliver 2020-09-28T20:35:15.134100Z

Also: Thanks for creating and maintaining shadow-cljs!

πŸ™ 1
vncz 2020-09-28T21:17:49.134700Z

Hmm ok understood. I was wondering how these data structures were implemented in JavaScript. All right, thanks!