Fork me on GitHub
#clojurescript
<
2017-01-30
>
lvh00:01:17

@alun Cloverage doesn’t do ClojureScript, but should be not that hard to port to it since it’s a source transformation

lvh00:01:30

@alun As its maintainer I’d be happy to do code review 🙂

bhauman00:01:09

[lein-figwheel 0.5.9] has just been released

mrg02:01:02

I have been playing with the new externs inference feature. Does anyone know how to typehint this correctly?

mrg02:01:49

My best guess was this, but that didn't seem to work:

sova-soars-the-sora06:01:43

So I learned in my pursuit of secure sockets and such for my cljs application..... always use HTTPS. That way, all communication is within an encrypted layer. On top of that, you can do logins and the initial over-the-wire username/pw combination can be considered secure. Once you have passed a token back to the client that they send on every request, you can also encorporate some "is this the same IP as before?" and make sure tokens expire over time so that your site stays secure even if token info is somehow compromised

jiangts07:01:40

I just upgraded to cljs 1.9.456 and my conformer spec started throwing errors

jiangts07:01:13

error is cljs.spec.spec_impl.call(...).call is not a function

jiangts07:01:02

;; conformer
(defn coll->set [x] 
  (cond
    (set? x) x
    (coll? x) (set x)
    :else :clojure.spec/invalid))

(s/def ::my-spec-coll (s/coll-of ::my-spec :kind (s/conformer coll->set) :into #{}))

danielstockton08:01:54

I'm seeing a problem with array-seq in advanced compilation mode. Works fine with no optimizations but in production I keep getting Cannot read property 'length' of undefined exceptions.

danielstockton08:01:02

It's within a this-as macro that I'm calling array-seq

thheller10:01:36

@danielstockton the array you call array-seq on: does it come from a javascript option which might need externs? ie. (array-seq (.getThatArray someJsObject))

thheller10:01:43

that is missing externs?

danielstockton10:01:51

@thheller yes, thats probably it.

thheller10:01:03

:pseudo-names true is very useful for such situations

danielstockton10:01:57

What does that do exactly? Emit certain warnings during compilation?

danielstockton10:01:35

I'll just try it out..

pesterhazy10:01:59

it'll mangle names, but in a predictable way

danielstockton10:01:04

The lib i'm using is a cljsjs package, does that mean they missed an extern?

danielstockton10:01:33

@pesterhazy Does that mean it's not something I want turned on all the time for my production builds? Are there disadvantages to it being true?

pesterhazy10:01:35

it may not mean that, e.g. if it's in a callback

pesterhazy10:01:59

no you only turn it on during dev time, temporarily, to figure out what's going on

danielstockton10:01:23

Ah right, ok. It is in a callback, would adding ^:export metadata help?

pesterhazy10:01:42

no I don't think so

danielstockton10:01:56

(aget this "field")?

pesterhazy10:01:56

probably best to just use goog.object/get instead of .- notation

pesterhazy10:01:18

IMO every call to .- needs to vetted to see if it'll continue to work during adv comp

pesterhazy10:01:38

personally I mostly resort to goog.object/get by default these days

danielstockton10:01:11

Ok, thanks for the help, that sorted it.

isaac13:01:41

How to find all vars in some namespace? Clojure has ns-publics

dnolen13:01:19

@isaac there’s no way to do those kinds of Clojure var things at runtime

dnolen13:01:43

you can do it at compile time with macros and the cljs.analyzer.api namespace

isaac13:01:45

The cljs.analyzer.api/ns-publics returns is not vars. I want to filter vars by meta data.

moxaj13:01:43

argh ... cljsbuild fails on travis-ci with Can't redefine a constant at line 61 ..., but it works locally. I've fought this issue once, but it went away, now it came back out of the blue 😞

moxaj13:01:03

back then I assumed this was a windows issue, but travis runs linux

tomaas14:01:44

hi, in a regeant project template, I've added [org.clojure/core.async "0.2.395"] in my project.clj file, and then in core.cljs I require [cljs-http.client :as http] [cljs.core.async :refer [&lt;!]]

tomaas14:01:11

running lein figwheel in project root, I get this error: No such namespace: cljs-http.client, could not locate cljs_http/client.cljs, cljs_http/client.cljc, or Closure namespace "cljs-http.client"

dnolen14:01:47

@tomaas you didn’t declare your dependency on cljs-http in your project.clj

tomaas14:01:47

sorry, thanks @dnolen

dnolen14:01:30

@isaac you can use it to return vars, cljs.test does this trick as well - you might want to look there for ideas

dnolen14:01:09

you could also just filter on the meta at compile time

Roman Liutikov15:01:12

FYI: I just built ClojureScript app with React directly from NPM and there seem to be a bug, you can read more about it here https://github.com/facebook/react/issues/8887

anmonteiro16:01:00

@roman01la: have you tried your cljs-npm-test under none or simple optimizations?

anmonteiro16:01:30

I get an error which is also of the form of the issue you opened

anmonteiro16:01:50

this._instantiateReactComponent is not a function

Roman Liutikov16:01:26

@anmonteiro No, I didn’t. But I’m setting up dev build at the moment, so we’ll see

anmonteiro16:01:46

It's not specific to your repo btw, happens whenever you consume React from NPM

Roman Liutikov16:01:03

ok, I’m doing that on the app at work

anmonteiro16:01:13

No idea why it works in advanced mode

anmonteiro16:01:20

And not in other modes

leov16:01:10

hihi. can you point me to routing examples in case where I have subcomponents? (menu, submenu) (still learning react)

leov16:01:16

not sure how to choose which component from root menu to render, when I have subcomponent of the submenu =/

Roman Liutikov16:01:37

@anmonteiro for some reason I couldn’t even make figwheel see a foreign lib js module which requires stuff from NPM cc @bhauman I’m using [figwheel-sidecar "0.5.9"]

tianshu16:01:51

for the infer-externs feature of 1.9.456, It seems failed to infer my project. https://github.com/DogLooksGood/HiccupMacroParser Is there any tips for how to write code that can get correct externs inference?

tianshu17:01:11

It seems like the problem is related to this line.

(.setState this# new-state#)
https://github.com/DogLooksGood/HiccupMacroParser/blob/master/src/one/macros.cljc#L54 this.setState has been compressed to something like c.Za.

dnolen17:01:27

@doglooksgood externs inference isn’t automatic in that way - have you read through the guide?

dnolen17:01:38

it works via warning on missing type-hints and uses those type hints to compute externs

tianshu17:01:17

No yet, I'm going to read the guide.

tianshu17:01:23

I walk through the guide and start adding type hints. all warning solved except this:

(fn [db]
    (let [f-type (:filter db)
          f (case f-type
              :all identity
              :active (complement :completed?)
              :completed :completed?)]
      (->> (get db :todos)
           (filter f))))
WARNING: Cannot infer target type in expression (. f-type -fqn) there's no javascript library interop.

thheller17:01:03

fairly certain that is the case accessing the fqn of the keyword(s)

thheller17:01:59

so safe to ignore

dnolen18:01:29

@doglooksgood hrm thanks will take a look at that- but yes safe to ignore

leov19:01:04

quick question: In :cljsbuild configuration I had to prepend :asset-path "js/compiled/out" with leading "/", otherwise when my server url is not root, I was getting figwheel warning, and it tried to find my js modules within current url subpath. so now my :asset-path is "/js/compiled/out". Am I doing it right?

leov19:01:20

(but official documentation says "js/compiled/out", as well as chestnut configuration sets it so? Sure it was corrected before, and I couldn't encountered the problem first?)

rauh19:01:50

@leov No you're good, that's one of the first things I change. I've seen this question a few times and this is the correct answer to your problem

leov19:01:04

omg thanks. I guess we should update both figwheel and chestnut >_<

leov19:01:03

(and probably clojurescript wiki/site)

dmillett19:01:17

If anyone is interested, I am trying initialize an open source project that facilitates building campaigns for public office in a transparent and less costly manner. There are more details in the #political-canvas channel

jiangts20:01:21

did anybody else get the cljs.spec conformer errors on 1.9.456 that I mentioned last night?

jiangts20:01:20

for reference: I just upgraded to cljs 1.9.456 and my conformer spec started throwing errors [11:04] error is cljs.spec.spec_impl.call(...).call is not a function [11:06]

;; conformer
(defn coll->set [x] 
  (cond
    (set? x) x
    (coll? x) (set x)
    :else :clojure.spec/invalid))

(s/def ::my-spec-coll (s/coll-of ::my-spec :kind (s/conformer coll->set) :into #{}))

jiangts20:01:22

seems like there were breaking changes

dnolen20:01:34

@jiangts need more information and something more minimal

dnolen20:01:40

what you have is not enough to go on

jiangts20:01:40

@dnolen hmm, ok. In my actual codebase it’s basically

(defn coll->set [x] 
  (cond
    (set? x) x
    (coll? x) (set x)
    :else :clojure.spec/invalid))

(s/def ::my-spec int?)
(s/def ::my-spec-coll (s/coll-of ::my-spec :kind (s/conformer coll->set) :into #{}))
(s/def ::my-spec-wrapper (s/keys :req-un [::my-spec-coll]))

(s/valid? ::my-spec-wrapper {:my-spec-coll [1 2 3]})

jiangts20:01:56

and on the call to s/valid? I get the cljs.spec.spec_impl.call(...).call is not a function error

jiangts20:01:05

is that more helpful?

dnolen20:01:18

@jiangts I don’t see this issue

dnolen20:01:41

@jiangts also :clojure.spec/invalid should be ::s/invalid

jiangts20:01:27

aha, didn’t realize that. And I’ll play around a bit more in my repl to see if I can isolate the problem a bit better

dnolen20:01:55

yeah - I copied and pasted your code and I don’t see that error

jiangts20:01:27

ok so playing in the figwheel REPL

jiangts20:01:47

(defn coll->set [x]
  (cond
    (set? x) x
    (coll? x) (set x)
    :else ::s/invalid))

(s/def ::set-ints (s/coll-of int? :kind (s/conformer coll->set) :into #{}))
(s/def ::vec-ints (s/coll-of int? :kind vector? :into []))
(try
  (s/valid? ::set-ints [1 2 3])
  (catch js/Object e
    (js/console.error e)))
(s/valid? ::vec-ints [1 2 3])

jiangts20:01:04

prints

TypeError: cljs.spec.spec_impl.call(...).call is not a function
    at eval (eval at figwheel$client$utils$eval_helper (utils.cljs?rel=1485763033743:57), <anonymous>:2:151)
    at cljs.spec.every_impl.cljs$core$IFn$_invoke$arity$4.cljs.spec.t_cljs$spec92144.cljs$spec$Spec$conform_STAR_$arity$2 (spec.cljs?rel=1485763028944:844)
    at cljs$spec$conform_STAR_ (spec.cljs?rel=1485763028944:40)
    at Function.cljs.spec.valid_QMARK_.cljs$core$IFn$_invoke$arity$2 (spec.cljs?rel=1485763028944:357)
    at cljs$spec$valid_QMARK_ (spec.cljs?rel=1485763028944:353)
    at eval (eval at figwheel$client$utils$eval_helper (utils.cljs?rel=1485763033743:57), <anonymous>:1:137)
    at eval (eval at figwheel$client$utils$eval_helper (utils.cljs?rel=1485763033743:57), <anonymous>:9:4)
    at eval (eval at figwheel$client$utils$eval_helper (utils.cljs?rel=1485763033743:57), <anonymous>:17:3)
    at eval (eval at figwheel$client$utils$eval_helper (utils.cljs?rel=1485763033743:57), <anonymous>:22:4)
    at figwheel$client$utils$eval_helper (utils.cljs?rel=1485763033743:57)

dnolen20:01:46

@jiangts remove Figwheel from your tests if you’re trying to isolate the bug

dnolen20:01:00

try to recreate the problem with the Quick Start uberjar thanks

jiangts21:01:25

ok, made a new project from mies template and updated the deps to cljs 1.9.456

jiangts21:01:34

and ran the same code as above and got the following:

jiangts21:01:41

TypeError: cljs.spec.spec_impl.call(...).call is not a function
    at core.cljs:10
    at cljs.spec.every_impl.cljs$core$IFn$_invoke$arity$4.cljs.spec.t_cljs$spec9434.cljs$spec$Spec$conform_STAR_$arity$2 (spec.cljs:844)
    at cljs$spec$conform_STAR_ (spec.cljs:40)
    at Function.cljs.spec.valid_QMARK_.cljs$core$IFn$_invoke$arity$2 (spec.cljs:357)
    at cljs$spec$valid_QMARK_ (spec.cljs:353)
    at core.cljs:13

jiangts21:01:31

the contents of the file are simply

(ns repro.core
  (:require [cljs.spec :as s]))

(defn coll->set [x] 
  (cond
    (set? x) x
    (coll? x) (set x)
    :else ::s/invalid))

(s/def ::set-ints (s/coll-of int? :kind (s/conformer coll->set) :into #{}))
(s/def ::vec-ints (s/coll-of int? :kind vector? :into []))
(try
  (s/valid? ::set-ints [1 2 3]) 
  (catch js/Object e
    (js/console.error e)))
(s/valid? ::vec-ints [1 2 3]) 

dnolen21:01:18

@jiangts just do it with the Quick Start please

jiangts21:01:26

how do I do that?

dnolen21:01:26

that’s the only thing we’ll take for bug reports

jiangts21:01:09

so download that cljs jar file and run it like java -cp cljs.jar:src clojure.main release.clj?

jiangts21:01:19

sorry I’ve only really used lein + figwheel so far

dnolen21:01:46

when trying to figure out bugs need to remove all variables except ClojureScript

jiangts21:01:33

ok. Did that and got the same error:

jiangts21:01:38

TypeError: cljs.spec.spec_impl.call(...).call is not a function
    at core.cljs:10
    at cljs.spec.every_impl.cljs$core$IFn$_invoke$arity$4.cljs.spec.t_cljs$spec860.cljs$spec$Spec$conform_STAR_$arity$2 (spec.cljs:844)
    at cljs$spec$conform_STAR_ (spec.cljs:40)
    at Function.cljs.spec.valid_QMARK_.cljs$core$IFn$_invoke$arity$2 (spec.cljs:357)
    at cljs$spec$valid_QMARK_ (spec.cljs:353)
    at core.cljs:13

dnolen21:01:17

and I will take a look later - if I can repro will definitely get resolved by the next release

dnolen21:01:41

there are some other things that need fixing that have come up so it won’t be long

jiangts21:01:55

awesome, thanks!

itruslove22:01:09

Anyone got a suggestion for a library to do selectors on Hiccup? I know of https://github.com/cjohansen/hiccup-find, but it doesn’t work with long form elements like [:div {:class “foo”}], only CSS-selector style like [:div.foo]. I suspect that this functionality has to exist in some library somewhere, even as a support function...