Fork me on GitHub
#clojurescript
<
2017-10-07
>
Bravi00:10:17

Hi everyone. Does format function not work in ClojureScript?

lincpa10:10:38

Java's String.format() compatible string formatting library for JavaScript. https://github.com/madogiwa/format4js

genekim04:10:59

Or use the format function from Google Closure library, which has worked great for me. See answer here — which is where this example comes from: https://stackoverflow.com/questions/34667532/clojure-clojurescript-e-g-the-format-function

(ns rostering.components.services
  (:require 
    [goog.string :as gstring]
    [goog.string.format]))

(str "$" (gstring/format "%.2f" 2.5))

paytonrules18:10:28

As you’ve probably gathered Bravi - it does not.

Bravi00:10:20

Basically, I have this line

[:p (format "Your score is: %d" @score)]
and doesn’t seem to work

lovuikeng00:10:44

do instead, [:p "Your score is: " @score]

mfikes01:10:19

@bravilogy there is a format function in Google Closure Library

lovuikeng02:10:57

thank you for tips, @mfikes , a bit of require setup

(:require [goog.string :as gstring]
          [goog.string.format]			
(gstring/format "Your score is: %d" @score)

danielcompton03:10:58

goog.string.format has significant dead code elimination issues, I think it was removed from cljs for this reason

danielcompton04:10:20

You can also use it directly, I misspoke above, cljs.core/format (which used goog.string.format) was removed from core. You can still call goog.string.format yourself

danielcompton04:10:28

But be aware of DCE issues

lovuikeng04:10:09

True, @danielcompton cuerdas makes use of goog.string but does its own format

ajs05:10:02

I’m having an unusual problem with lein cljsbuild auto that I’ve not had before. It will automatically compile upon save and show that is Successfully compiled in around 1.X seconds. But this message doesn’t actually appear for about 10 seconds. Anyone else seen this recently with recent versions of the compiler?

ajs05:10:30

I wonder what it is doing in the many seconds after the apparently successful compile?

Bravi09:10:56

is there a reason the built-in format doesn’t work?

Bravi09:10:09

I mean it works in repl, but not when using with re-agent

Bravi09:10:15

or rather, with clojurescript

lovuikeng09:10:49

Sorry, @bravilogy clojurescript removed format since v0.0-1885 https://cljs.github.io/api/cljs.core/format

Bravi10:10:28

I didn’t realise clojurescript had different api docs

Bravi10:10:35

that makes sense now 🙂

Bravi10:10:30

P.S. how difficult is it to deploy clojure / clojurescript application?

Bravi10:10:33

I’m still new at this

Bravi10:10:22

does it work the same way as node? In a sense that do I need to redirect connections from my nginx server?

lincpa10:10:38

Java's String.format() compatible string formatting library for JavaScript. https://github.com/madogiwa/format4js

lincpa10:10:48

This JS library lets clojurescript and clojure's format function remain compatible

lovuikeng11:10:47

@bravilogy using lein to create an uberjar... here can follow re-frame-template https://github.com/Day8/re-frame-template

$ lein new re-frame myapp +handler
$ cd myapp
$ lein uberjar
Compiling ClojureScript...
Compiling "resources/public/js/compiled/app.js" from ["src/cljs"]...
...
$ java -jar target/myapp.jar
2017-10-07 19:12:42.805:INFO::main: Logging initialized @2006ms
2017-10-07 19:12:42.855:INFO:oejs.Server:main: jetty-9.2.z-SNAPSHOT
2017-10-07 19:12:44.424:INFO:oejs.ServerConnector:main: Started ServerConnector@
3281dfc2{HTTP/1.1}{0.0.0.0:3000}
2017-10-07 19:12:44.425:INFO:oejs.Server:main: Started @3627ms

dominicm15:10:18

https://clojurescript.org/guides/javascript-modules#javascript-modules I can't follow this successfully. I did it all in copy/paste style & got: https://clbin.com/SIIVA am I doing something obviously wrong?

lovuikeng15:10:28

try require goog.object in your core.cljs

jeaye23:10:33

I have a barebones CLJS app, based on the figwheel + reagent template. I've added some :npm-deps, but I just can't seem to :require them.

jeaye23:10:38

I've followed every CLJS doc I've found regarding bringing in these NPM deps, which, as I gather, I'm meant to be able to require with no issue. Have I missed something?

genekim04:10:59

Or use the format function from Google Closure library, which has worked great for me. See answer here — which is where this example comes from: https://stackoverflow.com/questions/34667532/clojure-clojurescript-e-g-the-format-function

(ns rostering.components.services
  (:require 
    [goog.string :as gstring]
    [goog.string.format]))

(str "$" (gstring/format "%.2f" 2.5))