Fork me on GitHub
#clojurescript
<
2021-05-15
>
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`

raspasov08:05:57

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

raspasov08:05:58

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

raspasov08:05:09

… from the REPL

λmmij14:05:57

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
Ale15:05:43

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')

raspasov15:05:05

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

Ale15:05:35

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.

Ale15:05:33

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/`)

thheller16:05:42

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

thheller16:05:58

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

Ale16:05:44

I see! that did the trick, thanks ^^

Ale16:05:14

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 https://dzone.com/articles/fun-with-react-a-quick-overview and a few pages from React's own tutorial (linked to from https://fulcro-community.github.io/guides/tutorial-minimalist-fulcro/index.html#_prerequisites) 🙏

dpsutton17:05:47

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

athomasoriginal19:05:15

You can try https://github.com/athomasoriginal/create-reagent-app 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.

athomasoriginal19:05:58

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

peterdee17:05:40

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}))))

thheller17:05:57

@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)

peterdee17:05:42

Oh, I see. Thanks!

peterdee17:05:50

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

thheller18:05:12

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

thheller18:05:14

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?

peterdee18:05:21

That would be good to see.

peterdee18:05:09

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.

peterdee18:05:15

Agreed. Tricky.

Adam Helins18:05:46

So yeah, Macrovitch is a lib that leverage that, and this one as well but a bit differently : https://github.com/helins/medium.cljc (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
peterdee19:05:51

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

peterdee19:05:28

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

🙏 2
peterdee18:05:28

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

thheller18:05:43

cljs doesn't have a printf

peterdee19:05:25

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!

paulbutcher21:05:33

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?

dpsutton21:05:28

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

paulbutcher22:05:25

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

paulbutcher22:05:02

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.

dpsutton23:05:37

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

dpsutton23:05:10

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

p-himik23:05:48

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.

paulbutcher23:05:03

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.

paulbutcher23:05:36

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

phronmophobic23:05:56

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

paulbutcher23:05:51

@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 👍