Fork me on GitHub
#clojurescript
<
2017-03-17
>
ghosttoaster00:03:29

Does anyone here use boot for their clojurescript development? Does adzerk/boot-cljs-repl have the require macro? I'm getting require being undefined inside the cljs.user namespace.

qqq00:03:02

@cdimara : I 'm using boot + cljs. I worked through the first few of https://github.com/magomimmo/modern-cljs/tree/master/doc/second-edition and everything, including adzerk/boot-cljs-repl, worked fine

ghosttoaster00:03:18

I'm working through that too!

ghosttoaster00:03:31

I'm doing a little experiment though trying to run quil-cljs in a live environment.

ghosttoaster00:03:48

But it seems like things like require and doc would be built into all namespaces.

ghosttoaster00:03:04

But maybe because its clojurescript its different?

ghosttoaster00:03:59

Ok. I found the problem. Proto-repl and atom.

ghosttoaster00:03:15

Ran boot-repl and had no problems.

qqq00:03:24

sorry, missed all the followup thread replies; but glad to see you worked it out

seantempesta02:03:45

Is anyone else getting this error when using figwheel with the new clojurescript compiler (1.9.494)? I did package it myself to include the newest google-closure library to fix the core.async bug.

Compiling "target/not-used.js" from ["src" "env/dev"]...
module.js:472
    throw err;
    ^

Error: Cannot find module 'module-deps'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at [eval]:2:13
    at ContextifyScript.Script.runInThisContext (vm.js:23:33)
    at Object.runInThisContext (vm.js:95:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:571:32)
    at Immediate.<anonymous> (bootstrap_node.js:390:29)
The externs inference is pretty cool btw!

anmonteiro02:03:07

@seantempesta are you consuming Node modules?

seantempesta02:03:55

@anmonteiro: Yeah. This is a react native project.

anmonteiro03:03:25

@seantempesta so you need to install the module-deps package

seantempesta03:03:45

@anmonteiro: Yup. That fixed it. Sweet. Thanks!

luisdevlopez03:03:08

Does anyone know which one is best when passing state around in Reagent? a) Pass a defonce atom declared in the core namespace to components in other files as an argument IE [my-component state] b) Require and refer the state from the files as [:require my-proj.core :refer [state]] ?

Jon04:03:12

js
/**
 * Freeze the prototype of javascript build-in objects.
 */
/* istanbul ignore next */
export function freezePrototype () {
  Object.freeze(Object)
  Object.freeze(Array)

  Object.freeze(Object.prototype)
  Object.freeze(Array.prototype)
  Object.freeze(String.prototype)
  Object.freeze(Number.prototype)
  Object.freeze(Boolean.prototype)

  Object.freeze(Error.prototype)
  Object.freeze(Date.prototype)
  Object.freeze(RegExp.prototype)
}

Jon04:03:48

Still not very sure how does this piece of code break ClojureScript. Anyone got some clue?

noisesmith07:03:17

@jiyinyiyong

+cljs.user=> (.freeze js/Object js/Object)
#object[Object "function Object() { [native code] }"]

noisesmith07:03:42

that's equivalent to Object.freeze(Object)

noisesmith07:03:41

for the wrapper, something like (defn ^:export freeze-prototype [] ...) I think

noisesmith07:03:46

and then there's (.-prototype js/Object) (.-prototype js/Array) etc.

Jon08:03:16

I think they called Object.freeze(Object.prototype), why Ca.prototype.toString is frozen...

Jon09:03:50

Turned out they are fixing the problem with Object.seal https://github.com/apache/incubator-weex/pull/109

borkdude09:03:09

Is is possible to require a library based on a condition on ClojureScript for dev purposes? (if x (require '[..])) I notice that leaving out devcards and re-frisk speeds up (incremental) compilation, but I don’t think it can be accomplished this way. I’m talking about the dev build, in prod of course we leave it out already. Maybe I’ll make a third build.

rauh09:03:57

@borkdude I use different source paths for some parts of my app depending on dev/prod. Ie, you always include the files, but they might just be empty for production. Works really well and it's super easy.

borkdude09:03:23

@rauh That’s what I’ve been doing also

borkdude09:03:22

Hmm, I’m not sure what caused the slow compilation. I restarted and it’s within 2-3 seconds now

borkdude09:03:32

So never mind

thheller10:03:28

@borkdude conditional require is not possible no

thheller10:03:23

doesn't matter, that must be at the top-level as well

thheller10:03:42

its a restriction of Closure more than CLJS

borkdude10:03:49

I wasn’t saying it’s possible, just posting the link as an explanation why it’s not 😉

borkdude10:03:21

I’ve found a satisfactory solution though, so never mind

borkdude10:03:03

If needed I could make a second dev build which excludes certain things

jysandy11:03:35

I’ve been trying to run generative tests using spec in Clojurescript. I wrote this helper function:

(defn assert-generative-test
  ([sym] (assert-generative-test sym nil))
  ([sym opts]
   (is (empty? (->> (stest/check sym
                                 {:clojure.test.check/opts opts})
                    (map stest/abbrev-result)
                    (filter :failure)
                    (map :failure))))))

jysandy11:03:35

When I try to build though I get a java.lang.RuntimeException: Unable to resolve symbol: sym in this context Could someone explain why this is happening? This function compiles in JVM Clojure.

thheller11:03:44

@jysandy not 100% but stest/check in CLJS is a macro so it might not be possible to pass dynamic args like that

qqq11:03:03

I want a regex that can match ( [ { } ] ) so I try

#"[]})([{]"
but js does not like that

danielstockton11:03:01

This stuff changes quite a lot...If I want to create a package that I can add to my dependencies for https://github.com/cubiq/iscroll, is there an up-to-date guide on what to do?

boyanb11:03:55

https://github.com/clojure/clojurescript/wiki/Packaging-Foreign-Dependencies is latest afaik. To actually do the work, easiest is to simply check the boot.build of a package from cljsjs and adjust accordingly.

foobar12:03:52

What is this syntax? (:params query-data (params component))

foobar12:03:28

I don't understand calling a keyword on multiple items

foobar12:03:07

Ok, the last item seems to be the not found value

cpmcdaniel13:03:59

@foobar be aware that the (params …) function will be called even if the value isn’t used

cpmcdaniel15:03:42

@foobar I do think that using get is easier to read when you are using a default value like this

cpmcdaniel15:03:29

(get query-data :params (params component))

thheller16:03:49

@peterwestmacott that line com.cognitect.transit.util = {}; is basically goog.provide('com.cognitect.transit.util');

thheller16:03:07

so transit seems to be included in the server-side.js which then also loads the other files

thheller16:03:14

trying to load transit again

thheller16:03:40

but hard to tell without knowing your entry points .. looks like you have two builds server-side and app

qqq16:03:02

I have a char c; is there a way to check if c is a digit, i.e. 0..9 ?

Rachel Westmacott16:03:32

@thheller that's not my question, but I suspect it's related as I get a similar error. In my case I'm attempting to run cljs tests with doo on nashhorn.

noisesmith16:03:58

qqq js has no characters, but this works

+cljs.user=> (not (js/isNaN "9"))
true
+cljs.user=> (not (js/isNaN "a"))
false

qqq16:03:29

hmm, I ended up using a regex test

qqq16:03:33

but isNan looks like the right solution

qqq16:03:46

(.test #"\d" ...)

jr16:03:22

there's also goog.string/isNumeric

luisdevlopez16:03:38

does anyone know why lein-cljsbuild produces a 90 kb output when I only have a hello world println?

noisesmith16:03:20

@luisdevlopez all the code for all of cljs' data types and functions ends up in the output unless you turn on minification for the build

anmonteiro16:03:32

that’s probably a minified build already

luisdevlopez16:03:56

it is, I created a new lein figwheel project

anmonteiro16:03:03

the simple fact of enabling printing will cause a lot of stuff to be included in your build

anmonteiro16:03:22

(enable-console-print!) will add all that cruft

luisdevlopez16:03:28

yeah I have that one added

qqq17:03:37

#"" <-- how do I create a regex that matches #{ ?

martinklepsch17:03:27

@qqq (re-find #"#{" “hello#{”) — maybe? not sure if I fully understand

thheller17:03:35

(str/starts-with? x "#{") yes not a regex, maybe you don't need one?

qqq17:03:17

I need to split a string on all instances of #{

qqq17:03:33

@martinklepsch , @thheller : sorry for not making problem cleearer

thheller17:03:46

#"#\{" should do it

mobileink18:03:16

webcomponents v1 uses this js: class AppDrawer extends HTMLElement {... (https://developers.google.com/web/fundamentals/getting-started/primers/customelements). can this be expressed in cljs? i googled but came up with nothing.

martinklepsch18:03:34

@qqq (str/split "hello #{world#{today" #”#\{”)

thheller18:03:29

@mobileink that's not easy at the moment, mostly because some JS runtimes don't allow extends on native elements in any other form

thheller18:03:45

so you need to to it using Reflect

mobileink18:03:58

thanks. never used Reflect, is there a good example of what you mean somewhere?

noisesmith18:03:53

@thheller would that involve using Reflect.setPrototypeOf ?

thheller18:03:54

(defn component []
    (js/Reflect.construct js/HTMLElement #js [] component))

  (set! (.-prototype component)
    (js/Object.create (.-prototype js/HTMLElement)
      #js {:connectedCallback
           #js {:configurable true
                :value
                (fn []
                  (this-as this
                    (js/console.log "connected" this)))}

           :disconnectedCallback
           #js {:configurable true
                :value
                (fn []
                  (this-as this
                    (js/console.log "disconnectedCallback" this)))}

           :attributeChangedCallback
           #js {:configurable true
                :value
                (fn []
                  (this-as this
                    (js/console.log "attributeChangedCallback" this)))}

           }))

  (js/window.customElements.define "x-component" component)

thheller18:03:10

it has been a while since I experimented with that

thheller18:03:17

only worked in Chrome IIRC

mobileink18:03:35

@thheller you're awesome, thanks!

thheller18:03:40

can't remember the details really .. too long ago

thheller18:03:05

many things have changed probably

mobileink18:03:11

that's enuff to get me started. fwiw polymer v2 rc is just out, it uses wc v1, so i guess it's stable.

thheller18:03:48

no I meant the Reflect part was pretty hacky. it might not be required anymore

mobileink19:03:27

thheller: thanks. i know just enuff js to be dangerous so anything that kinda sorta works is okay for now. i'm generating the cljs from a macro anyway, so it doesn't matter how gnarly it is.

thheller19:03:41

IIRC either IE or Safari don't even have Reflect .. so be very careful 🙂

mobileink19:03:31

oy. what a pain the web is.

exit218:03:04

Is anyone aware of a tool for clojurescript projects that will look at your CSS files and audit other files to point out what classes/ids are not being used?

rafaelzlisboa19:03:57

haven’t heard of it, @njj - but as an alternative i’d recommend looking into something like https://github.com/roman01la/cljss (then you can do stuff like “find usages” on the styles since it will be clojure code)

jimmy19:03:08

yeah same :3

jimmy19:03:39

One of the interesting use case I can see from cljss lib is that , facebook does use this kind of thing to generate different class

jimmy19:03:59

in html file , every time we refresh the browser, it makes things harder to scrape. I just get to know it

exit219:03:53

@rafaelzlisboa I’ve seen this before, and definitely would like to move towards something like this at some point but thats a big undertaking w/ the amount of CSS we have right now 🙂

qqq19:03:48

@martinklepsch @thheller : I got it working with [#][{], but I like your solution of #\{ more

kenny21:03:53

@anmonteiro Out of curiosity, do we get DCE when using :npm-deps?

anmonteiro21:03:06

@kenny yes! Updating the post now

shaun-mahood21:03:26

@anmonteiro: If someone wanted to use :npm-deps without having node installed, or otherwise have a guaranteed immutable dependency, could they manually copy the downloaded deps files and have it work?

anmonteiro21:03:59

@shaun-mahood that’s not currently possible with :npm-deps

anmonteiro21:03:11

but you have cljs.closure/index-node-modules which you can use

anmonteiro21:03:23

you can feed the result of that to foreign libraries

anmonteiro21:03:41

we should maybe consider moving that to the cljs.build.api namespace

shaun-mahood21:03:57

Ok - not a blocker for me, but with the number of people who have avoided CLJS because they didn't want to install Java, I can see a similar conversation happening way too often with Node as well.

anmonteiro21:03:14

@shaun-mahood I don’t agree with that statement

anmonteiro21:03:40

if you wanna consume Node.js modules, you probably already have Node.js installed

anmonteiro21:03:24

and you can opt out of consuming them

anmonteiro21:03:30

do not include :npm-deps 🙂

anmonteiro21:03:43

that said, all of this is still alpha, as I mention in my post

anmonteiro21:03:02

we’ll be fine tuning the behavior over the next iterations, of course

anmonteiro21:03:52

I would say most people will like the current behavior

anmonteiro21:03:35

we can hopefully please the full spectrum as we iterate

nanuko21:03:43

has anyone had to deal with floats in transit? js only has the number type, so if your value is an integer, that number will be delivered via transit as an integer

shaun-mahood21:03:56

@anmonteiro: You could be very right on that point - I will happily be consuming them with Node installed. Having spent a bit of time lately working with Google Closure based JS libraries, I'm definitely looking forward to having a similar workflow for node libraries eventually.

nanuko21:03:58

can cause problems if the receiving service expects a float

nanuko21:03:30

i tried (cognitect.transit/bigdec 1.0), but the transit writer complains about that

tap21:03:43

@anmonteiro This is exciting. Just to confirm if I read correctly, we won’t have to run npm install separately anymore, right?

dnolen21:03:43

@shaun-mahood: I would argue that these days having Node.js installed is not a particularly strange expectation. And the fact that it won’t work without is no more troubling than the Node REPL not working either.

thosmos22:03:33

I'm trying to figure out how best to use the faunadb js driver (https://github.com/fauna/faunadb-js) in a clojurescript project. They have both nodejs and browserify versions, both of which are es5. :npm-deps {:faunadb "1.0.0"} throws a compiler error. Should I report this on the clojurescript bug tracker? So far, I'm able to load the browser build (https://github.com/fauna/faunadb-js-release/blob/master/faunadb.js) if I first create a new js file with a faunadb = require("faunadb") and then use browserify on that, and then include the new file either in a script tag or in :foreign-libs. Is there a better way? I tried adding :module-type :commonjs and :module-type :amd but both of those threw errors.

thosmos22:03:17

oh and I'm using clojurescript 1.9.500

anmonteiro22:03:35

@thosmos you’re probably hitting a Closure Compiler error

anmonteiro22:03:08

this one maybe?

thosmos22:03:07

it's similar but a little different: https://www.refheap.com/133232

anmonteiro22:03:03

looks like that one

anmonteiro22:03:22

try using Closure Compiler from master

shaun-mahood22:03:19

@dnolen: Well, this change has certainly given me a good reason to care more about Node than I did before - before this, I couldn't see any real benefit to using Node or NPM in a Clojure + CLJS environment. I guess my main concern is that npm-deps will become pervasive enough in the CLJS environment that beginners will essentially be required to learn the JVM, Maven, Clojars, NPM, and Node all at once. Likely a concern that can be remedied once the first patch is more than a week old, though 🙂 Either way, I think it's a very impressive and important step for ClojureScript to take and I'm glad to be along for the ride.

thosmos22:03:36

@anmonteiro @dnolen thanks for the work on this!

dnolen22:03:09

@shaun-mahood heh right, there’s definitely some expectation management to do here

dnolen22:03:39

but people should just try it and we’ll see what does and doesn’t work

thosmos22:03:54

@anmonteiro that looks like the one. using closure from master is basically cloning it, then a mvn install then updating clojurescript deps to use 1.0-SNAPSHOT?

anmonteiro22:03:41

@thosmos @martinklepsch made the instructions a little more beginner friendly the other day https://github.com/google/closure-compiler/pull/2374

anmonteiro22:03:26

@thosmos also note that there’s still an unsolved module bug which will hopefully be fixed in the next release. see https://github.com/google/closure-compiler/pull/2350

thosmos22:03:29

@anmonteiro ok, now I'm getting an error (https://www.refheap.com/133234) that looks very similar to the one I got when i tried to load the browser build in :foreign-libs with :module-type _: The two errors in the beginning are the same: identifier is a reserved word

anmonteiro23:03:34

@thosmos not every package can be consumed

anmonteiro23:03:44

boolean is a reserved JavaScript keyword

anmonteiro23:03:15

also you can set :closure-warnings {:non-standard-jsdoc :off} to silence those JSDoc warnings

thosmos23:03:56

cool, well, it's exciting work none the less. I can live with building it with browserify and loading externally. I'll probably make a cljsjs package for it

qqq23:03:07

how do i get cljs ids that are srings instead of numbers?

johanatan23:03:40

can anyone suggest state-of-the-art setup for CLJS testing w/ Node.JS and leiningen ?