This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-04
Channels
- # adventofcode (161)
- # asami (2)
- # babashka (56)
- # beginners (128)
- # calva (57)
- # cider (10)
- # circleci (1)
- # clj-kondo (4)
- # clojure (13)
- # clojure-europe (44)
- # clojure-france (32)
- # clojure-italy (3)
- # clojure-nl (18)
- # clojure-spec (7)
- # clojure-uk (26)
- # clojurescript (18)
- # code-reviews (15)
- # community-development (7)
- # conjure (5)
- # cryogen (8)
- # cursive (31)
- # datomic (18)
- # emacs (8)
- # events (4)
- # figwheel-main (7)
- # fulcro (42)
- # juxt (3)
- # kaocha (58)
- # lambdaisland (1)
- # malli (1)
- # minimallist (1)
- # pathom (11)
- # pedestal (9)
- # re-frame (28)
- # reagent (20)
- # reclojure (4)
- # releases (1)
- # reveal (23)
- # schema (2)
- # shadow-cljs (7)
- # test-check (67)
- # xtdb (23)
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 :require
d 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!@paulbutcher I think format is a bit weird in how it's used
That I believe!
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!
OMG. And if I do that (change the :require
line to [goog.string.format]
and then call goog.string/format
it works fine 😳
Thanks!