clojurescript-site
clojurescript-site copied to clipboard
Improve section on Google Closure import and require
I've just had to use Google Closure directly for the first time, and I found it difficult to understand the nuances in order to get things working properly on a real project even after reading all the documentation and linked blog posts. The areas that were unclear to me:
- Format to import in a namespace - surround with
[ ]
,( )
, or nothing - particularly when importing multiple dependencies. - How to use import when importing multiple namespaces -
(:import [goog URI OtherNS])
- the examples didn't explain this clearly to me. - Name collisions - for example, OpenLayers has classes
ol.source.Vector
andol.layer.Vector
- What is the recommended way to work with these? Is there a way to import classes with a namespace to distinguish these? - How to use things after importing or requiring them in JS interop -
URI.
orgoog.URI.
- this is laid out in a limited form, but I think an example of more extended interop would be very useful. - More specific documentation, perhaps with examples, of how to tell whether things are a Closure class or not.
I also think it would be worthwhile to better explain the benefits of using import
over require
, but with the caveat that everything will still work fine if you just require
everything - it may allow other beginners to this part of ClojureScript to get thing working quickly and improve or experiment as they understand things better.
I'm planning to work on a PR for this.
@smahood cool, though we might want to divy up some of this work ;)
@swannodette I'm all for that - my deep dive into Google Closure keeps getting delayed by other work, but it's still on my radar. If someone beats me to any of these I'll have no complaints :)
Given:
- There is no doc for
ns
(since it's not a macro as it is in clojure)** - There is quite a few differences to clojure
we should probably add a new page to the "Reference" section on the site (maybe call it "Namespaces"?). There has been quite a few questions about it on Slack.
It should probably include:
-
clojure.core.async
(or anyclojure.*
) gets automagically renamed tocljs.core.async
. -
:require-macros
(and move the section from "Differences" to the new page with a link to it). - Automatic resolving of macros when the CLJ + CLJS namespaces are the same.
- Other?
**: Or should there be so Cursive and other editors can pull documentation for (ns ...)
?
@rauhs this all sounds reasonable to me.