Fork me on GitHub
#clojurescript
<
2017-06-09
>
mfikes01:06:07

@michaelmrose I haven't scrutinized the birch script you referenced (it is not immediately clear to me if it trying to be lazy), but it is the case that ClojureScript doesn't have locals clearing. More info here http://blog.fikesfarm.com/posts/2016-01-15-clojurescript-head-holding.html

michaelmrose02:06:01

Thanks @mfikes interesting read

qqq03:06:13

When using reagent/om, is there a way ot "preload" images? Right now, images appear to be loaded WHEN THEY ARE NEEDED ... which sometimes causes delays / flickers. When I know for a fact that I will need an image, is it possible to pre-load it (without displayint it) ?

dnolen06:06:08

@weavejester what do you mean by “finding out more” about an analysis error?

osmirnov06:06:11

Hi all, maybe some one can help me... How i can provide check for undefined prop in js obj? I've try something like this (if (= (aget jsobj prop) nil/"undefined")) but it doesn't works 😞

thheller06:06:41

otherwise js/undefined should work

osmirnov06:06:22

@thheller Thanks! Will try now.

rauh06:06:00

@osmirnov You have the choice:

(exists? (.-fooo js/window))
(js-in "fooo" js/window)
(undefined? (.-fooo js/window))

sophiago07:06:57

When calling js from a macro do I have to ns qualify it somehow in order for it to see the actual DOM? I'm getting errors like document.getElementById(...).width is not a function

thheller07:06:49

@sophiago looks like you are emitting code that wants to call that as a function and not a property access

thheller07:06:15

if you emit (js/...) that is already namespace qualified as far as the macro is concerned

sophiago07:06:37

Ah, ok. I don't do much js interop in general and haven't had to query an element's width/height before.

sophiago07:06:54

But isn't it the other way around? i.e. this is a case of property access?

thheller07:06:09

hard to say without actual code

sophiago07:06:27

.width and .height are properties whereas .getElementById() is a function. So it seems properties are what you qualify with (js/...)

thheller07:06:54

(-> (js/document.getElementById "foo") (.-width))

thheller07:06:16

that would be the code you’d need to emit

thheller07:06:46

not sure why you are in a macro for this though?

sophiago07:06:20

Thanks, I think that should help a lot. Lemme give it a try

sophiago07:06:53

Looks good 🙂

gv08:06:48

Hello. Is there information how the (cljs-repl) in figwheel (chestnut) works? I have a raspberry pi development scenario where I develop on my laptop but run the leiningen repl remotely on the raspberry pi. The cljs-repl isn't able to connect in this case. It just hangs.

sophiago08:06:54

@gv I'm not sure, but have you tried pointing your browser at localhost:3449/index.html?

sophiago08:06:59

It's been a long time since I've had to deploy cljs and I've either totally forgotten how to get it to compile to one js file or it's not doing it automagically since I didn't have my project.clj set up for figwheel back then. Would anyone mind reminding me how to go about this, i.e. without needing a dependency on /goog?

gv08:06:27

yes, I visited raspberrypi:3449/index.html in the browser on the laptop which shows the example page

gv08:06:10

I have the suspicion that I need to run a browser on the raspberry pi...

sophiago08:06:20

Oh. Sorry, it's quite late here and I didn't read close enough to see you're developing on your laptop. I'm really have no idea about a workflow like that.

dominicm08:06:29

@gv I believe you can configure where the websocket will connect to 🙂

rauh08:06:39

Yes that's true. Use figwheel.client/start with {:websocket-url ""} as the param.

gv08:06:18

is there any background information on that?

nikki08:06:30

do i need to do something with a namespace before i can eval in it

nikki08:06:48

(trying to create a new namespace with (create-ns (gensym)) and then eval'ing in it)

thheller08:06:07

@nikki can’t do that, you need an actual CLJS ns for that

nikki08:06:24

is a (create-ns ...) not an actual CLJS ns?

thheller08:06:35

no thats clojure

nikki08:06:37

i guess namespaces go off goog.blah in the compilation

nikki08:06:54

was hoping to create reified namespaces to eval in lolz

nikki09:06:53

it also needs to know at compile time whether a name resolves to a var right? like that isn't latebound

thheller09:06:22

well you’d get warnings otherwise but yes

nikki09:06:31

i guess i could look at teh form and resolve things at eval time ;O

gv09:06:26

I am not sure that :websocket-url is what I am looking for. The remote nrepl should be the websocket host as far as I can tell and that is the default

nikki09:06:35

@thheller if you're familiar with http://www.selflanguage.org -- they implement "messages" for objects by basically sort of eval'ing in the scope of an object (as a reified namespace sort of) but objects also inherit names from parent objects

thheller09:06:58

nikki: not familiar no but sounds like a REPL?

thheller09:06:37

well except for the save part

sophiago09:06:33

I've tried to abuse namespaces before as well and feel like how Clojure overloads them sort of invites that. But Self is quite different. It's a prototype based OO language (like how OOP began with Smalltalk, or these days in Lua or JavaScript). Alan Kay did get the idea from Lisp, though. It's quite simple to polymorphism via message passing in Lisp (although I think Clojure protocols are a huge step forward).

sophiago09:06:25

Here you go 🙂

(defn make-from-real-imag [x y]
  (fn [op]
    (cond (eq? op 'real-part) x
          (eq? op 'imag-part) y
          (eq? op 'magnitude) (sqrt (+ (square x) (square y)))
          (eq? op 'angle) (atan y x)
          :else (println (str "Unknown op -- MAKE-FROM-REAL-IMAG" op)))))

sophiago10:06:23

That's an "object" implemented with message passing style, i.e. dispatches to different operations by passing their name as a symbol, that converts between complex numbers in polar and rectangular form. Ported from Scheme.

nikki17:06:22

nice @sophiago :D but ya i mean having "eval" inside an object where the locals are the objs locals plus parent stuff... haha

nikki17:06:29

could be weird n cool

sophiago00:06:39

The snippet above is message passing style, which you can see achieves pretty much the same result as Clojure's protocols. Sounds like you just mean a prototyping language. Doesn't make much sense to implement one in Clojure, but I'd think the best way to do it would be with continuation passing style (I've used ad hoc continuations in Clojure projects before and seem to remember David Nolen having a delimited continuation library).

gv09:06:55

I guess, I have to open the page on a browser on the raspberry then...

rauh09:06:33

If you open the browser on your laptop it needs to connect to the RP, so you should give it the IP of the RP

rauh09:06:40

The default port is 3449 IIRC

gv09:06:49

@rauh: ah right. so the default isnt derived from the other :host options? I already specified the host for the jetty server in project.clj

gv09:06:42

@rauh: thank you

rauh09:06:53

Yeah I'm not sure, figwheel does get the port automatically and it should work. See the code in figwheel.cient.

rauh09:06:13

The Jetty shouldn't have anything to do with the host/port. That's your server I assume?

gv09:06:08

@rauh: sure, it is the server and I had to provide the IP there to be able to access it remotely 😉 I'll try the :websocket-url configuration later. thank you

sophiago09:06:45

I should probably try asking this again... It's been a long time since I've had to deploy cljs and I've either totally forgotten how to get it to compile to one js file or it's not doing it automagically since I didn't have my project.clj set up for figwheel back then. Would anyone mind reminding me how to go about this, i.e. without needing a dependency on /goog?

dominicm09:06:30

@sophiago should happen if you set the :optimizations to :advanced for your production build

sophiago09:06:07

@dominicm do you mean in something like a release.clj or in project.clj?

sophiago09:06:07

I've tried both (using figwheel, cljsbuild, and running the release.clj with java -cp) and it still needs at least a goog 😕

sophiago09:06:53

Although with the release.clj method I wasn't certain I was specifying the main class correctly given I don't have a main function

dominicm09:06:55

I don't really understand.

sophiago09:06:11

The command I'm using is lein cljsbuild once and I do have :optimizations :advanced set

pradyumna11:06:27

@gv by default figwheel will connect to localhost:3449, but you can override in your project.clj . Add the :websocket-host option for figwheel configuration. For example:

:cljsbuild
  {:builds
   [{:id "dev"
     :source-paths ["src/cljs"]
     :figwheel {:websocket-host :js-client-host
                :on-jsload "my-app.core/on-js-reload"}
     :compiler {:main my-app.core
                :output-to "resources/public/js/dev/app.js"
                :output-dir "resources/public/js/dev/out"
                :asset-path "js/dev/out"
                :source-map true
                :source-map-timestamp true
                :preloads [devtools.preload]
                :external-config {:devtools/config
                                  {:features-to-install :all}}}}
:js-client-host is of special meaning for figwheel. This will tell figwheel to connect to the same host as the current page is running. So if you have opened raspberrypi:3449/index.html, it will connect to

macluck12:06:31

Hey! Does any one have an idea what could be wrong here? I am sending request in transit format with cljs-ajax with data containing a sequence. There are no problems in dev environment. However, in production it fails with exception in transit-cljs: Uncaught Error: Cannot write Function . Looks like this is related https://github.com/cognitect/transit-cljs/issues/30 . But things get even more weird, when i try to run production build locally, no exception is thrown

Roman Liutikov15:06:41

Digging into CLJS analyzer stuff. How can I eval a form from within a macro?

Roman Liutikov15:06:46

Given this snippet. How do I analyze/resolve/eval (inc val) form?

(def val 1)
(mymacro {:key (inc val)})

lvh15:06:45

(ns-)resolve will do that for you

lvh15:06:51

if you just want the val

lvh15:06:11

if you wnat to evaluate the entire thing, why not just return the form? that;s what clojure does anyway

Roman Liutikov15:06:44

I guess if a form makes use of a var from another namespace resolving will fail.

lvh15:06:44

derp, sorry; I just realized you said cljs-analyzer and completely misunderstood your question, because I’m in the wrong slack channel

Roman Liutikov15:06:25

So when I run analyzer on a form which uses vars from another ns I get errors about those vars are missing.

Roman Liutikov15:06:46

For context: I'm trying to eval a form to see if I can retrieve a value statically.

chrisdavies16:06:16

Does anyone here know a good way to get lein doo test to print out colors green/red or something other than black and white?

chrisdavies16:06:44

But it seems to be pretty much unmaintained. Curious if there's something everyone else is using for this that I'm unaware of.

dm317:06:30

what’s the fastest mutable map-like thing in cljs? Plain #js {}?

dnolen17:06:39

as long as you’re ok with strings keys yeah - otherwise Map if available

dnolen17:06:08

@roman01la what does that mean?

Roman Liutikov17:06:36

A macro accepts a form which has a var from another ns. Is it possible to evaluate this form in a macro so that I could retrieve result at compile time.

Roman Liutikov17:06:49

Basically do function call inlining.

dnolen17:06:11

@roman01la yeah I do not understand

dnolen17:06:25

how can you evaluate CloureScript in JVM?

Roman Liutikov17:06:28

Hm. Even if there's nothing cljs/js specific?

dnolen17:06:17

@roman01la then why not just call Clojure eval?

chrisdavies18:06:04

Followup on my previous question... how are you all testing ClojureScript code? Do you just use clojure.test, or is there something with more assertions, color-coded output, etc that you use?

Roman Liutikov19:06:10

@dnolen not sure if this would work if the form includes a var from another ns

mobileink21:06:22

roman01la: did u get this working? i had a similar situation, which i solved by using (bind [*ns* foo.bar]... ) plus some require statements.

shaunlebron21:06:35

@chrisdavies idk what people are using to prettify test output, would be great to get a PR for that in doo

metametadata22:06:12

@chrisdavies I use clojure.test and lein-doo and am also curious how to make assertion reports more readable.