This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-17
Channels
- # announcements (7)
- # babashka (56)
- # beginners (114)
- # bristol-clojurians (4)
- # calva (22)
- # cider (7)
- # clara (1)
- # clj-kondo (17)
- # cljs-dev (1)
- # clojure (93)
- # clojure-europe (8)
- # clojure-italy (5)
- # clojure-nl (2)
- # clojure-uk (79)
- # clojuredesign-podcast (18)
- # clojurescript (108)
- # code-reviews (6)
- # cursive (3)
- # data-science (16)
- # datomic (151)
- # duct (7)
- # emacs (10)
- # events (1)
- # fulcro (76)
- # luminus (8)
- # off-topic (3)
- # other-lisps (2)
- # pathom (8)
- # re-frame (5)
- # reitit (8)
- # schema (9)
- # shadow-cljs (37)
- # specter (3)
- # sql (17)
- # tree-sitter (2)
- # yada (9)
Hi, maybe someone can nudge me in the right direction. I’m working with #inst literal https://cljs.github.io/api/syntax/inst-literal I can’t find how to format these. Is there a tool I’m missing? I want to (for example: Display the time in the local time zone)
Not sure what you mean. CLJS will parse #inst
for you. Upon evaluation, you'll get a js/Date
object that you can format any way you like.
clojurescript itself doesn't provide any more operations for #inst
. #inst
is just a protocol-extended javascript Date
, so you can use any methods provided by Date
(long winded examples https://stackoverflow.com/questions/15141762/how-to-initialize-a-javascript-date-to-a-particular-time-zone) or some libraries that work on Date
s.
However, you might see by those examples that Date
has a pretty nasty API for doing anything practical, and Date
is all you'll get for doing time-related operations (no time durations or periods). There are other libraries that make time-related code much easier, the prime examples being https://github.com/henryw374/cljc.java-time and https://github.com/juxt/tick. Both present a more idiomatic interface to a https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html style library, so you'll get a lot more utility and readable code.
Hi! What’s the current state of ClojureScript advanced compilation and creating small bundles? Can you create a hello world that compiles to 2-3 lines of JS, or is it still a dream?
If you are looking to write a simple hello world function, then you might we well right it in JS…
right, that was exemplary question though 😉 the reality is: some data fetching, few event listeners and few DOM changes
It's state-of-the-art. Supports code-splitting (https://clojurescript.org/guides/code-splitting) and has dead-code elimination built-in.
If you're looking specifically at the size of a compiled (println "Hello, world!")
I'm not sure, but for any practical application it's going to be hard to beat
I know it’s state of the art 🙂 I work in Clojure/ClojureScript codebase with some little JS parts
I was curious is it possible to generate all code from ClJS and can I compete with compiled pure JS size 😉
FWIW even with a single CLJS file that has nothing but the ns definition and with the :fn-invoke-direct true
compiler option specified, the output file is still 91KB.
Hi, I am completely new to CLJS but familiar with Clojure. How do I consume this TypeScript library in CLJS? https://github.com/ethereumjs/rlp No CLJSJS version available.
If you're using Shadow-CLJS, you can just install it via NPM/Yarn and consult this documentation section: https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages
Yes, I am using shadow. I thought it is only for hot reload. Looks like I have a lot to learn. Thanks!
Hmm, interesting. I am completely new to CLJS. What are the de facto tools used by developers now-a-days?
Different people still use different things. There was a Clojure survey recently - the percentages were mentioned there.
Okay, here's another beginner level question. I created a shadow-cljs project today with lein new shadow-cljs +reagent
and looks like the project has no project.clj. Only a shadow-cljs.edn. Where does Lein/deps.edn fit in? Do you use deps.edn just for running some commands?
I use deps.edn
for all dependencies. Seems like you just need to read through the documentation of Shadow-CLJS. :)
To provide an alternative approach, my go-to is figwheel+clj/clojure
. Here is a blog I wrote outlining what my approach looks like: https://betweentwoparens.com/start-a-clojurescript-app-from-scratch and I also created a sort of “create react (reagent) app” like tool here: https://github.com/athomasoriginal/create-reagent-app
@andrzej.fricze only if you restrict yourself to JS style coding
I know I can avoid loading ie. Clojure data structures, but the minimal output is still 91kb, isn’t it? can I get smaller than that?
I can work with that. how can I achieve that? do you maybe have sample project with proper config?
literally self hosted ClojureScript (which is not even advanced compiled) is smaller than a lot of React projects it seems
so it seems that I really can use ClojureScript everywhere 🙂 just compiled minimal example to 5k :thumbsup:
of course, have to write only JS-like code, as you said, but I still have the same syntax, editor, repl and tooling
@andrzej.fricze out of interest, how did you set it all up?
did everything according to this instruction https://clojurescript.org/guides/quick-start
Interesting. I downgraded to 1.10.520 as suggested by dnolen, and got a 1.5kB file that has only the ns declaration and a single js/console.log
statement. Using shadow-cljs.
(function(){
if("undefined"!==typeof Symbol){var a=Symbol;"object"!=typeof a||!a||a instanceof Array||a instanceof Object||Object.prototype.toString.call(a)};console.log("Hello world!");
}).call(this);
This if
block looks completely useless though, but I could live with that.WARNING: The org.clojure/clojurescript dependency in shadow-cljs.edn was ignored. Default version is used and override is not allowed to ensure compatibility.
I used :deps true
and specified the CLJS version there.
Not sure how severe the warning is in this case.
I won't keep spamming asking this every day but does anyone know if there is any way to use a macro from an external cljs library in cljs.js/eval-string
? I've been stuck on trying to figure this out for a few days
@jjttjj it depends on if the macro is defined in a CLJS namespace and if it’s compatible with self-hosted CLJS
oh ok. so you’ve already migrated the core.clj
with the macros into a .cljs namespace?
yeah, you can’t load a .clj
file into self hosted clojurescript. all the macros need to be in a CLJS namespace, and need to not depend on any JVM Clojure constructs or behavior
Cool, yeah I removed the JVM stuff, is it then just a matter of changing the extension? Trying this now
if it’s self-hosting compatible, it probably will be be compatible in both lumo (self hosted on Node.js) and self-hosted in the browser
I still should have to do something like this, right? https://clojurescript.org/guides/self-hosting
I guess I'd probably have to include javelin itself to get the source or somehow reference the resource files
I googled “shadow-cljs self-hosting” and this was the third result: https://code.thheller.com/blog/shadow-cljs/2017/10/14/bootstrap-support.html
On the topic of macros, I also have a question. I am making a calculation register that can run entirely at compile time. Alot of data is built up in an atom there though, and I would like to transfer that data to the compiled app. Where I am now.
; clj
(def x (atom {}))
(defmacro reg-thing [k v]
(swap! x assoc k v))
(defmacro get-x [] @x)
It might not be a good idea in general: https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html#gotcha-2-caching-and-parallel-build
Whoops, sorry. I'm an idiot. I evaluated (comment x)
instead of x
. The data does end up coming through. I'll check out the link.