Fork me on GitHub
#shadow-cljs
<
2019-01-22
>
thheller11:01:50

@orestis there is something in the shadow-cljs devtools you might be interested in also. I never finished it but it is capable of compiling code on demand. if you have a running watch for a browser build try this in the browser console

thheller11:01:57

shadow.cljs.devtools.client.browser.compile("(prn :foo)", function(result) { console.log(result); })

thheller11:01:21

basically the compile function lets you request a compile on the server and you'll get the raw compilation results

thheller11:01:50

I could finish that to return the actual eval result instead

thheller11:01:09

saw you asking about self-hosted stuff and that is pretty close without any of the self-hosted parts

thheller11:01:52

limited to dev builds with a running watch of course but I was planning to use it to embed a REPL into the page directly and stuff

orestis12:01:50

I want to be able to show a textarea that people can type hiccup, and render it as it happens. Amazingly, you can go some way towards that using just cljs.reader/read and get some EDN back, that reagent will happily try to render — but in this case symbols get turned into strings, while I want to look them up in my actual build.

thheller12:01:30

yeah you could do that with the compile function in theory

orestis12:01:14

Does it return something now?

thheller12:01:58

yes. raw compilation results.

thheller12:01:44

its not exactly user friendly right now but you do get a :js field

thheller12:01:54

eg. :js "cljs.core.prn.call(null,new cljs.core.Keyword(null,"foo","foo",1268894036))"

thheller12:01:47

which you could eval

thheller12:01:09

(js/goog.globalEval (:js ...))

orestis12:01:50

This kinda works — but I don’t get anything back from globalEval, do I?

thheller12:01:06

you do get back whatever you eval'd

orestis12:01:31

I seem to get back undefined — but side effects like print work.

thheller12:01:51

prn returns nil

thheller12:01:06

try to compile("(fn [x] (+ 1 x))", ...)

orestis12:01:08

I’m trying

(shadow.browser/compile "(inc 1)"
                        (fn [result]
                          (let [src (get-in result [:actions 0 :js])
                                res (js/goog.globalEval src)]
                            (js/console.log src "=" res))
                          ))

thheller12:01:30

that should return something?

orestis12:01:44

And I see printed: ((1) + (1)) – "=" – undefined — I would expect to see a 2 somewhere.

orestis12:01:53

If I surround the (inc 1) with a prn, I do see 2 printed, so I think it’s something to do with JS not having expressions?

thheller12:01:56

try to compile (fn [] (inc 1)) that should give you back a function you can call to get the actual result

orestis12:01:35

Hm, that errors with: SyntaxError: Unexpected token '.'. Expected an opening '(' before a function's parameter list.

orestis12:01:48

The generated JS is:

(function cljs$user$cljs.user.cljs(){
return ((1) + (1));
})

thheller12:01:15

ah right its not compiled in the correct repl context

thheller12:01:49

ok I'll fix that later

thheller12:01:32

the compile is a bit too low level I guess 🙂

orestis12:01:52

Cool stuff though! This would fit my use case very nicely. I hope to be able to demonstrate/document that somewhere when it’s finished.

orestis12:01:15

I’m confused with how to update shadow-cljs — I do npm upgrade -g shadow-cljs and I did see

$ npm update -g shadow-cljs
/Users/orestis/.nvm/versions/node/v10.15.0/bin/shadow-cljs -> /Users/orestis/.nvm/versions/node/v10.15.0/lib/node_modules/shadow-cljs/cli/runner.js
+ [email protected]
updated 1 package in 12.434s
— but when invoking shadow-cljs again I still see 2.7.16…

leocardoso13:01:22

anyone already have this problem Error: clojure is not defined using :target :npm-module ? I'm using webpack too

thheller13:01:02

@orestis the global install is not relevant if you have (which you should) a version local in your project

thheller13:01:11

so npm install shadow-cljs in your project should update it there (without the -g)

orestis13:01:43

Ah, so the global install is just a nicety?

thheller13:01:45

@leocardosoti which version are you on?

thheller13:01:26

@orestis yes, pretty much only for CLI convenience but otherwise unnecessary. it will always use the version installed in your project

leocardoso13:01:22

@thheller latest

thheller13:01:09

it is most likely related to something using clojure.string (or similar clojure.*) directly without a require for it

thheller13:01:32

but the latest version should have relaxed that requirement as long as it was required somewhere

thheller13:01:59

yeah like that exactly

leocardoso13:01:04

but okay i'll try to update everything

thheller13:01:38

ensure that you have the latest version and restarted the server process after updating (eg. the watch)

leocardoso13:01:02

okay, thanks!

thheller13:01:38

as long as clojure.set is required somewhere before the re-frame stuff is loaded it should work

thheller14:01:21

@orestis FWIW it work if you use (js/goog.global.eval the-code). guess globalEval doesn't like return values