ClojureScript builds on, and ships with, the Google Closure Library (GCL), a general-purpose JS library of utility functions. The library cover a vast area, from JS data types to various Browser APIs. The API docs are comprehensive but lack discoverability. So let’s make a list of the most useful functions in this thread.
What are your favorite GCL functions — the library’s hidden gems?
(goog.object/get m k) won’t throw, even if k is not in m or if k or m are nil. You can also supply an optional third argument to specify a default value, if the key is missing.
Next, and similar to clojure.core/get-in, goog.object/getValueByKeys allows nested property access. Note, however, that unlike get-in, it expects each key as a separate argument:
cljs.user=> (goog.object/getValueByKeys #js{"a" #js{"b" 123}} "a" "b")
123
Especially when working with something like React, goog.async.ConditionalDelay is a useful way to wait for dynamic nodes to appear in the DOM. E.g. to scroll a node into view:
We found goog.dom.classlist to be very handy for manipulating class-strings on dom elements and goog.positioning for doing all sorts of positioning and attaching elements like popovers and the like.
Positioning looks interesting — how do you use this for popovers etc? Absolutely positioned element appended to the end of the body, then figure out what to put on top, left?