Fork me on GitHub
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?


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


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


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


note that you are in the cljs.user namespace

👍 4

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.


@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

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?


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


@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


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


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


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


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


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


I tried that, but I'm getting:

cljs.user=> (set! *print-fn-bodies* true)
cljs.user=> f



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


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


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


yeah, that works, thanks


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.


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


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


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


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