clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
blak3mill3r 2021-06-15T00:17:55.203400Z

look at vega-lite as well, less powerful but quite a bit easier to manipulate

blak3mill3r 2021-06-15T00:18:51.203800Z

also metasoarous/oz if you want to chart from your repl conveniently (this even works with a remote repl over ssh)

tomrbowden 2021-06-15T00:36:50.210400Z

Has anyone dealt with solving performance issues with Safari specifically for a web app written in ClojureScript? I am writing a feature involving drag and drop, using the Reagent wrapper around React, and the https://react-dnd.github.io/react-dnd/about library. The feature has some complexity to it, with calculations involving where the UI “blocks” can be dropped, including drag previews. I am able to get it to work quite smoothly on Chrome/Firefox/Edge, but the lagginess on Safari makes it unusable in that one browser… Does anyone have any advice/pointers? 🙏

p-himik 2021-06-15T10:50:36.216100Z

No direct experience, but I would first check that it's indeed CLJS and not the DnD functionality itself. Then, if you can confirm it's CLJS, I would simply profile it, assuming Safari has a JS profiler.

tomrbowden 2021-06-15T11:30:41.216500Z

How do I check it’s CLJS versus React DnD?

p-himik 2021-06-15T11:33:37.216700Z

If you can create two implementations of a very simple DnD functionality where one is written in CLJS and the other is in JS, then you can compare them. If it's not that easy, you can start with profiling - chances are, it will answer that question as well.

tomrbowden 2021-06-15T11:37:33.216900Z

Oh, the first part of that I have already done. With simple apps, there is no lag in Safari with either CLJS version of React-DnD, versus JS version of React DnD implementation. I only saw a big performance lag in Safari with the more complex feature, which I would rather not replicate in JS, due to time constraints. As said though, with other browsers the drag and drop works fine for the complex CLJS/ReactDnD…

p-himik 2021-06-15T11:40:28.217200Z

So it's still unclear what the cause is then. Either the complex feature is written in a way that's slow on Safari, or it uses some browser JS API that's slow on Safari. The first case might be fixable by just rewriting the same feature in a different way. The second one might be fixable if there exists some alternative API that could be used instead.

p-himik 2021-06-15T11:41:07.217400Z

Also, check out if you can find some relevant issues in the WebKit bug tracker.

tomrbowden 2021-06-15T11:42:34.217600Z

Thanks for the feedback - I will check those avenues!

2021-06-15T01:46:15.212400Z

what’s the right way to pull some CSS framework into a project like tachyon or bulma? I know that shadow-clj doesn’t really support sass/scss, though there’s ways to write CSS as clojure using garden

p-himik 2021-06-15T10:52:25.216300Z

You can use build hooks or just start a separate process to compile anything to CSS, including sass/scss. Sometimes people write their own small wrappers for CSS frameworks/libraries. I know of two for Tailwind CSS.

2021-06-15T07:20:15.215800Z

I switched to the newest devcards (0.2.7), which is now providing react via :npm-deps . This works fine. However, in combination with :install-deps true in my ClojureScript compiler options (for other reasons), two things happen: • the dependencies declared in npm-deps in devcards are added to my package.json (this is expected) • my app now fails with $jscomp is not defined and React is not defined (unexpected for me) There must be something about :install-deps that I don't understand. What am I missing? Thanks!

dnolen 2021-06-15T13:14:27.218500Z

@magnars this is usually a :language-out problem if I recall - set it to :es6 or higher I think?

2021-06-15T14:22:19.219700Z

Setting :language-out :es6 didn't do it, unfortunately. Do I have to make sure React is loaded into the page myself when using it like this?

2021-06-15T14:29:53.222Z

In short: React is provided via transitive :npm-deps in Devcards, until I add :install-deps true in my compiler opts. After that, I get ReferenceErrors.

dnolen 2021-06-15T14:50:04.222700Z

@magnars $jscomp is probably closer to the real problem

dnolen 2021-06-15T14:50:38.223500Z

Closure is generating some stuff that expects runtime support which is quite strange

dnolen 2021-06-15T14:51:24.224200Z

@magnars oh ... but it sound like you are trying to push React through Closure? doesn't work - you haven't said anything about using the :bundle target

dnolen 2021-06-15T14:51:53.224700Z

if that's true that the appearance of $jscomp and the other problems are not much of a surprise

dnolen 2021-06-15T14:52:11.225100Z

if you want to use stuff from node_modules you need to use :bundle target

2021-06-15T15:01:59.226100Z

That is indeed the case. We are not using the :bundle target. Thanks for the heads up, I'll follow up on that lead. 👍

West 2021-06-15T15:02:06.226300Z

Is there an equivalent to clojure.data.json for clojurescript?

dpsutton 2021-06-15T15:07:37.227100Z

the heart of that is reading and writing json which is handled pretty well natively by JSON/stringify and JSON/parse : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON

West 2021-06-15T15:08:42.228Z

Oh, so I can just call these by using something like js/json.stringify ?

dpsutton 2021-06-15T15:10:45.228600Z

(.stringify js/JSON (clj->js {:a :b})) . i think you can get away with js/JSON.stringify though

West 2021-06-15T15:12:59.229Z

It works! Thanks a bunch!

West 2021-06-15T15:27:34.229700Z

West 2021-06-15T15:28:03.230400Z

Looks like my script works fine when I run it in a repl, but it fails when I compile it to a js file and run with node. It will create a directory if it isn’t there, but it won’t generate any files.

thheller 2021-06-15T15:31:20.231100Z

remember that map is lazy. so you want to use something that forces the lazy seq. eg.

(defn gen-all-posts
  [in-path out-path]
  (create-out-dir out-path)
  (let [input (rest (file-seq in-path))]
    (doseq [file input]
      (spit (str out-path (:id (:data (blog-post (slurp file)))) ".json")
        (js/JSON.stringify (clj->js (blog-post (slurp file))))))))

West 2021-06-15T15:34:24.232Z

Ok, I might have to read up on what laziness means, because this is the second time I came across a problem like this.

West 2021-06-15T15:36:10.232600Z

Thank you again @thheller, and thank you doseq.

sergey.shvets 2021-06-15T23:37:30.236200Z

Hi. Is it possible to get access to compile-time def inside clojurescript macro? Here is what I'm trying to achieve

;; cljs file
(ns my.cljs)

(def test-map {:foo :bar})

(mymacro test-map)

;; macrodef.clj
(defmacro mymacro
   [symb]
;; can I get the {:foo :bar:} here somehow? 
) 
Thanks in advance! I tried every option I could google, but no luck thus far.

p-himik 2021-06-15T23:44:30.236300Z

It's possible if that def is inside a CLJC file.

sergey.shvets 2021-06-15T23:50:13.236500Z

Do I get it using resolve and deref ?

sergey.shvets 2021-06-15T23:50:39.236700Z

I'm able to get metadata of a def from cljs using cljs.analyzer, but can't figure how to get actual value.

p-himik 2021-06-15T23:55:36.236900Z

Neither. You just use regular :refer.

p-himik 2021-06-15T23:56:15.237100Z

Note that if you have some ns defined in a CLJC file, you cannot also have a CLJ or a CLJS file for that same namespace.

p-himik 2021-06-15T23:57:14.237300Z

;; a.cljc
(ns a)

(def test-map {:foo :bar})

;; macro.clj
(ns macro
  (:require [a]))

(defmacro mymacro [symb]
  (do-something-to a/test-map))