figwheel-main

figwheel-main http://figwheel.org
paulbutcher 2020-12-04T11:22:13.156200Z

I fear I’m missing something really basic, but can someone help me work out how to call goog.string functions in a project compiled with auto-bundling? The problem seems to only be with goog.string - I’m able to call plenty of other Javascript functions. I can reproduce the problem in a toy example: 1. Create a project with lein new figwheel-main hello-world.core -- +npm-bundle --reagent 2. Edit core.cljs to add:

[goog.string :as gstring]
to the list of :required libraries, and then change hello-world to:
(defn hello-world []
  [:div
   [:h1 (:text @app-state)]
   [:h3 (gstring/format "The text reads: %s" (@app-state :text))]])
Building with lein fig:build works fine. Build with lein fig:min and it gives the following at runtime:
TypeError: f.format is not a function. (In 'f.format("The text reads: %s",r)', 'f.format' is undefined)
I’ve tried every :require variation and every combination of js/ or #js, and nothing I’ve come up with has persuaded Closure to leave the name alone. I’m sure I’m missing something really simple and obvious, but I’m damned if I can find it. Any pointers would be very gratefully received!

dominicm 2020-12-04T12:45:01.156800Z

@paulbutcher I think format is a bit weird in how it's used

paulbutcher 2020-12-04T12:46:09.158100Z

That I believe!

dominicm 2020-12-04T12:47:06.159500Z

https://google.github.io/closure-library/api/goog.string.format.html see how it's provide by "goog.string.format"? That means you also have to require goog.string.format. But requiring it mutates goog.string, so you still call goog.string/format. Confusing, right!

paulbutcher 2020-12-04T12:49:30.160300Z

OMG. And if I do that (change the :require line to [goog.string.format] and then call goog.string/format it works fine 😳

paulbutcher 2020-12-04T12:50:16.160900Z

Thanks!