Clojurians
#clojurescript
<
2016-01-22
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

kanwei00:01:43

anyone have any idea how to get this piece of code to compile under advanced compilation?

kanwei00:01:46

:component-will-receive-props #(.destroy @dt)

kanwei00:01:05

where @dt is a jQuery object stored in an atom

dnolen00:01:40

@kanwei: you need externs for jQuery

dnolen00:01:50

so you’ll need an extern file that includes destroy somewhere

kanwei00:01:05

that actually did work

kanwei00:01:13

how did it figure it out even though it was for a cljs atom?

richiardiandrea00:01:27

it did not figure out, but simply you told him not to purge the destroy method during compilation

richiardiandrea00:01:53

the rest is JavaScript and dynamically typed languages magic :smile:

mfikes02:01:07

I’ve never seen this before: A case (in bootstrapped ClojureScript) where I wanted a function value to evaluate to itself if passed to cljs.js/eval. I wonder if you can even do this... https://gist.github.com/mfikes/3433645e09bca86268a5

dnolen02:01:52

@mfikes: it’s possible to do that in Clojure, probably needs some thought wrt. what exactly we should support in bootstrapped

mfikes02:01:30

@dnolen: By the way, the above is just for fun. But it would indeed be cool if it can be pulled off :simple_smile:

jaredly04:01:21

looks like there’s no ns-resolve in clojurescript :confused: I can hack it with (aget js/my.name.space (munge varname)) but is there a better way?

mfikes04:01:48

@jaredly: Just so happened to add one to Planck.

mfikes04:01:04

(But, it uses bootstrapped capabilities.)

mfikes04:01:12

@dnolen FWIW, I’m solving my function value problem by instead putting numbers into the emitted JavaScript that are then looked up. It works for lambdas, etc.: https://github.com/mfikes/planck/blob/7005b6b3ffa90fb92823e1ccc14059b3acedabc0/planck-cljs/src/planck/repl.cljs#L935-L965

mfikes04:01:59

cljs.user=> (ns foo.core)
nil
foo.core=> (def x 3)
#'foo.core/x
foo.core=> (ns bar.core)
nil
bar.core=> (require '[planck.core :refer [ns-resolve]])
nil
bar.core=> (ns-resolve 'foo.core 'x)
#'foo.core/x
bar.core=> @(ns-resolve 'foo.core 'x)
3

jaredly05:01:21

(reduce (fnil aget (js-obj)) js/window (conj (vec (map munge (.split (str the-ns) “.”))) (str the-sym))) works great

grounded_sage05:01:37

I saw someone post a video a while ago with web & iOS & tvOS all running at same time and coding it from a repl. Does anyone know if that is still online and where I can find it?

mfikes05:01:32

@grounded_sage: You are probably recalling https://github.com/artemyarulin/ktoa

mfikes05:01:30

The only tvOS thing I’m aware of is https://youtu.be/eaWy5mliO38

grounded_sage05:01:58

Cheers. First one was the eons I was seeking

grav07:01:37

Is it a hack to use (.-length my-fn)?

grav07:01:20

I want to do either (my-fn val1) or (my-fn val1 val2) depending on the arity of my-fn

meow07:01:57

@grav: not sure what you are asking or trying to do - can you clarify

grav07:01:05

@meow: (.length my-fn) returns the arity of a function (it’s a javascript interop thing)

grav07:01:18

So I can apply the function to either one or two args

grav07:01:59

Eg

(case (.-length my-fn)
  1 (render cell-value)
  2 (render cell-value row-value))

meow08:01:32

@grav: I see.

meow08:01:42

seems a bit hacky, but I haven't run into the need for that so it might be what you need to do

meow08:01:40

personally I would work my way out of the need for that

meow08:01:01

do you control the fn passed in as my-fn?

meow08:01:04

I think you need to provide more context - this seems like a code smell to me

grav10:01:02

@meow: yeah, agreed. it’s an attempt of uniting two interfaces into one, in order to make everybody happy :wink:

puzzler13:01:08

This blog (http://blog.fikesfarm.com/posts/2016-01-20-self-calls-type-hints-and-memoization.html) says that in clojurescript, the type hint for a return value needs to be before the function definition. Is that a bug? I thought type hints for return values always go before the parameter list(s).

dnolen13:01:15

@puzzler: that’s never been true in Clojure

dnolen13:01:40

the before the parameter list support only came after the numerics change

nxqd13:01:42

hi guys, I have a weird problem that whenever I include a namespace, the app just doesn't work ( the namespace and its function works fine in another namespace ) . The app ( main function ) shows blank page

slackbot13:01:43

Yo it's clojurian, whats up ?

dnolen13:01:48

@nxqd: sounds unlikely with the information you’ve provided thus far

bronsa13:01:11

@dnolen: since 1.8 type hinting before the argvec is the only reliable way to type hint return values in clojure

niwinz13:01:33

I'm a little bit confused with the blog post that @puzzler references, https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L401

niwinz13:01:03

cljs puts the type hints before the function name symbol

niwinz13:01:12

but the blog post says that is the wrong place

puzzler13:01:35

@dnolen See http://clojure.org/reference/java_interop. It says return values are type hinted before arguments vector. (This allows different type hints for functions that can take different numbers of args). In 1.8, I believe Clojure can throw an error if you put the type hint before the function name (this is also referenced in the blog post I referred to). So right now, Clojurescript behaves quite differently from Clojure, it appears.

nxqd13:01:53

@dnolen: it doesn't print out any error message. Just blank page, there is nothing special in that namespace. I'm aware of cycle deps, can it be the cause ?

dnolen13:01:08

@nxqd no idea, make something minimal so we can stop guessing :simple_smile:

dnolen13:01:00

@puzzler all I know is how it worked before and that’s there a lot of code that is the old way

dnolen13:01:09

@puzzler take it up with @alexmiller

dnolen13:01:44

which is to say I don’t have a definitive answer

dnolen13:01:55

and I don’t really consider the clojure website to be definitive about stuff like this

bronsa13:01:25

In clj type hinting on the function name only works if the type hint is a non primitive type

puzzler13:01:36

So is it correct to say that Clojurescript currently does not support different type hints on return values for functions with multiple arities?

dnolen13:01:51

@puzzler: you don’t need type hints at all in ClojureScript

dnolen13:01:01

reflection isn’t a thing

dnolen13:01:05

nor are primitives

niwinz13:01:24

^boolean is useful typehint in cljs as far as I know ..

dnolen13:01:39

@niwinz: it really isn’t unless you know what you are doing

puzzler13:01:40

Sorry, I haven't tried this myself, but according to that blog post, type hinting a return value as boolean can change the outputted Javascript code to something more efficient.

dnolen13:01:10

@puzzler: it will elide a truth test

dnolen13:01:25

it’s useful for critical predicates that show up in benchmarking

dnolen13:01:30

i.e. persistent data structures

niwinz13:01:44

In any case would be awesome have cljs and clj work in the same way with type hints

dnolen13:01:07

@niwinz: unlikely to happen

dnolen13:01:12

since the type hints can’t mean the same thing

dnolen13:01:30

as to the more narrow problem of where the type hint can appear

dnolen13:01:35

sure, happy to take a patch for that

niwinz13:01:55

Then, you says that clojurescript does not need at all the type hints, so why the cljs.core is full of typehints?

dnolen13:01:06

@niwinz: I already explained that

dnolen13:01:49

if you’re referring to the other type hints (i.e. not boolean), I would not assume anything about that stuff

dnolen13:01:58

either experimental or does nothing

niwinz14:01:03

So if I understand well, it is likelly that a patch for change the typehint order is welcome (for make it consistent with clojure...)? I'm wrong?

dnolen14:01:49

there will be no change to the order

dnolen14:01:56

only additive support

niwinz14:01:46

of course, I expressed myself badly

niwinz14:01:03

thanks, nice to know!

arohner15:01:45

figwheel is not re-drawing my page, and I’m not sure why. Is there any general advice to check? I’ve seen figwheel redraw successfully on this project, and I get the CLJ logo on-screen when I save files,

rasom15:01:29

@arohner: Do you have something like :figwheel {:on-jsload “ns.do-something-on-reload”} in your project.clj?

arohner15:01:35

@rasom: no

rasom15:01:01

can you show figwheel's config from project.clj?

arohner15:01:07

:figwheel {:http-server-root "public"
                              :port 3449
                              :repl false
                              :nrepl-port 7888
                              :css-dirs ["resources/public/css”]}

darwin15:01:30

is there a way how to name anonymous function for debugging purposes? I mean achieving emitting of "named function expression” http://stackoverflow.com/questions/3854141/naming-an-anonymous-function

anmonteiro15:01:50

is it possible to see the CLJS compiler environment under &env in macros?

anmonteiro15:01:36

If so, under what key should it be?

limist16:01:50

Possibly dumb question, but, what's the best way to check if js/some_var is defined, or not?

bronsa16:01:59

@limist: exists?

spinningtopsofdoom16:01:05

(exists? js/some_var)

jaredly16:01:08

@darwin: like you want the cljs compiler to automatically add names to #() fns? or do you want to do (with-name “somename” #(…))

dnolen16:01:17

@anmonteiro: yes

darwin16:01:25

@jaredly: second one

bronsa16:01:39

(fn foo [..] ..)

anmonteiro16:01:44

@dnolen: was just going to write that I just found it under cljs.env

dnolen16:01:51

@anmonteiro: ah, k cool

anmonteiro16:01:14

@dnolen: I'm looking in the right place, right? cljs.env/*compiler*. I can use that, ye?

jaredly16:01:15

@darwin: if you control the output on the other end, you can just add a custom attribute to the fn, e.g. (aset thefn “my-debugging-name” thename)

dnolen16:01:31

@anmonteiro: if you’re going to examine the compiler environment directly you should be OK with that not working at some point in the future

jaredly16:01:39

Or you could have with-name be a macro that creates a named function

dnolen16:01:54

otherwise you should use one of the helper macros in cljs.analyzer.api if something is missing

dnolen16:01:57

open a ticket and add it

limist16:01:01

@bronsa: @spinningarrow Thanks, wonder why that wasn't on http://cljs.info/cheatsheet/

anmonteiro16:01:39

@dnolen: this is in regards to Om invariant support. Maybe we should talk in #C06DT2YSY? Just asked here because it was a CLJS general question

arohner16:01:57

does om/refresh! at a toplevel owner refresh all child owners?

dnolen16:01:23

@darwin you can just name anon fns if you like

jaredly16:01:30

@darwin: or with-name could just wrap the anon fn in a new, named fn (if that suits your needs - e.g. for tracebacks)

dnolen16:01:44

at one point I toyed with giving all fns a name but this undesirable for many reasons

dnolen16:01:59

it’s worth considering as a compiler option for debugging purposes

dnolen16:01:15

as usual patch welcome

bronsa16:01:24

@dnolen: care to share some of those reasons?

dnolen16:01:35

@bronsa: global scope pollution

bronsa16:01:06

wouldn't the clj-jvm munging scheme work for cljs aswell?

darwin16:01:10

thanks all, works for me

bronsa16:01:37

*ns*$local_name$fn__gensym

dnolen16:01:04

@bronsa the JVM is not JavaScript

dnolen16:01:14

I mean JS global scope pollution

bronsa16:01:43

ok, I don't know enough about how the JS global namespace works to understand why that would be a problem :simple_smile:

dnolen16:01:57

you’re just going to see a bunch of junk at the top level

dnolen16:01:09

thus compiler flag

bronsa16:01:16

ok, thanks

dnolen16:01:46

for named top level fns we already do what you suggest

dnolen16:01:04

as some JS tooling only looks at the actual fn name, not the var assignment

jaredly16:01:12

hmm I wonder how many of those functions would be on the global scope, though? seems like most of them would be in some closure or other

dnolen16:01:43

@jaredly: that’s not how ClojureScript works

dnolen16:01:06

we emit Google Closure namespaces, we don’t wrap in closures

dnolen16:01:12

would damage REPL driven development

jaredly16:01:58

right — yeah that’s not what I meant. I meant a fn that’s actually defined inside of another function. (defn something[] … #(this-is-in-a-closure))

dnolen16:01:40

ah right for the cases where you are inside another fn yes - that's another possible compiler enhancement instead of doing it blindly

dnolen16:01:16

that may even be halfway done - I can’t remember if I just lost interest in it since the top level thing was more useful for debugging, perf profiling

dnolen17:01:01

@darwin stuff like that is better for #C07UQ678E

laforge4917:01:25

Having problems unit testing with crisptrutski.boot-cljs-test.

laforge4917:01:15

error: Writing clj_test\suite.cljs... Writing output.cljs.edn... Compiling ClojureScript... WARNING: Replacing ClojureScript compiler option :main with automatically set value. ò output.js Running cljs tests... ERROR: doo was not loaded from the compiled script. Make sure you start your tests using doo-tests or doo-all-tests and that you include that file in your build

laforge4917:01:32

Was told on the boot channel that it works on non-windows

laforge4917:01:52

First time unit testing in clojure script, first time using phantomjs.

dnolen17:01:44

@laforge49: it’s a boot-centric question - but yeah maybe some Windows people here know about it

laforge4917:01:06

fingers crossed

laforge4917:01:16

Next step is to post an issue

dnolen17:01:26

it maybe that boot doesn’t properly handle Windows path conventions as well

dnolen17:01:36

it took a bit of wrangling to get that sorted out in ClojureScript for sure

juhoteperi17:01:41

Probably boot-cljs-test specific problem

dnolen17:01:39

@laforge49: it may be worth your time to examine boot-cljs-test to look for any obvious error around file paths

dnolen17:01:47

I can’t imagine the project is very big

laforge4917:01:11

Thanks :simple_smile:

dnolen17:01:10

@laforge49: in ClojureScript anyway we just went and replaced hard coded “/“ with File/separator

seantempesta18:01:11

@zavalit: Yeah, I just got it working yesterday

seantempesta18:01:28

Requires a bit of finessing to get it running.

zavalit18:01:34

i don’t get any letters in input field

zavalit18:01:52

cursor just doesn’t move

zavalit18:01:45

@seantempesta: can you share it maybe per gist

seantempesta18:01:01

Yeah. I had the same problem. You’ll need to do two things. In search-field change :onKeyUp to :onChange

seantempesta18:01:16

And you’ll need to upgrade to the latest alpha of om-next.

zavalit18:01:49

@seantempesta: cool, i got the input working, and now it throws "Uncaught TypeError: Cannot read property 'call' of undefined"

seantempesta18:01:11

Yeah, that’s why you need to upgrade to the latest alpha. I think it’s 29?

seantempesta18:01:19

[org.omcljs/om "1.0.0-alpha29-SNAPSHOT"]

zavalit18:01:58

@seantempesta: thx a lot, you save me a bunch of brainfucking

seantempesta18:01:16

@zavalit: np! :simple_smile:

seantempesta18:01:26

Anyone here using om-next with react-native? I’ve found a lein template and a natal template so far. Any tips on which one is better or if there is another better approach? https://github.com/artemyarulin/om-next-cross-platform-template https://github.com/dmotz/natal

mfikes18:01:24

@seantempesta: There is a #C0E1SN0NM channel with users interested in those subjects :simple_smile:

seantempesta18:01:47

ah, perfect. Thanks @mfikes

artemyarulin18:01:33

Mine is better! :smile:

zavalit19:01:47

@seantempesta: sorry for bothering you, it’s still throws smth. wiered, in my case, i get after upgrading to org.omcljs/om "1.0.0-alpha29" an error: *Uncaught TypeError: uri.call is not a function with pointing to uri out of *(defn jsonp ([uri] (println uri) (jsonp (chan) (uri)))... any idea why it can be that way?

seantempesta19:01:07

Lein clean and rm the contents of the js folder?

seantempesta19:01:52

And you updated the I'm dependency in your project file?

seantempesta19:01:54

Not sure. It’s working for me.

zavalit19:01:04

it look’s like it gets url string and tries to call it

zavalit19:01:16

and it fails

seantempesta19:01:40

You’re importing Jsonp? (ns om-tutorial.core (:require-macros [cljs.core.async.macros :refer [go]]) (:require [goog.dom :as gdom] [cljs.core.async :as async :refer [<! >! put! chan]] [clojure.string :as string] [om.next :as om :refer-macros [defui]] [om.dom :as dom]) (:import [goog Uri] [http://goog.net Jsonp]))

zavalit19:01:54

looks pretty much the same

seantempesta19:01:34

Yeah, not sure what’s going on. I just made those two changes and it started working for me.

zavalit19:01:46

ok, anyway thank you

futuro19:01:40

@zavalit: so instead of (jsonp (chan) (uri)) it should be (jsonp (chan) uri)

zavalit19:01:45

@futuro: realdeal, i’m a dumb

futuro19:01:57

no worries :simple_smile:

zavalit19:01:16

@seantempesta @futuro thx guys, now i can finally grab some friday beer :+1:

seantempesta19:01:38

Awesome. Have one for me. :simple_smile:

ddellacosta19:01:30

so, I’m sure this question has been asked a bazillion times, but: is there a good way to stub out js/document (and I guess maybe other stuff, this is just the current wall I’m running up against) in the CLJS nashorn repl?

ddellacosta19:01:57

I tried doing this before, and I can get this working with a test runner easily, but can’t figure out how to do testing in the repl

venantius19:01:52

Is there a reason you’re not using something like Figwheel to get a browser REPL you can develop with?

ddellacosta19:01:20

don’t want to?

ddellacosta19:01:38

more specifically, trying to do the simplest thing I can first

venantius19:01:59

okay. I don’t think that’s a great answer; if you want to have access to a browser environment where things like js/document will just work, a bREPL is the tool you should be using

agile_geek19:01:01

A REPL is not a substitute for tests, surely? Regression?

ddellacosta19:01:14

…I’m trying to run tests in the repl, if that’s not clear

ddellacosta19:01:29

to get a quick feedback loop going

venantius19:01:32

can we see what sort of tests you’re trying to run?

venantius19:01:42

I’m a little confused about where this is breaking down

ddellacosta19:01:57

it’s breaking down as soon as I require anything in my ns

ddellacosta19:01:58

which refers to something in the DOM

ddellacosta19:01:04

the tests don’t even get loaded/run

ddellacosta19:01:21

so sorry—not even a question about tests, apologies for the confusion

bensu19:01:25

@ddellacosta: it is an uphill battle to test DOM stuff in nashorn

ddellacosta19:01:30

simply loading up namespaces

ddellacosta19:01:49

bensu, yeah, so far that’s what it seems like. :confused:

ddellacosta19:01:13

really would love to have something that is very minimal to stub stuff out, but I’m starting to think I’ll have to write that myself

bensu19:01:50

@ddellacosta: I would try to use node's repl and then find an npm package that has some dom stubs

bensu19:01:21

or, I would just use a browser as venantius suggested and then run the tests on Slimer/Phantom

ddellacosta19:01:30

yeah, I mean, that’s basically what I do now

ddellacosta19:01:46

just would really like to have the same quick feedback loop I do with Clojure tests

ddellacosta19:01:06

anyways, thanks @bensu, sounds like that’s the state-of-the-art right now

ddellacosta19:01:14

will check out node’s repl

venantius19:01:50

I guess the way I would think about it is this

venantius19:01:54

if you’re writing tests that touch the DOM

venantius19:01:03

presumably you’re writing an app or library that need to touch the DOM as well

venantius19:01:23

I’m not sure why you’d go out of your way to use a tool that isn’t intended for browser / DOM interaction

venantius19:01:40

using the Node runtime for this feels like trying to fit a square peg to a round hole

venantius19:01:51

It’ll work, but sooner or later you’ll want a browser repl anyways

ddellacosta19:01:39

I suppose the answer is that I’ve got too much coupling in my code, and want to separate out DOM-specific stuff from non-DOM-specific stuff

ddellacosta19:01:53

but I need an interim solution before I strip everything out

ddellacosta19:01:50

in any case, ideally I don’t really do much DOM testing anyways other than at the edges, but it’ll take some time to get there, and I just want something now that lets me stub stuff out so I can at least load namespaces up without getting errors

dnolen19:01:46

@ddellacosta: you’re on your own if you haven’t separated DOM bits from non-DOM bits

dnolen20:01:08

this is the reason Google Closure Library is so useful - it doesn’t make any assumptions

dnolen20:01:35

the best way to deal with this - think about it ahead of time

ddellacosta20:01:31

yes, I understand that, thanks for reminding me that my system is not perfect dnolen

dnolen20:01:12

@ddellacosta: everyone can use reminding about this particular pitfall - it’s really too painful to be stuck on the other side of it

dnolen20:01:35

having made this mistake myself far too many times in my JS days

comamitc21:01:37

Is there a preferred place (channel) to post issues with CLJS compilation?

dnolen22:01:11

@comamitc: yes this is the place to report perceived issues, and we’ll see if it’s actually a problem

dnolen22:01:01

@comamitc: if there is an actual issue, then you can make a JIRA ticket

firstclassfunc22:01:29

I am just getting my head around core/async. is the pattern to call your go routine in a function and update the DOM or pass the channel down to another function?

dnolen22:01:19

@firstclassfunc: there’s not really an established pattern around core.async and the DOM

dnolen22:01:40

most people are using some React binding abstraction, not core.async to deal with the DOM

firstclassfunc22:01:28

@dnolen thanks yes, sorry i am using a react component updated by a cljs-http call to Datomic

dnolen22:01:42

@firstclassfunc: I’m not aware of any specific patterns for React in general in this case - it also depends on what binding you’re using - they have different community idioms

comamitc22:01:56

@dnolen: got it; thanks! I think I got past my issue so now I know for future reference :+1:

firstclassfunc22:01:06

@dnolen I simply want to return a collection from a cljs-http call so I can render it in OM.. But of course the return is a Go channel not my collection

dnolen22:01:57

@firstclassfunc: sounds like you need pass some kind of callback

firstclassfunc22:01:29

@dnolen: Yea that makes sense, I just have to figure out how that will work with devcards.. Tks

actsasgeek22:01:27

are there any secrets or gotchas for converting d3 javascript to ClojureScript? I’m trying to convert this example: http://bl.ocks.org/mbostock/3885304#index.html and everything seems to work except for the:

svg.append("g")
      .attr("class", "x axis")
      .attr("transform", "translate(0," + height + ")")
      .call(xAxis);
line. A straight conversion to:
(.. svg
    (append "g")
    (attr "class" "x axis")
    (attr "transform" (str "translate( 0," height ")"))
    (call x-axis))
results in a Uncaught TypeError: Cannot read property 'insertBefore' of null but taking out just the (call x-axis) works (but there’s not axis, obviously. Grrr.

actsasgeek23:01:17

Here’s a gist of all the code. https://gist.github.com/actsasgeek/3120ac9cdae44c5264b0 It’s very perplexing. If I remove both of the expressions that add the x-axis and y-axis, I get bars. If I remove (call x-axis) and (call y-axis) I get the <g> elements so it seems to be the call calls that are messing something up. I checked the values of x-axis and y-axis in the console and they are apparently identical to what the JS returns.

dnolen23:01:01

@actsasgeek: there’s a typo in what you pasted, early closed paren

actsasgeek23:01:29

yeah, let me fix that…it’s corrected in the gist.

dnolen23:01:46

@actsasgeek: otherwise seems fine

dnolen23:01:00

Chrom DevTools can save you a lot of time here, just set a breakpoint and see what’s going on

actsasgeek23:01:13

ok, thanks. I’ll have to give them a try.