Fork me on GitHub
#clojurescript
<
2019-08-19
>
Robert Brotherus10:08:15

I am using re-frame and lein figwheel. When I want to test some subscriptions or events from the repl, I need to require the re-frame namespace: dev:cljs.user=> (require '[re-frame.core :as rf]) dev:cljs.user=> (rf/subscribe [:posti-kioski-gui.sending/prices]) .... How can I perform the (require '[re-frame.core :as rf]) initialisation every time I run "lein figwheel" automatically?

Roman Liutikov10:08:23

@robert783 put user.cljs with that code on the classpath and it will be executed when build starts

Robert Brotherus11:08:19

Thank you! I added a new file src / cljs / user.cljs (I am not sure if this is equivalent of "on the classpath). As content of the file, I have:

(ns user)
    (println "Hello from user.cljs")
    (require '[re-frame.core :as rf])
    (require '[cljs.pprint :refer [pprint]]) 
This is partly successful since the message from println is printed. However, (rf/subscribe [:aaa]) gives error in"rf is not defined"

Roman Liutikov11:08:41

also put user.cljs under dev dir and add the directory to source paths for dev build, so you don’t include that into prod build

👍 4
Robert Brotherus11:08:17

Now user.cljs is at src_dev/cljs/user.cljs and I have added src_dev/cljs as source-path in :cljsbuild. Println gets executed there ok. The remaining problem is that any require-statements I execute in user.cljs do not seem to have effect on bringing those namespaces visible in the repl

thheller11:08:49

@robert783 move the require calls into the ns form like normal via :require

Robert Brotherus11:08:46

I have now in user.cljs

(ns user
  (:require [re-frame.core :as rf]))

(println "Hello from user.cljs")
Still I get error "rf is not defined" when I write in the repl dev:cljs.user=> (rf/dispatch [:aaa])

thheller11:08:00

note that you are in the cljs.user namespace

👍 4
thheller11:08:05

but you created the user ns

Robert Brotherus11:08:43

Thanks, now works! 🙂 So in user.cljs I have now

(ns cljs.user
  (:require [re-frame.core :as rf]))

Robert Brotherus11:08:17

For some reason my IDE (idea + cursive) still gives me error about "Namespace name does not corrspond to filesystem hierarchy" (although the code works). Based on the namespace cljs.user, Cursive would like now to move user.cljs to src_dev/cljs/cljs/user.cljs (since I have src_dev/cljs as source path. If I move user.cljs there, Cursive is satisfied but the code is not loaded any more at startup. I can live with this Cursive error.

mfikes12:08:24

@robert783 Perhaps you can make Cursive not complain by writing the code as

(require '[re-frame.core :as rf])
(The default namespace for that file is cljs.user.)

👍 4
✔️ 4
grav19:08:22

Someone somewhere mentioned that a compile-to-wasm language with Clojure-like syntax might be a good thing for a subset of Clojure’s features, and without GC (as far as I remember). Is there a discussion going on about this anywhere?

cultofmetatron19:08:48

lisp without a GC is such a weird thing for me considering lisp was the first language to have a gc

dnolen19:08:00

@grav not that I'm aware of but it's likely I might work a bit on that in the near future as it would be best if the results could be easily integrated with the ClojureScript compiler

dnolen19:08:32

but GC in WASM is not off the table either - there's a ton of design work to do before trying anything

grav20:08:44

@dnolen Great to hear! You have my moral support for both 🙂

grav20:08:01

If you do any posts or similar on thoughts or progress, I’d be eager to check it out.

borkdude22:08:55

how can I print the js code of a function, like it used to work in the CLJS repls of olden days?

mfikes22:08:56

@borkdude (set! *print-fn-bodies* true)

borkdude22:08:53

I tried that, but I'm getting:

cljs.user=> (set! *print-fn-bodies* true)
true
cljs.user=> f
#object[cljs.core.MetaFn]

borkdude22:08:52

ah:

cljs.user=> (with-meta (fn []) {:a 1})
#object[cljs.core.MetaFn]

mfikes22:08:04

My guess is that older REPLs printed meta fns that way as well

mfikes22:08:06

(.-afn (with-meta inc {:a 1})) might be a suitable workaround

borkdude22:08:52

yeah, that works, thanks

cfleming23:08:12

Following up on @robert783’s question earlier and thinking about it a bit, is it the case that although the default ns for CLJS is cljs.user the compiler expects that file to be in user.clj? If so, I’ll need to add an exception to that error check.

mfikes23:08:15

@cfleming yeah, but the file is actually user.cljs or user.cljc

mfikes23:08:48

So theoretically Cursive’s exception would allow any ns form in that file

cfleming23:08:27

Oops, sorry, yes, cljs or cljc of course.

cfleming23:08:32

I guess the same is probably true of Clojure, and I shouldn’t warn in any user.clj[sc]? file.