Fork me on GitHub
Evan Haveman02:05:06

are there any good guides on starting a simple clojurescript project that doesn’t need the browser (eg a library of functions). i know i can use node. but i cant seem figure out what my deps.edn should look like, what the command line is to open a repl and play with my code, and what the command line is to run my tests.

Evan Haveman02:05:31

clj -M --main cljs.main --compile foo.core --repl works fine to open a repl connected to a browser and im able to run my code but when i try `clj -M --main cljs.main --repl-env node --compile foo.core --repl` the repl loads (without the browser) but i can’t run my code. `Execution error (ReferenceError) at (<cljs repl>:1). foo is not defined`


clj -Sdeps ‘{:deps {org.clojure/clojurescript {:mvn/version “RELEASE”}}}’ -M -m cljs.repl.node


… assuming you have: src/foo/core.cljs You should be able to successfully run: (require ’foo.core) (in-ns ’foo.core)


… from the REPL


This does not work for me.

Evan Haveman15:05:46

thank you @U050KSS8M that worked. turns out clj -M -m cljs.main --repl --repl-env node also works if i then manually require in my code when it starts. the --compile option doesnt seem to work. but i can live without that so now i have that as my command line to start the repl my deps.edn is {_:deps_ {org.clojure/clojurescript {_:mvn/version_ "1.10.844"}} _:paths_ ["src" "test"]} and i can require in my test package and run my tests inside the repl. progress!

👍 2

Hello, beginner question: how do I import SQLite from 'sqlite-react-native-storage' in cljs? I tried (require '[sqlite-react-native-storage :refer [SQLite]]) but it fails with TypeError: undefined is not an object (evaluating 'dondai.core.node$module$react_native_sqlite_storage.SQLite')


I see a space in “: refer”. There should be no space.


sorry. just a typo here on slack. The es5 way to require the library would be just require('react-native-sqlite-storage'), but for some reason doing that returns nil on my repl.


I mean, doing it the cljs way - I tried both (require '[react-native-sqlite-storage :as foo]) and (js/require "react-native-sqlite-storage"). I checked the library is working correctly by requiring it from krell_repl.js from the build output directory (`target/`)


in react-native things cannot be required dynamically as metro needs to fill them in


so you can only use it if one of your source file requires it already and you reload that app


I see! that did the trick, thanks ^^


I initially tried requiring from a source file but failed - but after cleaning the target directory up and restarting it worked

Jakub Holý (HolyJak)16:05:35

Hi folks! Any good React intro for a would-be Reframe/Fulceo/etc. user, one that explains all the important things without wasting too much time on things irrelevant for us? The best I found after hours of digging is and a few pages from React's own tutorial (linked to from 🙏


does anyone happen to have a figwheel-main example app using the bundle target and react from npm? would love a simple hello world, or perhaps the flappy bird repo updated for bundle


You can try as a simple hello world. All you should need to do is add React to the package.json, run npm install and then require it in and everything else should be setup.


I will actually update the template to default to this later this week.


There must be something about clojure reader conditionals that I’m not understanding, maybe regarding their use in macros. I have the following code in a macro; the java part of it, java.lang.Exception, is getting into my .js (compiled through shadow-cljs): (try [email protected] #?(:clj (catch Exception e# {:error (.getMessage e#) :pstate ~pstate}) :cljs (catch js/Error e# {:error (str e#) :pstate ~pstate}))))


@peterd reader conditionals are resolved at read-time, you cannot use them to emit conditional code in macros. the typical check is (if (:ns &env) :cljs :clj)


Oh, I see. Thanks!


Or, maybe I don’t see. Where do I put this ‘if’ ?


(try [email protected]
     ~(if (:ns &env)
        `(catch js/Error e# {:error (str e#) :pstate ~pstate})
        `(catch Exception e# {:error (.getMessage e#) :pstate ~pstate})


something like that

Jakub Holý (HolyJak)18:05:59

There is a library for helping with that, can't remember the name. Maybe @UCFG3SDFV know?


That would be good to see.


Ah, I see. And it uses a namespace “being.john” 😄

Adam Helins18:05:33

Understand reader conditionals is a bit tricky in that regard. Using them in a macro is only useful when you use self hosted CLJS. What Thomas suggests is using a little trick, knowing that when a macro expands code for CLJS, its &env value contains :ns.


Agreed. Tricky.

Adam Helins18:05:46

So yeah, Macrovitch is a lib that leverage that, and this one as well but a bit differently : (it tries to distinguish even between CLJS for dev and CLJS for release)

Alex Miller (Clojure team)18:05:07

the key shift in thinking is that macros are about WRITING code so you need conditional write, not conditional read

👍 4

Yes, and the &env trick is about the time of the evaluation of the conditional to perform the write, I suppose.


@UCFG3SDFV your library gets right to the point. Thanks!

🙏 2

What reason might a file of macros not find something like printf? I get Use of undeclared Var cljs.core/printf


cljs doesn't have a printf


My mistake. Googling I found it defined in the clojure/clojurescript repository. But didn’t notice that I was looking at a view from 2013!


What should I be looking at for space-efficient Clojurescript serialisation? I’m currently using edn, but it’s creating files which are rather too big for comfort. I’m aware of Transit, but the documentation suggests that it’s not ideal for data which needs to be stored durably (which I do need). Nippy doesn’t support Clojurescript. Is there anything else that I should be looking at?


What size are you talking about? And can you use a database?


The data is of the order of 10s to 100s of megabytes when serialised (much less when in RAM).


I could use a database, but right now the data is just files on an S3 bucket and I would rather keep it that way unless there’s a strong reason to introduce a database.


i'd say at the tune of 100s of megabytes you are firmly in database territory


at that point you really need random access to the data, or perhaps if you can partition it into multiple files and basically index it yourself


It should be fine to use transit as long as you use the very same library version and the same settings to both read and write the same file. As soon as the version changes or some config changes, all bets are off.


I see why you are thinking database, but these are "all or nothing" files (they're data logs from racecar telemetry, as it happens). The Clojurescript is mainly just passing them along to Vega for visualisation.


Thanks @U2FRKM4TW. It's the "all bets are off" bit that's worrying me.


another option is to just use edn and use something like gzip on the result


@U7RJTCH6J: that's where I suspect I may be headed. But I thought I'd check to see if there was a better option first 👍