Fork me on GitHub

How do you invoke an es6 static class method from ClojureScript?


@oliver.mooney Is this what you're asking?

class Foo {
  static bar() {


(.bar js/Foo) ;; logs "baz"


"Everybody using reagent was mind blowing, you write functions, and functions make the UI, it's a beautiful world!..It's no wonder that it's just blew up. within 4 months, everyone in ClojureScript was using react we're adopting react before JavaScript was adopting react"


I have a cljs fn that takes a javascript object instance as an argument. I want to call a method on the instance from cljs, but advanced optimizations shortens the method name


(fn [my-instance] (.sayHello my-instance))


Is there a simple way to tell closure compiler not to shorten sayHello?


Right, but how do I tell the compiler what my-instance is in this case?


I feel like I’m missing something obvious


(fn [^js my-instance] (.sayHello my-instance))


I love this kind of assertion from Ruby Rspec: expect { some_side_effectful_code }.to_change { some_variable }.from(:foo).to(:bar) That's a stronger assertion than the more typical


expect(some_variable).to equal(:bar)

Because one asserts cause-effect relationship between excercised code and expected values. At work we use cljs.test. What's the cheapest (i.e no framework swap) thing we can bring for getting this kind of assertion?


what does it mean to “change a variable” in this context?


@tatut better worded: the return value of a piece of code


was thinking, this assertion would be trivial to implement api:

(expect some-side-effectful-fn
        :to-change get-counter
        :from 1
        :to 1)


impl would simply invoke cljs.test (is (= ...)) which you absolutely can do programatically


so expands to something like (let [old-value (get-counter)] (some-side-effectful-fn) (let [new-value (get-counter)] (is (= old-value 1)) (is (= new-value 1))) ?


I think the plain cljs test version using let is pretty simple, if you don’t need it often


anyone about who uses the Klang library?


started seeing “Uncaught ReferenceError: React is not defined” errors that seem to be coming out of the Klang initialisation code.


not sure what i might have done that could trigger that


@tatut yeah exactly


we had be using this pattern (or similar) with cljs.test from time to time - so worth abstracting away in our case!


@sandbags Do you have react loaded before klang?


@rauh i assume so, i’m not really clear how i would affect that (since this was working)


sorry, useful context, i am using re-frame


So it was working before, but now not?


In a dev environment?


i’ve been using it for months, not seen this before


Did you upgrade re-frame or reagent? Maybe they're using npm nowadays and don't define the global react anymore?


no, not upgraded either


the google dependency code seems to be referencing React via cljsjs at least as far as i can tell. I’m not sure how the dependency order is calculated or why anything I might do would change this.


i mean, React is definitely there or none of the re-frame code would work


grr… pulling all the calls to info! would be a pita


@sandbags I should probably change the code of klang to not require React upon loading the namespace and lazy initing everyting. I'll do it real quick


@rauh ah, sorry i didn’t put two and two together … so first of all, thank you for Klang!


i was in the middle of writing a Github issue … is it worth continuing with that?


@sandbags Not unless you have info about why React isn't defined. I completely leave that up to the user.


But I agree that I shouldn't make calls to js/React unless you actually show the overlay.


So later on in time...


I have no insight whatsoever into why React isn’t defined 🙂


@rauh the error is different now, there is less to the stack trace but it’s still there… 🙁


@rauh klang.core:50 (def h js/React.createElement) is what’s causing it now


it’s really weird the way this has popped up


besides at the point where I :require [klang.core] i should have thought React would be available


Also listen to Tony Kay's episode, where he discusses the other side of Reagent. Good to know the pros and cons. "Reagent doesn't lend itself to simplicity."


@ajs, reagent as opposed to which alternative?


@pesterhazy he was comparing it to two other libraries, Om Next and Rum


mostly Om Next though


@jeaye There is now a patch in which, if things went that way, would have at least saved you some time by warning about instrumenting multi-arity functions.


I'm running boot cljs and getting the following error:

boot cljs
Writing main.cljs.edn...
Compiling ClojureScript...
• main.js
         java.util.concurrent.ThreadPoolExecutor$  624
          java.util.concurrent.ThreadPoolExecutor.runWorker 1149
                        clojure.core/binding-conveyor-fn/fn                     core.clj: 2027
                              adzerk.boot-cljs/compile-1/fn                boot_cljs.clj:  160
                                   adzerk.boot-cljs/compile                boot_cljs.clj:   72
                                          boot.pod/call-in*                      pod.clj:  413
org.projectodd.shimdandy.impl.ClojureRuntimeShimImpl.invoke  102
org.projectodd.shimdandy.impl.ClojureRuntimeShimImpl.invoke  109
                                          boot.pod/call-in*                      pod.clj:  410
                                      boot.pod/eval-fn-call                      pod.clj:  359
                                         clojure.core/apply                     core.clj:  657
                         adzerk.boot-cljs.impl/compile-cljs                     impl.clj:  156
                            adzerk.boot-cljs.impl/dep-order                     impl.clj:   36
               adzerk.boot-cljs.impl/cljs-depdendency-graph                     impl.clj:   29
                                        clojure.core/reduce                     core.clj: 6753
                                clojure.core.protocols/fn/G                protocols.clj:   13
                                  clojure.core.protocols/fn                protocols.clj:   75
                         clojure.core.protocols/iter-reduce                protocols.clj:   49
            adzerk.boot-cljs.impl/cljs-depdendency-graph/fn                     impl.clj:   30
                      adzerk.boot-cljs.impl/ns-dependencies                     impl.clj:   23
                                  cljs.analyzer.api/find-ns                     api.cljc:  163
  java.lang.AssertionError: Assert failed: (symbol? sym)
clojure.lang.ExceptionInfo: Assert failed: (symbol? sym)
    line: 104
I'm 99% certain that this is NOT an assertion I wrote, but some assertion somewhere in cljs/boot code. Is there a way to get the name of the file it was processing when this error occured ?


@mfikes Yep, I've been following. Thanks for the patch. Either support for this or a diagnostic would've solved my problem, so what you've done is good by me! Thanks again.


Someone around here might know! (even if not, this might interest you)


I'll ask here: I've been using goog.i18n libs to format dates. The issue I'm having is that it seems to be forcing american style dates, even when I have English (UK) at my most preferred language in chrome and the header my chrome produces is Accept-Language: en-GB,en-US;q=0.8,en;q=0.6


@roklenarcic, unfortunately, this may not answer your question, but just in case: as a workaround, you might consider using the cljs-time lib. It provides a lot of flexibility in formatting dates, and lot of out-of-the-box formatters too.


thanks will check it out


So the british locale should be preferred, but it isn't?


Hi all. Experimenting with an integrated clj/cljs/js environment. Basic story I'm trying to implement is to get code written in js to easily consume cljs namespaces. To that end I've been using the techniques described here under the section "Google Closure Compiler Compatible Code". This leads to a very simple example:


js.lib.debugMessage = () => {
I have two basic questions: 1. Is there any other way besides marking a var as ^:export in cljs to properly resolve a cljs some_cljs_var in js? It's a little annoying to have to re-define a js api with ^:export and underscores. 2. What is the recommended way to consume cljs objects in js? Like if I have a configuration map stored as a var in cljs, and want to use that in js? I know about clj->js but not quite sure how to use that in js. Or maybe there's another approach altogether?


Was the way macros are done in cljs changed recently? I remember hearing something about that?


@roklenarcic no, nothing changed recently.


@zalky what are you trying to do exactly? dont need the ^:export. not sure what you mean by the “underscores”, JS can’t have - in names so its converted to _ in JS always.


I think one way around ^:export would be to manually set! interesting functions on some global object, for example js/window and at that point you have a chance to rename them to javascript convetions


@zalky When using ^:export you shouldn’t have to rename in order to introduce underscores. See


@thheller: I'm trying to consume cljs functions and vars from within js code. I'm experimenting with a build that would allow js developers to participate in a project, mostly working on view related code. My minimal example above shows the basics of the approach I'm trying. As far as I know, in order to guarantee the name of the compiled cljs var (ie: once it's compiled to js) is to use ^:export. And because, exactly as you say, js can't have -s, they need to be replaced, conventionally with _, but I suppose you could also use camelcase. To be honest, the ^:export is only a minor annoyance. What I'm much more interested in is what the best approach is for passing data back and forth between the cljs and js.


@zalky I would go with ^:export and go with the convention that all of the arguments and return types are just JavaScript objects (and force the ClojureScript side to do the JavaScript interop.)


@mfikes: thanks! That's very helpful. What about if you have some cljs object defined in a var, (like let's say an ontology map or something) that is also being used by the cljs side?


I suppose i could just re-def the var.


Perhaps use clj->js before returning it to JavaScript


Otherwise if it needs to be simultaneously accessed from both sides, I’d keep it as JavaScript if possible.


I would do the same as @mfikes, but instead of ^:export I would write a macro which would walk interesting namespaces and emit a js object which would act as a namespace for collected functions, in that namespace I would camelCase the names for convenience of my js devs, I would set that object as global, for example to window.myAPI


Do you think that doing something like:

(def cljs-map
  {:this "that"})

(def ^:export js-map
  (clj->js cljs-map))


Would be a bad approach? On the one hand, it's manual work, on the other, it explicitly enumerates the js api.


Hi, this seems like a simple question but I’m having a hard time finding an answer…Can I use a normal clojure library in clojurescript? For example, I would like to use reduce-fsm ( in my current project


@U0HF3QKAM: Unfortunately I don't think there is. However, there is a great FSM library called automat that works in both clj and cljs.


That’s actually the first one I came across, but the repo is “archived”. I wasn’t sure if that meant it was basically abandoned, or if it was just “done” 🙂. I’ll take a look though if it works in cljs. Thanks for the heads-up!


for reduce-fsm specifically, it looks like a lot of the usage is via macros, which you can use from javascript clojurescript


but in general, unless the library is using cljc files, it won’t be available to clojurescript and clojure


I just would like to add that in some cases like core.async not all functions from clojure are also available in clojurescript. And for some libaries there are clojurescript alternatices with the same fuctions. Like spec. Which you might use in a cljc file like: (:require [#?(:clj clojure.spec.alpha :cljs cljs.spec.alpha :default clojure.spec.alpha) :as s])