Fork me on GitHub
#clojurescript
<
2017-06-23
>
the-kenny07:06:02

Om didn't get a feature to return multiple children from a component without wrapping them in a singular parent, right?

thheller07:06:04

@the-kenny React does not yet support it so om doesn’t as well (it will come with React v16)

the-kenny07:06:38

Ah, I thought I remember React gaining that feature with one of the latest releases. Couldn't find it in the Changelog though

thheller07:06:58

the new fiber stuff supports it but that’s still alpha

thheller07:06:25

no idea whether om supports fiber or not

hkjels08:06:44

Wow. This is expected behavior

dm308:06:21

welcome to IEEE 754

shader13:06:42

lol. Yes, NaN is actually a number... which makes sense given it is a possible result of math operations, but not when you remember what it means 😛

m14:06:55

anyone experienced with cljsjs? I'm ablte to require the JS library I need after I put it to my dependencies. But until now every attempt to access the object in question fails... Shouldn't it be somewhere in the global space? Or do I have to add some externs manually to the project.clj?

gaverhae15:06:45

m: Maybe give a bit more details? Which library are you talking about and what exactly have you tried to access it? Dependency vector from the project.clj and a complete (but minimal) namespace that shows what you tried (and an explanation of what you expected instead) would probably go a long way towards making people able to help

m15:06:41

you're right.. I' about to use the Handsontable library. I added [cljsjs/handsontable "0.31.2-0"] to the depencencies of leiningens project.clj. I can require [cljsjs.handsontable] in a cljs source file without any errors and indeed the js files are included in my figwheel dev build. However, now I'd expect to access the global Handsontable object further in the code but this fails.

dnolen14:06:02

@m you need only externs for advanced compilation

marciol14:06:12

Hey guys, a off-topic and a little bit newbie question: There are a lot of materials and blog posts about use of Clojurescript to build SPA's but I'm a little old school guy and despite a lot of javascript in my web apps, I still do the old server side rendering through Ruby on Rails, but I want to use Clojurescript too. I found this post from @dnolen http://swannodette.github.io/2015/02/23/hello-google-closure-modules and I think that will solve the problem, so the question is: Do you think that clojurescript is also suitable to this kind of scenario?

dnolen15:06:56

@marciol if all you want to do is add some scripting here and there then I don’t really think you need Closure modules

dnolen15:06:25

advanced compiled ClojureScript w/o a bunch of 3rd party libs around the size of jQuery

dnolen15:06:42

which at least when I was doing RoR was perfectly acceptable to load onto any page that required JS

marciol15:06:01

hmmm, good

marciol15:06:13

thanks @dnolen I'll go for it!

m15:06:11

Unfortunately the cljsjs problem is not solved yet... Here are some more details: I' about to use the JavaScript Handsontable library via cljsjs. I added [cljsjs/handsontable "0.31.2-0"] to the depencencies of leiningens project.clj. I can require [cljsjs.handsontable] in a cljs source file without any errors and indeed the js files are included in my figwheel dev build. However, now I'd expect to access the global Handsontable object further in the code but this fails since it does not exist..

metametadata16:06:23

@m js/Handsontable fails?

metametadata16:06:54

I included the lib in project and ns as you described and it worked:

(ns example.core
  (:require [cljsjs.handsontable]))

(enable-console-print!)

(println "Handsontable" js/Handsontable)
Handsontable #object[Handsontable "function Handsontable(rootElement, userSettings) {
  var instance = new Handsontable.Core(rootElement, userSettings || {});
  instance.init();
  return instance;
}"]

m16:06:18

ha! now I see. I'm using Electron. I'm just seeing that it works in the Browser..

valyagolev16:06:00

https://github.com/alexkehayias/praline - this doesn’t seem very popular - does it mean there’s an alternative everyone uses, maybe more general in some way? (e.g. no reagent dependency)

m16:06:11

Electron knows about 'require' even in it's client-windows... I guess this might cause handsontable to not load properly. However, (js/require "handsontable") doesn't do anything here... Does anyone have an idea about this?

wildermuthn17:06:50

@m Are you trying to load it in the main process or the renderer?

wildermuthn17:06:16

Also, can talk about this more in #electron

pandeiro18:06:18

Is anyone familiar with a recent CLJ/CLJS routing lib inspired by silk/bidi but with support for non-nested syntax? I saw it a little while back but can't remember the name of it and have had no luck googling

domkm18:06:31

@pandeiro What do you mean by non-nested?

pandeiro18:06:27

There was a shorthand syntax for routes involving multiple segments that didn't require nesting vectors and maps for matching

noisesmith18:06:32

if you don’t need nesting, I’d think a hash-map would suffice to replace a router

noisesmith18:06:55

except for the issue of wildcards I guess

pandeiro18:06:58

No I do want complex routes, I just find the data structures hard to read

pandeiro18:06:04

Yeah, I want wildcards

danielsz18:06:05

I have a cljs app that breaks in advanced compilation mode, but doesn't when using the pseudo-names compiler flag. How on earth should I go about debugging this?

pandeiro18:06:38

Definitely a candidate for the best and worst named ClojureScript library of the year

dnolen18:06:31

@danielsz there are two cases where that is likely to happen

dnolen18:06:52

1) you’re not wrapping your script in an :output-wrapper causing a collision with something else on the page

dnolen18:06:36

2) you’re relying on cljs->js to convert some JS value which will clash with Closure generated properties

danielsz18:06:38

@dnolen Awesome. I'll investigate and report back. It's a conundrum, but a delightful one.

dnolen18:06:47

for the record I believe cljs->js has too many accumulated issues and in general I would avoid it. I’ve built a lot of apps and I can’t remember a single time where I thought I needed it

danielsz18:06:26

I've taken note. My application doesn't use cljs->js directly, but one if its dependencies might. I don't know yet.

noisesmith18:06:57

so is this cljs->js you guys are talking about something different from clj->js ? is it an inferior alternative for using the #js reader macro?

dnolen18:06:13

er I mean clj->js of course

dnolen18:06:27

it’s not so much inferior as it wasn’t really a great idea to begin with

dnolen18:06:48

it’s definitely one of these we probably shouldn’t have added - even though people keep asking for it

noisesmith18:06:37

so if I’m using js that expects a js object or array should I be using #js for constructing it or some smart alternative that’s escaping me or?

dnolen18:06:52

there so many things to use

mobileink19:06:35

dnolen: asking as a relatively naive cljs user, is there a blogpost or other that surveys that options, pros & cons, etc.

dnolen18:06:07

js-obj, array, #js

dnolen18:06:32

and for handling you have goog.object, goog.array

chouser18:06:30

I'm trying to stick a Babylon component into an existing reframe app that's built with boot. I've never used any of those technologies before. It's possible I've bitten off too much at once. Anyway, what's the best way get a different version of Babylon than is currently provided with cljsjs/babylon?

darwin18:06:24

@danielsz I would try to compile in advanced mode with source-maps, Chrome DevTools could give you more context with reformatting and source mapping

darwin18:06:18

once I had similar issue caused by names aliasing in advanced mode, with pseudo-names the problem went away because the naming scheme prevented the clash

darwin18:06:34

simply by coincidence

timgilbert18:06:51

@pandeiro: I also like sibiro for routing, it's simple and you can use it on the back-end too if you need to: https://github.com/aroemers/sibiro

chouser18:06:03

yep, which cljsjs provides, but it's an older version and is breaking in a way that makes me wonder if it ever worked.

dnolen18:06:46

well as long you can get the JS for it you can just make a local foreign lib

chouser19:06:19

yeah, ok. I'll need to learn more about boot for that. Thanks.

dnolen19:06:01

@chouser it’s just ClojureScript compiler option, so hopefully nothing to learn wrt. boot other than how to pass it along

chouser19:06:54

well I'm apparently using boot to serve the files to the browser, and so I need to get it to serve the babylon files too. My first attempt to do that failed, but I can pursue it more.

dnolen19:06:40

@chouser hrm I don’t really understand that

dnolen19:06:59

ClojureScript copies everything to :output-dir and whatever you’re using should be serving from there or allow you to configure that

chouser19:06:36

I barely know what I'm talking about. I typed "boot dev" and then can point my browser at localhost:3000. I can browse to static resources that are in resources/public/, but when I added a symlink there to the babylon.js directory, I was getting 404s for files there.

dnolen19:06:20

right you don’t need to bother with all that

dnolen19:06:29

ClojureScript must copy everything to :output-dir

chouser19:06:39

I'll keep trying. I just thought cljsjs might be easy and convenient, but it hasn't panned out yet.

dnolen19:06:41

otherwise serving JS via a webserver is a disaster

dnolen19:06:55

@chouser it’s useful to pass :verbose true as a compiler option

dnolen19:06:06

then you can see all the fun stuff that’s happening

dnolen19:06:11

analyzer, compilation, and copying stuff

dnolen19:06:31

if Babylon is not getting copied - that’s your problem right there

darwin19:06:05

@chouser speaking about cljsjs, I don’t rely on internets to make externs for me, I tend to write a thin wrapper cljs library for js library using string names and include the js lib in html file directly outside my :advanced mode compilation. This way I completely avoid dealing with externs, :foreign-libs and related stuff: https://github.com/binaryage/cljs-oops#side-stepping-the-whole-externs-mess

danielsz19:06:21

Thank you, @darwin. My first instinct was to launch a dirac repl, actually. (and then I saw the message about advanced mode).

darwin19:06:37

@danielsz not sure what message do you mean…

danielsz19:06:10

darwin: "You required cljs-devtools library in a project which is currently compiled with :optimizations :advanced."

darwin19:06:17

ok, but that is unrelated to your advanced mode issue. it is even unrelated to dirac.

darwin19:06:31

that only says that cljs-devtools does not work properly in advanced mode

danielsz19:06:40

OK, great. It suggests to use the preloads compiler option, which I wasn't sure about.

darwin19:06:13

you should be able to use source-maps and minified js reformatting in normal Chrome DevTools

martinklepsch19:06:44

@chouser are you using tenzing by any chance?

martinklepsch19:06:26

@chouser if things are set up correctly adding a cljsjs package is 1) adding the dep 2) requiring it 3) using it

dnolen19:06:05

@mobileink no but that sounds like great contribution to the ClojureScript site https://clojurescript.org/guides/quick-start

dnolen19:06:20

like an interop guide with best practices and caveats about clj->js

chouser19:06:49

@martinklepsch I don't know what tenzing is. I added and required the cljsjs/babylon dep. When I attempt to use it, it breaks somewhere inside the Babylon code, so it's loading, but who knows what it's doing. I'll attempt more direct control of the babylon code loading.

dnolen19:06:49

I’ll say again that updating the ClojureScript site docs is like the lowest of lowest hanging fruits if you want to have a big impact 🙂

martinklepsch19:06:13

@chouser is your code up somewhere?

martinklepsch19:06:51

@chouser happy to take a look if so

dnolen19:06:52

people often say they don’t feel like they have the knowledge to write up a guide - but that is unfounded - someone who knows is going to review the PR!

chouser19:06:03

@martinklepsch Wow, that's generous. Give me a few more hours to poke at it. This will definitely all go up online at some point, working or no.

dnolen19:06:20

@chouser as an aside you should desire to take less control of Babylon loading 🙂

dnolen19:06:26

ClojureScript handles this for you

mobileink19:06:55

@dnolen i'm game, i need to figger this stuff out any way. anybody else got any recommendations? fwiw i have data structures i need to pass to js objs. i use clj->js, out of pure ignorance (path of least resistance). i reckon good docs would start with use cases, then pros and cons of various techniques?

dnolen19:06:22

@mobileink guide should start with fundamentals

dnolen19:06:38

js-obj, array, then #js literals (noting not recursive).

dnolen19:06:53

clj->js should be called out as convenience but the dangers for advanced compilation should be noted

dnolen19:06:06

it doesn’t need to be a particular long or verbose guide - and we can now direct people to it that have questions

danielsz19:06:44

I personally have always referred to this guide for that kind of stuff. http://www.spacjer.com/blog/2014/09/12/clojurescript-javascript-interop/

mobileink19:06:40

me too, great resource. but i think it needs some more details, and for the official docs it needs to be a bit more concise (imho).

mobileink19:06:56

the obvious question: if clj->js is "not so great", but #js is not recursive, what to use if you have e.g. a nested structure of maps, sets, vectors, etc.?

dnolen19:06:29

#js is fine for this

danielsz19:06:44

You can put the reader tag before every node of the nested data structure..

dnolen19:06:01

you have make a nested literal anyway to pass to the JS api

dnolen19:06:10

most JS apis are not that cumbersome to require deeply nested stuff

mobileink19:06:48

and another naive question: how often does it happen that interop is not needed in real-world situations?

dnolen20:06:10

libs can get away with it

dnolen20:06:31

but it seems unlikely in any real application that talks to some non-Clojure(Script) thign

mobileink20:06:00

ok, i'm a bit confused about #js. if i recieve a hairy clj structure from the server (e.g. using transit), then to translate it to js w/o clj->js, i need to walk it somehow to insert #js? that sounds like a dumb q to me, have mercy. 😉

mobileink20:06:02

and fwiw i'm thinking of polymer bindings, heh.

mobileink20:06:53

fyi if i set a property to a hairy js structure, polymer bindings will propogate the contained data automagically, with no coding.

mobileink20:06:38

(the background issue is how to make polymer and react-based stuff play nice.)

danielsz20:06:37

@mobileink I've experienced that, absolutely. When producing or consuming a non- trivial clj nested structure, clj->js is handy. I have no good answer.

dnolen20:06:25

@mobileink server/client comm concerns really are out of scope for what this guide is about

dnolen20:06:33

we’re not going to talk about Transit at all there

dnolen20:06:59

but one idea for that specific case is to just write your own thing w/ clojure.walk

dnolen20:06:18

but stepping back a bit, if my integration is just to feed stuff into Polymer, I don’t know what value there is marshaling immutable Transit

dnolen20:06:28

I would just take JSON and avoid all this unnecessary marshalling

mobileink20:06:41

makes sense re: guide.

dnolen20:06:00

this is what I meant above about never personally needing clj->js

dnolen20:06:06

I would not put myself in situation where it’s required

dnolen20:06:11

not worth it

mobileink20:06:50

but: would walking be (sometimes?) more efficient than clj->js? that would be surprising to me, at least.

dnolen20:06:07

I don’t see how it would be any different

dnolen20:06:10

clj->js is slow

dnolen20:06:00

I’ve actually seen apps where people took 5mb EDN payloads only to call clj->js

dnolen20:06:04

this doesn’t make any sense

mobileink20:06:26

re: feeding stuff to polymer: i might be doing it wrong, but i transit some data to my frontend, then shove it into datascript, so i can muck with it at will in cljs. then i grab some of it and pass it to polymer.

mobileink20:06:53
replied to a thread:this doesn’t make any sense

dnolen: yikes

mobileink20:06:00

so i might pass some data to one component, and some other data to another component. make sense?

dnolen20:06:39

@mobileink sure if the amount of data your pushing throw is small that’s ok, I’m just saying if you think about it up front you can avoid lots of problems

dnolen20:06:51

if I can avoid marshalling in my system I will

dnolen20:06:52

convenience is not important

dnolen20:06:38

(I’m not saying in general, I’m just talking about data flow design)

mobileink20:06:44

e.g. just send json in the first place? i agree avoid marshalling, but there's an unavoidable tension if i want to do data manip in cljs while still talking to js objs, no? i obviously need to spend more time actually doing this, heh.

dnolen20:06:47

and there’s lot of ways to fix this for any given problem

dnolen20:06:06

for example I might just say no to Polymer because of this and go React or whatever

dnolen20:06:14

or I may say no to Transit

dnolen20:06:31

but in the end clj->js is not the answer

dnolen20:06:34

it’s just a symptom

mobileink20:06:06

no to polymer!!?? blasphemy! (miraj author here). 😉

danielsz20:06:04

@dnolen All this talk about clj->js and in the end it was the :output-wrapper thingy. I was pulling my hair out. Turns out I'm not the first. https://dev.clojure.org/jira/browse/CLJS-1520

danielsz20:06:03

@dnolen Thank you for pointing me to the right direction.

dnolen20:06:37

@danielsz yeah I was pretty sure that was your problem

danielsz20:06:03

@dnolen But why this landmine? Is it really going to be a breaking change?

mobileink20:06:04

@dnolen well thanks so much for the feedback. lots o food for thought.

dnolen20:06:18

clj->js collisions are less likely - I think most people just monkey-patch it if they hit a problem

dnolen20:06:30

@danielsz it’s too old - massive breaking change

mobileink20:06:25

if i can come up with a sane and concise discussion of this stuff i'll sub a doc pr.

danielsz20:06:26

@dnolen I see. Maybe auxiliary tooling is in a good position to be doing something. boot-cljs has a related ticket. https://github.com/boot-clj/boot-cljs/issues/64

dnolen20:06:07

@danielsz my vote would be to deprecate it and perhaps make a new thing that just uses walk and has no bells or whistles and no extension points

dnolen20:06:44

@danielsz oh you’re talking about :output-wrapper true for advanced

dnolen20:06:54

right you can do that downstream

dnolen20:06:48

I think cljsbuild may already do that?

danielsz21:06:55

@dnolen Yes indeed, if you could do it again, you would enforce :output-wrapper true as a default, no?

danielsz21:06:55

Certainly for advanced compilation where collisions are likely to happen without it.

danielsz21:06:55

There seems to be some confusion regarding where the best place to enforce this option should be. https://github.com/boot-clj/boot-cljs/issues/64#issuecomment-166929728

magic_bloat21:06:00

Howdy. Newbie question coming up...

magic_bloat21:06:49

I've imported goog.events.EventType. What is the difference between EventType/KEYDOWN and EventType.KEYDOWN.

danielsz21:06:12

@dnolen There seems to be some resistance to change the defaults in build tools just to stay aligned with the compiler defaults. What's your take on that? Is there any reason not to enforce output-wrapper true for advanced compilation in our build tools?

magic_bloat21:06:47

Both seem to work. Using slash is what I'm used to from Clojure. But it gives an undeclared Var error. Using dot works a-ok. But seems wrong.

dnolen21:06:01

@danielsz having different defaults always makes documentation more confusing

dnolen21:06:22

and whatever problem you hit with the default somebody will hit another problem with the new default

dnolen21:06:54

so I understand the resistance

dnolen22:06:18

that said, I don’t have any real issues if downstream tools want to do more or different stuff

danielsz22:06:51

@dnolen Right. It's a tricky one. lein-cljsbuild enforces output-wrapper for advanced builds, and at boot-cljswe are considering it too. I am in favor because this is such an obscure source for bugs.

dnolen22:06:41

:output-wrapper true downstream seems like OK to me

danielsz22:06:42

@dnolen Thank you for sharing your perspective.

dnolen22:06:49

just should be documented

chouser22:06:03

oh! hah -- apparently I'm using bootstrapped cljs. I guess boot is just for serving files and triggering reloads in this model?

ag22:06:10

hey guys, what's the correct way of converting string to number in cljs? why this (int "1") works but this (int "11111111111") returns negative num?

ag22:06:34

should I use js/parseInt instead?

noisesmith22:06:41

js/parseInt is the right thing to use

ag23:06:47

but sometimes that thing returns NaN

ag23:06:22

WAT?

cljs.user> (js/parseInt "--000--")
NaN
cljs.user> (number? (js/parseInt "--000--"))
true

noisesmith23:06:25

maybe you need more pre-processing before making these things numbers?

ag23:06:27

can someone explain rationale behind this: (number? NaN) is true

dnolen23:06:41

JavaScript

noisesmith23:06:42

it doesn’t take “not” as literally as we would like

noisesmith23:06:57

clj on the jvm does the same thing

ag23:06:25

there's NaN in java?

noisesmith23:06:46

it’s a static field in java.lang.Double Double/NaN

noisesmith23:06:01

it’s part of the floating point spec to have that value

noisesmith23:06:45

or value(s) even iirc

noisesmith23:06:13

https://en.wikipedia.org/wiki/NaN - quiet nan, signaling nan, plus some bits for a “payload” that usually goes unused

emccue23:06:50

Is there a good tutorial for getting figwheel running with a non-Ring server (in my case django)

richiardiandrea15:06:29

emccue: if I understand correctly, no tutorial is needed, you cljs code will send network calls against your Django server (localhost in dev?)

emccue15:06:31

That works fine usually, but the way it is set up, I need to test data preloaded by the server which is just put in the head

richiardiandrea15:06:19

emccue: that data lives in the server and unless you expose it using a GET or something you won't be able to access it (it is python right?)

emccue15:06:18

No, it's being preloaded in the template

emccue15:06:56

Exposed with window.PRELOAD

emccue15:06:11

The rest of the data is fetched via GET

richiardiandrea15:06:29

Oh ok, so everything in the browser should be visible, you just need to use some cljs interop. I don't think figwheel handle this specifically but I might be wrong. You can ask in #lein-figwheel as well.