Fork me on GitHub
#clojurescript
<
2019-06-06
>
vemv02:06:52

Error: Unable to resolve spec: :cljs.core.specs.alpha/params+body
Why would I get this? I'm developing a .cljc library. I'm using #?(:clj [clojure.core.specs.alpha :as specs] :cljs [cljs.core.specs.alpha :as specs]) and the latest versions of clj + cljs + core.specs.alpha

Alex Miller (Clojure team)02:06:23

doesn't cljs already automatically alias the clojure namespace to the cljs one?

8
vemv03:06:30

tried out, no luck. I wiped all references to the cljs version of the require, leaving the clj require only, and unconditionally. but I still get the same exact error

thheller08:06:35

@U45T93RA6 these specs are currently only accessible in the CLJ version. don't know why but they aren't usable in CLJS at runtime

thheller08:06:55

the .cljs file is empty and just loads the specs in macro form

vemv08:06:46

weird b/c there are no defmacros in the .cljc file thanks for the pointer!

thheller09:06:54

yeah I'm not sure why the .cljs file exists. it isn't necessary

thheller09:06:20

might be for self-hosted reasons

vemv10:06:28

now to make things even weirder, I am seeing java.lang.Exception: Unable to resolve spec: :clojure.core.specs.alpha/params+body when consuming my library from a JVM app. When developing/testing the lib, the spec could be resolved. Any idea of what it might be?

Alex Miller (Clojure team)12:06:13

What does “consuming” mean? Those specs are loaded by the Clojure RT. Is it possible you’re using an entry point via Java such that they aren’t loaded?

vemv16:06:00

Consuming means that ns l from library L requires clojure.core.specs.alpha. And a ns a from app A requires l When developing/testing L everything is OK, when running A I get the error > Is it possible you’re using an entry point via Java such that they aren’t loaded? Not entirely sure what this means / how that would happen. I use the Reloaded workflow with vanilla requires and project organisation

vemv16:06:13

(posted again -and more clearly- in #clojure-spec since this doesn't have to do with clojurescript anymore)

shidima08:06:10

how would I write something like this in cljs:

const { exec } = require('child_process');

Roman Liutikov08:06:15

(def cp (js/require "child_process"))

shidima08:06:54

It throws an error ReferenceError: require is not defined

kstehn08:06:52

just need to add this to your :require [child_process :as child-proc] then you can use child-proc in your code and can use exec with (.exec child-proc)

Roman Liutikov08:06:30

@shidima are you sure the code runs as Node.js process?

Roman Liutikov08:06:09

@slack1038 In this case it can be (child-proc/exec ...)

shidima08:06:11

@slack1038 That works, thanks

shidima09:06:13

How do I get the output of this:

(child-proc/exec "ls" 
   (fn [err stderr stdout]
      (println stdout)
      (println stderr)))
#object[ChildProcess [object Object]]

kstehn09:06:49

in my project it gets printed with (println (.toString stdout))

Chris Swanson10:06:33

anyone know how to get figwheel to run with openjdk11 (I'm getting java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter)

ghadi13:06:45

what version of lein?

zane17:06:33

Maybe try in #figwheel, also?

Alan Thompson17:06:51

I am running Java 12 (was 11) with Figwheel-Main. Are you on the old figwheel?

Alan Thompson17:06:02

Just checked an older figwheel (not -main) project, and it runs on Java 12 too. Have you tried the Oracle JDK?

ghadi17:06:28

it's not the jdk, it's lein

ghadi17:06:53

i think lein itself is failing, not the project

Alan Thompson17:06:49

> lein --version Leiningen 2.9.1 on Java 12.0.1 Java HotSpot(TM) 64-Bit Server VM

Chris Swanson10:06:43

tried just adding the deps but no luck

Chris Swanson10:06:20

for context i'm trying to build a cljs expo app so there could be something else weird going on

borkdude18:06:17

is there any downside of using hash as a key on React items?

isak19:06:11

undefined behavior if/when you get a collision

coby19:06:29

Hey folks, so I have this map of options I get back from a REST endpoint and I need to loop through them and render them as <option>s.

{"439" "Alderwood Park"
 "440" "Alling Park"
 "443" "Baltimore Park"
 "2885" "Browns Point Athletic Complex"
 "450" "Browns Point Lighthouse Park"
 "451" "Browns Point Playfield"
 "454" "Center at Norpoint"
 "446" "Charlotte's Blueberry Park"
 "3689" "Charlotte's Blueberry Park Community Garden"
...
 "566" "Wapato Hills Park (Skip and Laura Vaughn Playfield)"
 "3490" "Wapato Hills Sprayground"
 "567" "Wapato Park"
 "572" "Wright Park"
 "3499" "Wright Sprayground"}
Problem is, they're rendered in the wrong order. Is there a way to loop over this map in a way that preserves the order, or do I need to convert to a seq before looping and sort explicitly? Here is what I have currently:
(doall (for [[value label] options]
  ^{:key value} [:option {:value value} label]))

borkdude19:06:52

@ctamayo they are not rendered in the order you receive them?

dpsutton19:06:16

it looks like they are received and put into a map which has no order. what you're looking at there is already "too late"

borkdude19:06:27

ah that’s a good point 😉

borkdude19:06:11

so the backend should return a list of maps instead one giant map to preserve order

dpsutton19:06:05

seems javascript objects are ordered

dpsutton19:06:17

(according to a cursory look)

coby19:06:21

Yeah, they appear that way to me too

>> obj1 = {one: "one", two: "two"}
Object { one: "one", two: "two" }
>> obj2 = {two: "two", one: "one"}
Object { two: "two", one: "one" }
>> Object.keys(obj1)
Array [ "one", "two" ]
>> Object.keys(obj2)
Array [ "two", "one" ]

coby19:06:32

but, good thought about the backend

borkdude19:06:45

but they aren’t in the JSON spec

dpsutton19:06:01

(also that test there would pass in cljs)

coby19:06:30

if that test would pass in cljs, how is it that maps are not ordered?

dpsutton19:06:59

because as an implementation detail they are ordered up to 8 key/value pairs

coby19:06:31

ah, I'm guessing that's why I was not able to repro this with a smaller map? It was only 5 or 6 in my dev sandbox...

coby19:06:14

ok, thank you!

👍 4
coby19:06:23

@borkdude you mention returning a list of maps...is there an advantage over sending a list of lists instead?

borkdude19:06:20

@ctamayo a list of tuples you mean?

borkdude19:06:34

I think maps are easier to work with than tuples, easier to extend in the future

Alex Miller (Clojure team)19:06:21

tuples implicitly complect position. useful for conciseness (so good for human apis), but far more brittle for evolution.

Alex Miller (Clojure team)19:06:55

but that's a lot of trouble :)

borkdude19:06:25

also you want to the entire response wrapped in a map also, maybe: https://twitter.com/borkdude/status/1135841658199826432

borkdude19:06:47

like {:things [{:a 1} {:a 2}]}

borkdude19:06:54

so you can add a :things2 later

coby19:06:55

it is wrapped, this is just part of the response 🙂

coby19:06:38

the shape of the response is more like:

{
  "data": {
    "locations": {
      "439": "Alderwood Park",
      ...
    },
    "categories": { ... }
  },
  "success": true
}

coby19:06:41

so are you suggesting that locations be something like [{"id": "436", "name": "Alderwood Park"}, {"id": "440", "name": "Alling Park"}] ?