Fork me on GitHub
#clojurescript
<
2016-08-17
>
bwstearns00:08:32

So I want to make a clojurescript library that can eventually be used by JS programs. I've sat down and sketched out the idea and messed around a bit on a repl thinking it through and I am about to start coding. Is there a good example/lein template for starting out a project with the intention of making a cljs library vs the more general templates? I threw a couple queries at google but js interop and more generic lein examples are crowding out the search.

bwstearns00:08:55

Is Mies the goto cljs template?

shaunlebron02:08:58

@bwstearns: I don’t think there’s a goto cljs template right now

shaunlebron02:08:13

mies was the standard for a while, but it shifted away from cljsbuild when cljs.jar became the quick start method. and now we have tenzing template for the boot, which is an alternative to lein

shaunlebron02:08:45

any of them will work, you just need to use ^:export metadata on vars you want accessible from JS, or goog.exportSymbol explicitly to customize the name

bwstearns02:08:20

thanks @shaunlebron, I ended up just spinning up a figwheel lein project and I'll cut it down to the library when I've got something.

onetom05:08:13

not sure how to search for it, so i would ask here: is there an equivalent of coffeescript's existential operator in clojurescript?

zip = lottery.drawWinner?().address?.zipcode
becomes
zip = typeof lottery.drawWinner === "function" ? (ref = lottery.drawWinner().address) != null ? ref.zipcode : void 0 : void 0;
i would hope to have something similar in clojurescript, so i wouldn't need to write for example
(when error (.-message error))

gerrit07:08:19

some-> should work the same way

pupeno09:08:45

I remember a very useful function to convert objects into string representations that worked nicely with console.log. Does anybody know what might be the name of such function?

brabster09:08:26

@pupeno: you mean JSON.stringify(...)?

brabster09:08:42

oh sorry you mean cljs?

pupeno09:08:51

In clojurescript… it was something like pt-str

darwin11:08:41

@pupeno: clojure.pprint/pprint?

pupeno11:08:15

Darwin I'll try it later when I'm home, but the function I'm looking for was definitely a short name with two words it, such as pt-str.

chancerussell15:08:56

Anyone know if there’s a way to make the clojurescript compiler fail on warnings?

chancerussell15:08:07

Or at least return something other than 0?

dnolen15:08:14

@chancerussell: yes - you can supply custom warning handlers

risto16:08:24

whats the status on spec/instrument and spec/gen? have they been ported over to clojurescript?

risto16:08:46

I tried using them but I couldn't get them to work, but it might've been because of my setup

anmonteiro16:08:04

@risto: Spec is at feature parity with Clojure as of 1.9.216

risto16:08:27

oh ok, then I must be doing something wrong 😓

risto16:08:27

when I try to use (println (s/exercise-fn 'myfunc)) (' is backtick) I get java.lang.AssertionError : Assert failed: (symbol? sym)

sdegutis17:08:15

Is there any "framework" or library that lets me define a back-end end-point in my ClojureScript, such that I can call a Clojure function on it, and it'll locate the corresponding Clojure function in the back-end (via RPC or something), call it, and return the result, assuming it's just EDN?

sdegutis17:08:44

In other words, is there something that lets me call a Clojure server from a ClojureScript front-end, as if it was in the same process, but only assuming EDN arguments and return values?

anmonteiro17:08:45

@sdegutis: never used it, but I think this looks like what you’re looking for? https://github.com/hoplon/castra

sdegutis17:08:27

Neat, yeah that looks right.

cdine17:08:11

Is there a cljs nrepl client available?. Tried googling , but no luck.. There is one available as a node module though...

chris17:08:33

piggieback

cdine17:08:27

Thanks @chris. Checking it out.

wildermuthn17:08:21

Does anyone know of a parser that transforms javascript into cljs code, using simple interop?

wildermuthn17:08:02

I run into this about once every few weeks, where I want to take a nodejs example and just run it as cljs. Usually doesn’t take long to manually transform it, but still… 🙂

jasonjckn18:08:58

my production javascript files are getting cached, anyone have an example on how to solve this, I understand you're suppose to add myfile.js?rel=x.y.z i was thinking of adding the md5 hash of the file, i'd like this to be automatic my lein build

jasonjckn18:08:39

(the issue is older versions of my SPA are loaded on clients browsers even when a new JS file is shipped to the server)

jasonjckn18:08:45

until they invalidate their cache

darwin18:08:13

@cdine: there is no cljs or javascript implementation of nREPL client, AFAIK

darwin18:08:14

I wanted an nREPL client in Dirac DevTools, ended up running it on server-side and opening a websocket tunnel to it from client-side: https://github.com/binaryage/dirac/blob/417b81c3959e9b156f148f9448f2935f33631658/src/lib/dirac/lib/nrepl_tunnel.clj#L13-L47

chancerussell18:08:17

@timothypratley: Very interesting. Thank you!

cdine18:08:50

Thanks @Dirac.. That was helpful..

risto19:08:21

is there a way to use clojure.test.check.clojure-test/defspec with cljs.spec.test/check?

risto19:08:16

or really more generally to integrate cljs.spec.test/check⁠ with clojure.test?

dnolen19:08:33

@risto not as far as I know

sherbondy19:08:04

@darwin: do you by any chance know if there’s anything lacking in https://developer.chrome.com/apps/sockets_tcp that would prevent me from implementing a proper nREPL client with it?

darwin19:08:15

@sherbondy: no, it should be possible to use that api to implement real TCP connection to nREPL server

darwin19:08:12

I needed it from a normal web app or extension, so this option wasn’t available for me

sherbondy19:08:33

ah right, chrome apps only 😕

darwin19:08:14

but maybe there is another option, to teach nREPL server another transport, e.g. websocket

darwin19:08:24

I haven’t explored that

darwin19:08:22

that would require people running nREPL server to configure it and still you would have to implement clojure.tools.nrepl and bencode on client-side, which is a lot of work

darwin19:08:50

maybe not bencode, I don’t remember exactly if it is part of transport protocol or not

darwin19:08:13

ok, it is part of the transport, so you could use json or edn, when implementing websocket transport to make your life easier: https://github.com/clojure/tools.nrepl#transports-

cdine20:08:13

@darwin , thanks.. will take a look at this

richiardiandrea21:08:42

Has anyone faced this issue with clojure.spec in cljs?

clojure.lang.Compiler$CompilerException: java.lang.NoClassDefFoundError: com/google/common/base/Predicate, compiling:(cljs/closure.clj:1:1)
         java.lang.NoClassDefFoundError: com/google/common/base/Predicate
       java.lang.ClassNotFoundException: com.google.common.base.Predicate
                                                  ...                       
                cljs.closure/eval7975/loading--auto--      closure.clj:    9
                   cljs.closure/eval7975/invokeStatic      closure.clj:    9
                                cljs.closure/eval7975      closure.clj:    9

dnolen21:08:41

@richiardiandrea: it does not look spec related

richiardiandrea21:08:11

ok thanks David I will investigate more

richiardiandrea21:08:24

I am saying spec because it coincided with me introducing it in the cljc files but it might actually be something else

dnolen21:08:39

just doesn’t look related to me

richiardiandrea22:08:30

false alarm, I was excluding the guava dependency in the project for some obscure reason

richiardiandrea22:08:13

oh...it is tricky to spec a number in javascript (not an expert here)

richiardiandrea22:08:33

(instance? js/Number 3) => false

anmonteiro22:08:41

@richiardiandrea: what’s wrong with cljs.core/number?? 🙂

richiardiandrea22:08:11

@anmonteiro: I guess nothing

richiardiandrea22:08:31

just better 🙂

richiardiandrea22:08:00

(I mean yours is better)

(s/def ::timestamp #?(:clj #(instance? Long %)
                      :cljs #(number? %)))

richiardiandrea22:08:14

kind of ok for now ahah

anmonteiro22:08:18

@richiardiandrea: there’s also number? in clojure

anmonteiro22:08:35

but can be float, double etc

richiardiandrea22:08:36

it should actually be a long in clj

anmonteiro22:08:09

I think long? exists

richiardiandrea22:08:27

nope I don't see it, but today I am not seeing things 😉

richiardiandrea22:08:51

yeah no it is not there

anmonteiro22:08:02

@richiardiandrea: I wonder where it went

richiardiandrea22:08:33

I was going to quit for today but thankfully you saved my day 😄

richiardiandrea22:08:04

I'll stick with the instance check but thanks for pointing that out

risto22:08:28

@dnolen: I came up with something, though it's a little quick and dirty: https://gist.github.com/Risto-Stevcev/dc628109abd840c7553de1c5d7d55608

risto23:08:33

clojure specs seem to bring something like gradual dependent types to clojure/script

risto23:08:44

i'm curious about how it might integrate with core.logic

spieden23:08:02

hmm, do you mean core.typed?

risto23:08:51

core.logic

risto23:08:14

using the power of spec with core.logic to construct proofs about your program

risto23:08:32

though I've never used core.logic yet, but I think it might be useful for that sort of thing

spieden23:08:04

yeah i started reading reasoned schemer — never got around to applying any of it

risto23:08:03

nice -- yea I'm planning on reading that real soon 🙂

spieden23:08:40

main utility for everyday programming seems to be when you have a bunch of conditions that need to be satisfied for some result, and when you don’t get that result you want to introspect why. with just functional programming not so easy, but with logic programming just assert the result and the set of conditions that are satisfied to get back the ones that aren't

risto23:08:32

yeah you get a little bit of that with :fn in fdef, but it doesn't handle situations where you want to prove that your program behaves a certain way when interacting with other functions (ie transitivity)

risto23:08:22

you could use this ad-hoc type system with logic programming to prove that kind of stuff, though admittedly I've only played around with some really trivial stuff in Idris for that sort of thing

spieden23:08:38

ah i was talking about business logic vs behavior of code, but i think i follow