clojurescript-site icon indicating copy to clipboard operation
clojurescript-site copied to clipboard

Improve section on Google Closure import and require

Open smahood opened this issue 7 years ago • 4 comments

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 and ol.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. or goog.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 avatar Mar 06 '17 16:03 smahood

@smahood cool, though we might want to divy up some of this work ;)

swannodette avatar May 19 '17 20:05 swannodette

@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 :)

smahood avatar May 19 '17 20:05 smahood

Given:

  1. There is no doc for ns (since it's not a macro as it is in clojure)**
  2. 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 any clojure.*) gets automagically renamed to cljs.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 avatar May 26 '17 13:05 rauhs

@rauhs this all sounds reasonable to me.

swannodette avatar May 26 '17 14:05 swannodette