Fork me on GitHub
Tommy Jollyboat12:05:32

Total newbie here, using Electric Clojure. Project is using shadow-cljs if that's relevant. I can't figure out how to import or require goog.color from Closure Library. From what I understand, goog.* should be available by default with no need to install anything, but perhaps I'm wrong about this? I've made a minimal product, adapted from the example repo.

(ns app.todo-list
   [hyperfiddle.electric :as e]
   [hyperfiddle.electric-dom2 :as dom]
   #?(:cljs goog.color)))

(e/defn Todo-list []
   (dom/text "Mitt!")
   ;; hslToHex( h, s, l ) → string
   (dom/text (goog.color/hslToHex 0.5 0.5 0.5))))
The important bits are that I :require #?(:cljs goog.color) and that the (dom/text "Working!") works. Guarding the whole e/client with a CLJS only #?() proves that it's not CLJ that has the problem. Error is: No such namespace: goog.color, could not locate goog/color.cljs, goog/color.cljc, or JavaScript source providing "goog.color" I've tried placing it in a seperate (:import ...) block instead of (:require ...) . (edited to remove bug from code)


Actually, what you wrote seems to be pretty much on point and should work. Do you see an error somewhere or what?


Ah, 50 50 50 is invalid input to that function.

Tommy Jollyboat12:05:36

Oh, thanks!! Didn't see your reply immediately, I was editing the post (pressed RET by mistake). Should it be 0.5 ?


Read the docstring. :)

👍 2

But it has nothing to do with the "No such namespace" error.


I tried pretty much the same thing that you have, and also with shadow-cljs - and it worked just fine. No clue in which way your setup is different so that it doesn't work for you.

Tommy Jollyboat12:05:54

I see your point, changing the args to be correct has worked. Perhaps I was taking the wrong thing from the error... stacktrace or whatever the term is.

👍 2
Tommy Jollyboat12:05:26

Ah, they're warnings - I'm still getting :undeclared-ns and :undeclared-var, but it does work.


That is weird that you're getting them. Definitely a sign that something's not right.

Tommy Jollyboat12:05:30

Could it be my Clojure install somehow?

Dustin Getz12:05:53

I need to confirm, but I think you can't use #?(:cljs in e/defn

Dustin Getz12:05:18

Just don't guard it

Tommy Jollyboat12:05:36

that was there for testing, and I've since removed it

Tommy Jollyboat12:05:09

I presume e/client effectively does the same, or even just dom/*

👍 2
Tommy Jollyboat12:05:10

(Side-issue: I've found #C7Q9GSHFV now! Not used Slack before)

Dustin Getz12:05:42

Replicating your code in the electric starter app, I am getting JS errors in the console, bad usage of hslToHex

Dustin Getz12:05:45

I also replicate the warning

Dustin Getz12:05:12

Do you have a correct invocation now?

Tommy Jollyboat12:05:59

Yes! 0.5 instead of 50 for the args

Tommy Jollyboat12:05:33

well, or (1, 1, 1) would do fine

Dustin Getz12:05:47

It looks like the warning is on us, extracting #?(:cljs (defn foo [] (goog.color/hslToHex 0.5 0.5 0.5))) and calling (foo) from electric does not produce the warning

Dustin Getz12:05:12

I logged a ticket

Dustin Getz12:05:05

I also scanned our own codebases, all uses of goog seem to be from clojure not from electric

Tommy Jollyboat12:05:41

okay that makes sense 🙂 I was starting to think I might extract most of the logic into clojure defns anyway

Tommy Jollyboat12:05:51

Thank you for all your help, Eugene & Dustin!

🙂 2

is there a cljs nrepl client? I only see but is js not cljs


when and and looks so similar


(not= (when true false true) (and true false true))


To clarify a @U63D7UXJB's response a bit: For the when example

(when true false true)
when takes one conditional and treats everything after as the body. So this is equivalent to
(when true (do false true))
; => true
; false is eval'd into the aether, then true is eval'd and returned
The and example
(and true false true)
applies short circuiting to each expression in kind, so is equivalent to
(and true (and false true))
; => false
; false is returned, so the second true is never eval'd
--- Additionally, and returns a falsey conditional (which could be nil or false), while when always returns nil in the falsey case.
(when false true)
; => nil
(when nil true)
; => nil

(and false true)
; => false
(and nil true)
; => nil


Interesting point re falsy conditional, that's only false and nil natively right


Yes. Everything else is truthy