Fork me on GitHub
#clojurescript
<
2016-08-12
>
isaac10:08:05

How ClojureScript new an object from an attribute of an object? eg: (new (.-Foo obj))

rarous10:08:51

@isaac: (new (goog.object/get obj “Foo”))

isaac10:08:05

got error clojure.lang.ExceptionInfo: First arg to new must be a symbol at line 1

isaac10:08:06

ClojureScript new not support expr

isaac10:08:05

It's ok, 🙂

rarous10:08:37

@isaac: try (let [Foo (.-Foo obj)] (Foo.))

joshkh10:08:18

try (js/someobj.SomeObjectConstructor. "param1") ?

joshkh10:08:50

(assuming someobj is on the window)

joshkh10:08:53

so in your case (obj.Foo.) note the trailing dot

isaac13:08:17

But my object not on the top layer of window?

isaac13:08:55

@rarous: thanks , it's ok

fenton16:08:21

with the new clojurescript spec, I can't use float? as a predicate. What should I use in it's place?

dnolen17:08:04

@fenton number? all numbers in JavaScript are doubles

dnolen17:08:42

the integer predicates are really for portability / convenience

fenton17:08:13

@dnolen: when sending stuff to the backend, via edn/read-string, etc... might be a chance that the JS double becomes an integer. So if require a float on backend...might have to ensure on JS side that any numbers that look like an integer, dont continue to look like an integer over EDN etc...???

fenton17:08:29

so i have a spec that is checked on JS side to ensure numbers dont look like integers and thus get converted to integers.

fenton17:08:43

homemade float'ish spec: (s/def ::flt (s/and number? #(not (integer?))))

dnolen17:08:32

@fenton: yeah that’s not going to be very reliable

dnolen17:08:44

since you may actually want 1.0 etc

dnolen17:08:09

if you want to communicate floats from a JS environment better to be explicit about it by wrapping it in a tagged value or using Google’s floating point types

dnolen17:08:36

anyways not much we can do about JS numerics, it is what it is

fenton17:08:39

@dnolen: I didn't realize (integer? 1.0) is true

dnolen17:08:02

because there is no such thing as integers in JavaScript

fenton17:08:36

shouldnt' that test to false tho? does in clojure.

fenton17:08:02

i would assume that the presence of a decimal takes it out of integer land...?

dnolen17:08:54

I trying to imply that such a predicate is in fact impossible

fenton17:08:58

but i guess i understand the difficulty...since like you say JS doesnt support.

fenton17:08:10

ok i understand...right.

dnolen17:08:24

integer? would be (defn integer? [n] false)

dnolen17:08:53

or (defn integer? (constantly false)) for functional goodness

fenton17:08:09

not so useful huh? lol.

dnolen17:08:26

still we do need more feedback about cljs.spec and numerics, I’ve punted on making hard choices for now - open to hearing more ideas

fenton17:08:29

@dnolen: cool, just starting to use it for that... I'll look into what you suggested about : "wrapping it in a tagged value or using Google’s floating point types" haven't used them before. Thanks as usual!! 🙂

krchia18:08:55

would anyone happened to know how to get all my javascript code in one file?

krchia18:08:29

i use chestnut, and i’m looking through the compiler options and im not sure what i should be looking for

dnolen18:08:26

@krchia: use :optimizations

dnolen18:08:38

:whitespace, :simple, :advanced all produce a single file

shaun-mahood18:08:35

@krchia: If you're using the current chestnut template, lein cljsbuild once min should output an :advanced optimizations js file to your resources/public/js/compiled folder.

krchia18:08:02

that might be it - i just noticed that one of my builds didn’t have :optimizations

krchia18:08:42

so i suppose i have got to learn how to use different builds -

krchia18:08:29

thanks shaun-mahood and dnolen 🙂

krchia18:08:45

i was just using lein cljsbuild once which i suppose defaults to build “app"

dnolen18:08:04

@krchia: the Quick Start covers the basic compiler options btw, might be worth reading through

dnolen18:08:14

it covers essential information needed to understand any build tool

plexus18:08:49

@krchia: chestnut also has its own forum/mailing list. You're welcome to ask questions there, we'll be happy to help you

krchia18:08:22

i think this was a most embarassing omission on my part to fail to read the quick start - but i am glad for the generous offer of help 🙂

dnolen18:08:52

@krchia: you’ll grow past at it pretty quick but it really it’s a 30 minute investment to avoid head scratchers down the road

dnolen18:08:12

most of the tools are much friendlier than the raw compiler, but when you’re in a bind understanding how the compiler works can help

krchia19:08:19

@plexus: not sure if this is a chestnut thing, but i couldn’t get my app to output the min file

krchia19:08:11

so i tried with a fresh chestnut build - i get the same errors as well, which is "ClojureScript could not load :main, did you forget to specify :asset-path?"

plexus19:08:42

That sounds like it might actually be using : optimizations :none, which means it will output one file for each namespace instead of one big concatenated one

krchia19:08:58

specifying the asset-path in build “min” also causes the same error

krchia19:08:17

am i doing it wrong, or shouldn’t it work right out of a fresh template?

plexus19:08:32

It should work, although I rarely test it that way. The main usecase we focus on is building an uberjar, which will include a fully concatenated optimizated js file

plexus19:08:53

You can try lein uberjar, that should create a minified js and leave it lying around

krchia19:08:25

you mean this?

krchia19:08:29

"lein with-profile -dev,+uberjar cljsbuild once” from the website

plexus19:08:37

just a second, trying it out now

plexus19:08:02

this works for me

plexus19:08:06

lein new chestnut minitest
cd minitest
lein cljsbuild once min
firefox resources/public/index.html

krchia19:08:20

it works for me too - am trying to replicate the error

plexus19:08:24

that with-profile command is outdated, I'll update the FAQ, lein cljsbuild once min should do the trick

krchia19:08:39

so i did it differently - i just did lein cljsbuild once

krchia19:08:52

and i get "subprocess failed"

krchia19:08:01

lein cljsbuild once min works i guess

plexus19:08:46

yeah this should be documented a bit better in the readme, before we had (IIRC) just a single ClojureScript build configured and relied on profile merging, hence the advice to use with-profile

plexus19:08:59

now we have three builds with their own ids, "app", "test", and "min", when doing lein cljsbuild once it tries to build all three, but it's missing some test dependencies so the second one fails... this isn't great, we should probably move that test build into the test profile

krchia19:08:08

i am curious as to why optimizations :none breaks the build

krchia19:08:18

with the asset-path error

plexus19:08:25

if you use :optimizations :none then it spits out dozens of individual files, one for each namesapce. when your app boots it tries to load all the necessary namespaces, but it doesn't necessarily know where those files are, what URLs they have

plexus19:08:50

:asset-path is a way of saying "this is the place where you can find those files"

plexus19:08:21

I guess doo (the ClojureScript test runner we use) doesn't have that problem though, cause it seems to work fine without :asset-path

plexus19:08:03

don't know if the above makes sense... working your way through the Quick Start would probably make this more clear

plexus19:08:08

(I also did a Lambda Island episode about the ClojureScript Compiler that explains these things in detail, let me know if your trial expired I'm happy to renew it https://lambdaisland.com/episodes/clojurescript-compiler)

plexus19:08:32

@krchia: looking at it again I think we have some usability issues when using cljsbuild directly. This hasn't come up before because people mainly use Figwheel+Uberjar. I documented the issue here: https://github.com/plexus/chestnut/issues/177 will need some thinking how to address it. I think you ran into the last issue where a previous "app" build was standing in the way of doing a proper "min" build

krchia19:08:47

@plexus: i’m not too familiar with uberjar - might you suggest a good resource like quick start for cljsbuild?

plexus19:08:56

Specifically for uberjar? Or for cljsbuild?

plexus20:08:06

Cljsbuild is just a thin wrapper around the clojurescript compiler, the clojurescript quick start + cljsbuild readme is probably enough for that

plexus20:08:18

Uberjar is a leiningen feature, don't know if there's much documentation for it. It compiles all your code, and bundles it with all dependencies into a single "jar" file (java archive)

plexus20:08:25

So you can just copy that one file to a server to deploy your app. In chestnut we hook into that process to also compile clojurescript and put it into the jar

chris20:08:09

latest version looks great, especially the implicit macro loading and autoaliasing clojure namespaces. thanks all

bostonaholic23:08:14

awesome job on this!