Fork me on GitHub
#clojurescript
<
2016-12-06
>
chooie04:12:24

Anyone have an idea on best practices for running tests in a cljs repl (using Boot)? Got a basic skeleton going but it’s not working. My test runner:

(ns wordroot.test
  (:require
   [cljs.test :refer-macros [run-all-tests]]))

(defn run-frontend-tests
  []
  (run-all-tests #”^wordroot.*-test$”))
How I attempt to execute it at the repl:
(ns cljs.user
                 (:use [wordroot.test :only [run-frontend-tests]]))
(run-frontend-tests)

chooie04:12:36

Update: Including the namespace in my core.cljs file fixes the issue of the namespaces not being included

chooie04:12:39

However, executing (run-frontend-tests) just returns nil now

aengelberg07:12:30

What is the difference between clojure.core/instance? and cljs.core/implements??

aengelberg07:12:47

Obviously there are differences between the Java and JS versions of things we're working with. I'm mostly curious why they have to be named differently.

stevechan07:12:51

js : {aaa : 111, bbb : 222, ccc : 333 } , how to write to cljs ?

aengelberg07:12:40

@stevechan: In cljs we generally use immutable maps: {:aaa 111, :bbb 222, :ccc 333}. If you really need a mutable JavaScript object type, you can use #js {:aaa 111, ...}

stevechan07:12:32

if i want to call aaa method, how to do?

stevechan07:12:43

for #js {:aaa 111, …}

stevechan07:12:19

how to write it by cljs ?

aengelberg07:12:28

looks like

#js {:showDropdowns true,
     :showWeekNumbers true,
     :opens "right",
     :buttonClasses #js ["btn btn- ......
     ...

aengelberg07:12:57

Note that you can also write a Clojure data structure (same thing without the #js's) and then call clj->js on the whole thing, which recursively transforms all maps into objects and all vectors into arrays

aengelberg08:12:54

You can call aaa method by calling (.aaa my-obj my-args)

stevechan09:12:43

document.getElementsByClassName("applyBtn")[1].onclick = function(){alert(111)}

stevechan09:12:47

Not found onclick ?

stevechan09:12:09

How to write it by cljs ? for document.getElementsByClassName("applyBtn")[1].onclick = function(){alert(111)}

stevechan09:12:31

that’s work ok, thanks 😄

thheller12:12:33

@chooie to run tests you must require all namespaces that include tests as well not just cljs.test

dnolen13:12:47

@aengelberg you should avoid implements? it’s a perf thing only to avoid the bottleneck in satisfies?

dnolen13:12:33

to answer your question, there are no interfaces in JS, so instance? can’t be used to test for protocol membership

dnolen13:12:47

(testing for protocols requires macros)

mitchelkuijpers13:12:52

Can anyone see why my conformer does not work?

(defn valid-money? [x]
  (let [res (cond-> x
              (string? x) money/string->number)]
    (if (money/nan? res)
      :clojure.spec/invalid
      res)))

(s/def :sale.line/amount (s/conformer valid-money?))

(s/def :sale.line/description (s/and string? #(re-matches #".+" %)))

(s/def :sale/line (s/keys :req [:sale.line/amount
                                :sale.line/description]))

(s/conform :sale/line {:sale.line/amount "wrong"
                       :sale.line/description "foo”}) => {:sale.line/amount :clojure.spec/invalid, :sale.line/description "foo"}
spec does not seem to care that I return :clojure.spec/invalid

mitchelkuijpers14:12:02

Omg it has to be cljs.spec/invalid

thheller14:12:16

@mitchelkuijpers use ::s/invalid, just to be safe 😉

mitchelkuijpers14:12:32

That would be a better solution

mitchelkuijpers14:12:57

@thheller Thank you that works like a charm

mitchelkuijpers14:12:19

(was already seeing himself adding clj and cljs reader conditionals)

Aron14:12:11

most of it is empty

Aron14:12:25

wait, wrong channel, srorry

Aron15:12:27

not that it makes a difference, seems like i get one answer a month from the clojure community, otherwise i am completely ignored

cmal16:12:54

Does clojurescript frontend production env need a pm tool like pm2 of js? Why if not?

noisesmith16:12:14

what is a "frontend production env" ?

dacopare16:12:01

From https://github.com/Unitech/pm2: >"PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks."

noisesmith16:12:39

@dacopare the word that confuses me there is "frontend" which that page does not mention

noisesmith16:12:04

I mean, node.js on the frontend in production - does that imply running a cluster on the client machine or what?

noisesmith16:12:53

I know what a load balancer is, and I'm familiar with node, but a load balanced node frontend I don't get

noisesmith16:12:47

if the question is whether pm2 is useful when using cljs as a backend on node, I'd make a wild guess that it would be as useful as it would be with js

borkdude17:12:59

How do I eval a javascript snippet in ClojureScript again?

robert-stuttaford18:12:58

(js/eval “window.alert(‘eval is evil’)”)

borkdude18:12:43

js* was what I was after, thanks 😉

danielglauser18:12:53

Is anyone else here using Petrol? https://github.com/krisajenkins/petrol We use it in one of our projects. Hasn't seen any commits since January.

krisajenkins18:12:41

Perhaps I should raise my hand for this question. 🙂

krisajenkins18:12:16

Petrol is the distillation of the approach I'd used with ClojureScript apps for the couple of years prior to releasing that library. My main aim was to crystallise the pattern, so I could describe it at ClojureX 2015.

krisajenkins18:12:35

I still believe in the approach, and it’s how I’d tackle a ClojureScript project if I were starting one today.

krisajenkins18:12:00

I haven’t had any ClojureScript gigs this year. So that’s why there’s been no activity on it. 😞

danielglauser18:12:26

Thanks for explaining that. Saw open PRs, issues, and no commits since January so I figured I'd ask. I'm just getting up to speed with it now. Seems similar to an approach I was originally pushing for, which was to use CQRS on the front-end. I like the similarities and the extra structure the library provides, was just concerned about the longer term maintenance.

danielglauser18:12:01

I'll keep my ears to the ground for anyone looking for a hired gun @krisajenkins

krisajenkins18:12:24

My best advice would be to take the pattern and make it your own. (That’s what I did for 2 years before it got a name.) It’s really only about 120 lines I think. It’s more idea than codebase. 🙂

krisajenkins18:12:05

And, thank you. 😉

danielglauser18:12:35

Sounds good, thanks Kris! I've posted in the Den of Clojure (Denver user group) Slack to see if anyone is looking for a contractor.

krisajenkins18:12:47

Aw, thanks. 🙂

jrheard18:12:42

sorry you’ve been having that experience

Aron18:12:03

could be worse 🙂

Aron18:12:07

just saying why the complains

Aron18:12:14

i didn't start with complaining 😄

ddellacosta19:12:46

soooo I have tried this before but in the past I believe it was not possible: is there a way to get the current namespace in CLJS?

dnolen19:12:06

@ddellacosta no - no namespace or var hijinks are possible in non-bootstrapped ClojureScript

borkdude19:12:25

does cljsjs always load the minified version of the js file in a package?

anmonteiro19:12:43

@borkdude: no. Only if 1. A :file-min is specified (which I assume it is in your case) And 2. You're compiling with :simple or :advanced

Lone Ranger20:12:17

hi there 🙂 is there a good channel for clojurescript noobs?

shaun-mahood20:12:20

@goomba: #beginners is a great place to ask any type of question, Clojure or ClojureScript

Lone Ranger20:12:31

great, thank you 🙂

michaeldrogalis20:12:40

Has anyone tried using core.async to handle “catastrophic backtracking” in a regular expression? This is particularly problematic in JavaScript where regular expression calls may never return, thus locking up a Go block completely. I’m having trouble extracting a value from the Go block or timing out, and I suspect it’s because the Go block can’t release control.

michaeldrogalis20:12:02

This is notably not a problem on the JVM, the rub is because of JS’s single threading.

michaeldrogalis20:12:02

To be more specific, after launching a Go block that will execute a catastrophically bad regex evaluation, other Go blocks cannot start.

dnolen20:12:15

@michaeldrogalis there isn’t a solution to that problem since it doesn’t have anything to do with core.async

dnolen20:12:25

if you write something that doesn’t terminate in JS - nothing we can do about it

michaeldrogalis20:12:04

@dnolen That makes sense, thanks for verifying. 🙂

danielcompton22:12:02

@michaeldrogalis I agree there's probably not much you can do for a catastrophic regex, but @viebel detects something like this in Klipse, not sure how he does it, or under which circumstances it is applicable.

michaeldrogalis22:12:40

@danielcompton Attempting to stuff it into a web worker or some such. 😕 It’s not a particularly fun problem.

jrheard22:12:26

heh solving klipse lockups was pretty fun

jrheard22:12:56

clever idea, works great for klipse, not sure if it’s generalizable though

jrheard22:12:32

basically there are two pieces to it 1) a go-block that periodically wakes up every N milliseconds and updates a “this is the last time i woke up” atom, and 2) the JS that klipse emits includes a bunch of calls to guard, which checks to see if the “this is the last time i woke up” atom hasn’t been updated in a long time, and throws an exception (killing the currently executing function) if so

jrheard22:12:19

the idea is that if you’ve got an infinite loop, it’ll block the “watchdog” go-block from running and trigger the guard bailout; https://github.com/viebel/klipse/pull/131/files#diff-b818e251587635f1ae83246d9765c30d is the relevant code

jrheard22:12:56

again i don’t know if this approach makes sense in any other context but this one, i don’t think most people will want to write+use modified versions of cljs.compiler/emits

mac22:12:28

What is the best way to debug cljs-ajax calls? I am getting a very non-informative error from the server. Is there a way to see the actual request being made?

michaeldrogalis22:12:49

@jrheard Interesting. Thanks for the pointer, Ill dig into this patch.

dnolen23:12:47

@mac yes Chrome DevTools can show you all the requests

dnolen23:12:04

look at the Network tab

mac23:12:14

@dnolen Thanks, got the request now. Works when pasted into the browser, but still fails when called from code.

dnolen23:12:00

@mac try goog.net.XhrIo instead. I avoid 3rd party libs for requests - less to deal with

dnolen23:12:30

trying it another way might give you more information about cljs-ajax if you want to keep using it

mac23:12:28

@dnolen 🙂 js/fetch works fine, but using cljs-ajax because of re-frame - trying that channel - thanks.