Fork me on GitHub
#clojurescript
<
2016-12-29
>
jimmy00:12:53

hi guys, I'm looking forward to update cljsjs react-dates but I'm not sure how to generate extern for this lib. How can we get the single js file to generate extern file ?

Busy escaping the comfort zone01:12:32

Hey, looking for a way of selecting items from a Vector using Specter (like srange but for any index), couldn't find a way of doing: (select [ALL <?>] [[1 2 3 4 5] [1 2 3 6 7]]) -> [[2 5] [2 7]]

Busy escaping the comfort zone01:12:55

(select [ALL (multi-path (keypath 1) (keypath 4)) ] rs)

Busy escaping the comfort zone01:12:19

but it flattens out the result

michaelstalker02:12:09

Has anyone used both cljs-http and cljs-ajax, and could give any feedback on their pros and cons?

michaelstalker02:12:04

Forgive me if this is a frequent question. I've been looking for an idiomatic way to perform HTTP requests, and have found an overabundance of resources. It's hard to choose!

michaelstalker02:12:34

(Or, if all I needed for now was to do GET requests, would you recommend just using goog.net.XhrIo and core.async?)

jimmy02:12:39

I use XhrIo and there is no single problem yet. Because it's simple and it works

karolisl07:12:42

Hello, I'm developing a script in cljs on nodejs. For release (=production) build I want to have a single file with all my code, for which I use :optimizations :simple but looks it like it minifies my variable names. Is it possible to not have the variable renaming? It's pretty uncomfortable to see a.request is not a function.

olslash07:12:11

the main function of simple is to shorten the var names

olslash07:12:17

you might want whitespace-only mode

olslash07:12:49

actually a sourcemap might be a better option

karolisl07:12:28

I am using sourcemaps, but the exception is still TypeError: a.request is not a function, also sourcemap suggest error to be one line above the actual line (I have a s-exp splitted into 2 or 3 lines there)

karolisl07:12:39

Regarding :whitespace java.lang.AssertionError: Assert failed: :nodejs target not compatible with :whitespace optimizations 😞

karolisl07:12:18

So it might be that there's nothing better to do than to fill a feature request or something? 🙂

olslash07:12:26

yeah sorry my experience is shallow

seako07:12:26

my experience here is also shallow but i believe you will need something like https://github.com/nervous-systems/cljs-nodejs-externs in order that the closure compiler will not alter those symbols

karolisl07:12:03

Ok, I'll investigate that. Thank you very much!

pesterhazy08:12:03

@karolisl, simple solution: use optimization: whitespace

pesterhazy08:12:24

don't think simple optimization offers significant benefits when running on node

karolisl08:12:12

@pesterhazy sadly, but I cannot do that: java.lang.AssertionError: Assert failed: :nodejs target not compatible with :whitespace optimizations

pesterhazy08:12:32

wow, who knew?

pesterhazy08:12:40

sorry for the noise

pesterhazy08:12:08

I'm curious why whitespace won't work with node

karolisl08:12:12

Maybe you know a place where I could submit a feature request?

karolisl08:12:02

Strange. https://groups.google.com/forum/#!topic/clojurescript/dCu5J7ngezE Looks like it should be fixed by now, but with latest cljs and lein-cljsbuild versions I still get the same assertion errror. 😞

mikepjb13:12:03

(ns cljs.install
  (:require [cljs.nodejs :as node]))

(println "Script initialized")
(node/require "util")
(def process (.-spawn (node/require "child_process")))
Is there a different way to set variables for js objects in clojurescript? the following code results in a TypeError Cannot read property 'process' of undefined

mikepjb14:12:37

fyi this is being run using clojurescript-nodejs

mikepjb14:12:34

seems to have been a namespace conflict

mikepjb14:12:01

changing the ns to test.install or anything other than cljs.X resolves the issue

dnolen14:12:17

@aengelberg we create ClojureScript compiler 2 artifacts, 1) is normal sources JAR 2) the other is AOT'ed

dnolen14:12:49

the later loads significantly faster since you don’t have to compile 10,000 lines of Clojure to start compiling ClojureScript

dnolen14:12:07

if somebody is trying to get this working with Lein though, it’s not your problem - I’ve never been able to get it work

dnolen14:12:33

you should ask them to try it with just Maven

gfredericks14:12:21

I am using reagent for the first time (first time using anything reacty) and am trying to build a pair of input components where editing one changes the value in the other

gfredericks14:12:33

e.g., you could imagine a celcius:left_right_arrow:fahrenheit converter

gfredericks14:12:51

the happy case I got working fine by having one piece of global state that they both display the value of

gfredericks14:12:03

but I'd like the text boxes to support invalid input

gfredericks14:12:17

where it shows an error message below, but leaves the bad input in the text box for the user to edit

gfredericks14:12:39

but if the user goes to the other box and puts something valid there, the bad input in the other box would go away

gfredericks14:12:13

my hunch was that I needed local state for each component to hold its current value, but I'm not sure about how to wire the whole thing together

gfredericks14:12:13

currently I have a local atom for each component, and a global atom for the state that gets updated on valid input; but I can't get the effect of " if the user goes to the other box and puts something valid there, the bad input in the other box would go away"

gfredericks14:12:59

I imagine I could hack something together by stapling more global state to more side effects, but I'm hoping there's some Better Way to do it

adamfrey14:12:26

can someone explain what’s going on under the hood to make this happen?

(let [win js/window]
   (.-innerWidth win))
=> 1920
(let [window js/window]
   (.-innerWidth window))
=> TypeError: Cannot read property 'innerWidth' of undefined

dnolen15:12:15

@adamfrey just look at the generated JS

dnolen15:12:36

if you’re messing with this in a REPL simple to do by wrapping your expression in (fn [] …)

dnolen15:12:10

(meaning there may be code-gen issue here - I don’t know)

sova-soars-the-sora15:12:18

Hi I'm using LightTable and within lightTable my code renders in a Browser Tab (awesome!) but I would also like to preview it in a browser. I have figwheel running in a separate terminal, but connecting to localhost:3449 only loads the html page, not any of the associated js...

adamfrey15:12:16

thanks for the (fn [] …) technique, David. It doesn’t look like a CLJS code gen problem, it’s a quirk in JS that I didn’t know about.

function broken () {
  var window = window;
  return window
};
broken() => undefined

adamfrey15:12:23

not a quirk so much as a hoisting issue, I guess

gfredericks15:12:07

well it'd be nice if cljs wasn't sensitive to that; but that might be impractical, I dunno.

gfredericks15:12:09

okay so cljs locals can shadow the global js namespace I guess?

adamfrey15:12:20

@gfredericks yes they can. Which I guess I didn’t realize until now

gfredericks15:12:28

is there no reliable way of getting at it?

gfredericks15:12:55

I thought generally js/window was the entrypoint to the global ns but if window itself can be shadowed then I don't know what fallback there is

gfredericks15:12:28

if window really is unique and special I suppose cljs could special-case-munge it for locals

adamfrey15:12:53

here’s an example of that shadowing, for reference:

(fn []
  (let [window 1]
     (inc window)
      (.-innerWidth js/window)))
=> #object[ret__8703__auto__ "function (){
var window = (1);
(window + (1));

return window.innerWidth;
}"]
I also feel like the answer might be “It’s not practical to avoid this"

gfredericks15:12:55

the compiler already has to munge things

gfredericks15:12:55

if it's just an extra line of code in the compiler somewhere, I have a hard time believing that's worse than saying every cljs programmer everywhere has to remember to never use window as a local name

dnolen15:12:27

@adamfrey yeah now that I understand your example, you shouldn’t expect that to work

thheller15:12:59

@adamfrey I get different code from the compiler

thheller15:12:16

var window_41135 = (1);
(window_41135 + (1));

window.innerWidth;

dnolen15:12:23

@adamfrey goog.global is a thing also

dnolen15:12:19

though admittedly that would make your code more opaque

adamfrey15:12:25

@thheller how did you generate that?

thheller15:12:59

(let [window 1]
  (inc window)
  (.-innerWidth js/window))
in a file

thheller15:12:32

but the fn version does generate the "wrong" code

thheller15:12:08

(defn x []
  (let [window 1]
    (inc window)
    (.-innerWidth js/window)))

thheller15:12:43

test.x = (function test$x(){
var window = (1);
(window + (1));

return window.innerWidth;
});

thheller15:12:51

(in test ns)

dnolen15:12:52

hrm, now that I think about it window should be in the shadow list

thheller15:12:15

@dnolen it works on the top level, but not inside fn

adamfrey16:12:00

@dnolen I can create a ticket if you’d like

dnolen16:12:30

@adamfrey go for it! Thanks!

rauh16:12:02

@adamfrey You can probably add navigator and document to the list. See https://www.youtube.com/watch?v=mHtdZgou0qU#t=7m

lwhorton17:12:31

Hrm. I’m stuck on a way to return a symbol from a fn… if that’s even the right strategy. The pandeiro/boot-http lib for http-proxying accepts a :handler ‘my.app/some-ring-handler argument (a symbol). If I wanted to do something like

...
(boot-http/serve :handler (make-proxy “/my-api/” “”)
...
I would need to return a symbol for serve. How does one generate a function inside a function, and instead of returning the generated function, return a symbol for that function? Is this totally incorrect?

peeja17:12:43

@lwhorton Are you sure it's 'my.app/some-ring-handler and not #'my.app/some-ring-handler?

peeja17:12:51

It's weird for it to take a symbol

peeja17:12:27

Oh, maybe it takes a symbol as well, for command-line usage

lwhorton17:12:41

If I were to simply define a proxying function as a let block, and return the symbol of that fn, does a closure hold onto that symbol?

(defn make-proxy [args]
  (let [prox (-> routes (wrap-proxy args))] (symbol “my-handler” prox))
?

peeja17:12:10

I'd expect to be able to pass a function instead. Have you seen whether that works yet?

peeja17:12:52

A symbol is convenient on the command line, but if you're specifying it in clojure-land anyhow, I'd hope a function would work too

lwhorton17:12:56

I would also expect that, but it doesn’t seem to take anything but a var/symbol

geoffs17:12:59

@lwhorton you might have better luck asking about this in the #boot channel too since this is more related to using boot

lwhorton17:12:06

java.lang.IllegalArgumentException: option :handler must be of type sym

peeja17:12:16

Ah. Well, that's unfortunate.

lwhorton17:12:35

I was considering that, but this was also interesting as a more general clojure question

peeja17:12:48

But to answer the Clojure part of the question… a symbol is just a value, like a string

lwhorton17:12:00

Can you bind a local symbol and return it, and expect the lookup sym->var to “stick around” in a closure?

peeja17:12:18

The only relationship it has with the function is that if you look up the var named by that symbol in the namespace, you'll get a var that contains a function

peeja17:12:42

so there's no notion of a "local binding" of a symbol like that

peeja17:12:00

(which is why it's weird for something like this to take a symbol)

lwhorton17:12:21

are let blocks made "top level” during resolution, then?

lwhorton17:12:14

like inside my.ns the (let [foo #()] …) becomes my.ns.some-fn/foo?

peeja17:12:54

No, the let bindings are separate, and don't use namespaces

lwhorton17:12:07

interesting, I clearly don’t understand this fully

lwhorton17:12:34

so a symbol is just a name for a var, but the var holds the real value

peeja17:12:39

When the compiler reads foo inside a let that binds foo, it connects that reference to that foo. If it doesn't see a local binding, it resolves it as my.ns.some-fn/foo instead

peeja17:12:59

(or some other namespace, if you've :refered that symbol from elsewhere)

peeja17:12:08

That's it precisely.

peeja17:12:20

(Which I think is different from some other lisps?)

lwhorton17:12:54

Not sure, but I’m curious why the symbol at all and not a var?

peeja17:12:07

Why the symbol what?

lwhorton17:12:22

If symbols just name vars why do we need them, and why can’t we go straight to a var?

peeja17:12:33

Ah, because they don't just name vars

peeja17:12:43

A symbol is a value, like a keyword or a string

peeja17:12:10

It's treated specially by the reader, though: when the reader finds it, it tries to resolve it to a value

peeja17:12:33

which is either from a local binding or from a var in a namespace

peeja17:12:08

You can also quote it as 'some-symbol and get the name itself

peeja17:12:00

Symbols are important, for instance, in macros, where your code is given the actual forms in the call the user made

peeja17:12:43

So, if you call (my-macro foo (bar baz)), your my-macro gets two arguments: the symbol foo and the list of two symbols (bar baz)

peeja17:12:02

Those symbols haven't been resolved yet, and you can do whatever you want with them

peeja17:12:19

my-macro may interpret foo as some kind of special instruction, for instance

lwhorton17:12:42

i see... thinking about them as primitive values passed around to later be resolved makes it more clear

peeja17:12:54

Yep, that's exactly it

lwhorton17:12:58

oh the joys of a new language *to me 🙂

lwhorton17:12:18

many thanks

peeja17:12:38

Generally a "handler" argument in an HTTP server takes a function

peeja17:12:32

and often it's convenient to pass the var containing that function, because you can call a var like a function and it will pass the call on to the function inside it

peeja17:12:14

but if you change the definition of the function (say, by changing the code at dev time and reloading it), the var will now point to the new definition, and you won't have to reload your server to get the new handler function into it

peeja17:12:56

But passing a symbol to an HTTP server as the handler is pretty weird, and probably only used here because typing myapp.server/app at the boot CLI passes a symbol to the function

lwhorton17:12:46

I agree and would also expect the task to accept a fn or a symbol (or a var)

wilkerlucio20:12:54

hello, I'm having a strange compilation problem with ClojureScript

wilkerlucio20:12:02

my project compiles fine with :none optimizations

wilkerlucio20:12:12

but by trying any other compilation I'm getting the error:

wilkerlucio20:12:22

I tried to modify my project, and try to compile a simple file containing only a (def hello "world")

wilkerlucio20:12:33

even trying to compile only this, the error still happens

wilkerlucio20:12:00

I tried removing dependencies, and after a fill tries I figured that Datomic dependency seems to be the one causing some problem

wilkerlucio20:12:22

by removing the [com.datomic/datomic-pro "0.9.5530"] dependency the simple file starts compiling again

wilkerlucio20:12:53

any idea what might be happening? I'm stuck with what to try next

henriklundahl20:12:15

Perhaps lein deps :tree can provide some insight?

wilkerlucio20:12:52

thanks @henriklundahl , I figured the guava dependency on datomic and clojurescript are clashing somehow, following the recomendations on lein deps :tree I removed guava from clojurescript first, but that was erroring, by excluding it on datomic the cljs compilation worked

wilkerlucio20:12:53

well, datomic doens't even need to be load to compile cljs, maybe a good idea would be to put it in some profile and remove that profile while compiling the JS, I'm afraid excluding it from datomic dep might cause some problems running datomic on the server

stbgz22:12:24

hey all does anyone know of a non-spa template for luminus using clojurescript?

ajss23:12:48

I'm trying to extract some of my code in a clojurescript web app into a library to be shared with another project. Is there a standard, modern, plain lein template for a clojurescript library?

geoffs23:12:11

@ajss I don't think a special purpose cljs template will get you much on top of the default lein app template... there isn't really much configuration needed for building a clojurescript library...

ajss23:12:29

So, just lein new, then add clojurescript as a dependency, src/cljs as a source path? Thanks 🙂