11

I want to write a Google Chrome extension, using ClojureScript. With ClojureScript I can use all the Google Closure libs, but afaik access to the Chrome browser is not included in those libs. So I want to wrap all the Chrome stuff in my own JavaScript lib.

So far I tried creating my own jar that has a single JavaScript file that just creates a Foo object and exports the constructor. I'v added this jar to the lib directory of the ClojureScript compiler (which also has for example goog.jar), but so far without luck:

Exception in thread "main" java.lang.IllegalArgumentException: No implementation of method: :-compile of protocol: #'cljs.closure/Compilable found for class: nil
at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:494)
at cljs.closure$eval1056$fn__1057$G__1047__1064.invoke(closure.clj:187)
at cljs.closure$get_compiled_cljs.invoke(closure.clj:422)
at cljs.closure$cljs_dependencies.invoke(closure.clj:440)
at cljs.closure$add_dependencies.doInvoke(closure.clj:462)
at clojure.lang.RestFn.applyTo(RestFn.java:139)
at clojure.core$apply.invoke(core.clj:602)
at cljs.closure$build.invoke(closure.clj:701)
at user$eval1246.invoke(cljsc.clj:21)
at clojure.lang.Compiler.eval(Compiler.java:6406)
at clojure.lang.Compiler.load(Compiler.java:6843)
at clojure.lang.Compiler.loadFile(Compiler.java:6804)
at clojure.main$load_script.invoke(main.clj:282)
at clojure.main$script_opt.invoke(main.clj:342)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:405)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)

Has anyone tried this before?

Maurits Rijk
  • 9,789
  • 2
  • 36
  • 53

2 Answers2

8

Take a look at this post from Luke Vanderhart: "Using JavaScript libraries in ClojureScript"

http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html

Also, this video from Kevin Lynagh: "Extending JavaScript Libraries from ClojureScript"

http://www.youtube.com/watch?v=XfzXFWTT-z0

Rodrigo Taboada
  • 2,727
  • 4
  • 24
  • 27
FreeAgent
  • 77
  • 2
  • 1
5

If I remember Rich Hickeys talk correctly the whole program optimization of the closure compiler needs any library code to adhere to certain coding conventions. I think he also said something of JQuery not doing this but Dojo doing this. I never did this but you might find some useful information here

msung
  • 3,562
  • 3
  • 19
  • 30
  • 1
    If that is the only problem, we should still be able use these libraries with lower optimization settings. Will try – Goran Jovic Aug 16 '11 at 10:08
  • The Jquery-wrapper jayq https://github.com/ibdknox/jayq elaborates this. However, the Closure-compiler makes the code more efficient, having external libs will be slower. – claj Aug 17 '13 at 08:16