look at vega-lite as well, less powerful but quite a bit easier to manipulate
also metasoarous/oz
if you want to chart from your repl conveniently (this even works with a remote repl over ssh)
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? 🙏
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.
How do I check it’s CLJS versus React DnD?
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.
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…
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.
Also, check out if you can find some relevant issues in the WebKit bug tracker.
Thanks for the feedback - I will check those avenues!
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
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.
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!
@magnars this is usually a :language-out
problem if I recall - set it to :es6
or higher I think?
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?
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.
@magnars $jscomp
is probably closer to the real problem
Closure is generating some stuff that expects runtime support which is quite strange
@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
if that's true that the appearance of $jscomp
and the other problems are not much of a surprise
if you want to use stuff from node_modules
you need to use :bundle
target
That is indeed the case. We are not using the :bundle
target. Thanks for the heads up, I'll follow up on that lead. 👍
Is there an equivalent to clojure.data.json
for clojurescript?
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
Oh, so I can just call these by using something like js/json.stringify
?
(.stringify js/JSON (clj->js {:a :b}))
. i think you can get away with js/JSON.stringify
though
It works! Thanks a bunch!
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.
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))))))))
Ok, I might have to read up on what laziness means, because this is the second time I came across a problem like this.
Thank you again @thheller, and thank you doseq
.
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.It's possible if that def
is inside a CLJC file.
Do I get it using resolve
and deref
?
I'm able to get metadata of a def from cljs using cljs.analyzer, but can't figure how to get actual value.
Neither. You just use regular :refer
.
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.
;; a.cljc
(ns a)
(def test-map {:foo :bar})
;; macro.clj
(ns macro
(:require [a]))
(defmacro mymacro [symb]
(do-something-to a/test-map))