Fork me on GitHub
#clojurescript
<
2016-05-18
>
mfikes00:05:02

@pedroiago: deref on a var yields its value

pedroiago01:05:18

@mfikes: I am getting a "clojure.lang.Cons cannot be cast to java.util.concurrent.Future" when trying to use deref inside a macro =\

mfikes01:05:21

@pedroiago: Hmm… well, you definitely don’t want the deref to occur at macro expansion time. But I wonder… if it expands to a deref it might be OK. Is your code expanding to a deref or derefing while expanding?

sbmitchell02:05:49

anyone have a good reference for reagent component testing? I seem to be running into Warning: Something is calling a React component directly. Use a factory or JSX instead. See: attempting to render a component using a phantom runner using lein doo plugin

sbmitchell02:05:12

It looks like it happens when trying to call components that are using r/create-class forms

lewix03:05:13

how come reframe doesn't have a channel?

mikethompson04:05:30

@sbmitchell: the Reagent tests (in the reagent repo) will probably be an interesting source of information for you. Best to move further discussion onto the #C0620C0C8 channel.

dsouth08:05:02

How would I pass a clojurescript function reference to JavaScript? I just thought if I defn it and passed in the name, then that would suffice?

dsouth08:05:37

Wow, order is important. I needed a forward declaration on my function name, but the function name was passed in before the function was declared. Makes sense now that I’ve ‘said it out loud’...

vikeri11:05:33

I know clojurians traditionally have not been overly concerned with security 😉 but is anyone using a good RSA library that they can recommend? Both for enc/dec and key generation. Couldn’t find it in goog.crypt

bojan.matic12:05:41

lol couldn’t find in goog.crypt…did you bring a shovel?

plexus12:05:18

I'm asking because use of js* is discouraged, but it seems they have a valid use case here. Would there be a way to do the same things without js*?

jannis13:05:33

Is it possible that transit-cljs is lacking support for decimals at this point? It converts floats to integers at the moment:

cljs.user=> (transit/write (transit/writer :json) {123.123 :foo})
"[\"^ \",\"~i123.123\",\"~:foo\"]"

jimmy13:05:30

@jannis: I just test it only happens if you use decimal as a key in map, it works fine in value. But it's a good observation and it should be a bug .

jannis13:05:47

Yep, you're right. I'll look into a fix (or perhaps a workaround for me plus a bug report).

dnolen13:05:20

@jannis yes file a GH issue

jannis13:05:32

@dnolen: Cool, will do

dnolen13:05:34

probably simple to fix, and can cut a release today for that

jannis13:05:39

Nice, thanks 🙂

miguelb16:05:02

hi everyone, does clojurescript have anything like import mockJson from “./fixtures/mockJson”? I’m trying to load some local json data into my cljs file but running into circles

roberto16:05:46

assign your mockJson to a var

roberto16:05:51

maybe you can have a my-project/fixtures/mockJson like this:

(ns my-project.fixtures.mock-json)

(def sample-json “some sample json goes here”)

and you can use it in your code like this:
(require [my-project.fixtures.mock-json :refer [sample-json]])

;; use sample-json anywhere now

miguelb16:05:16

so loading it from a file is not a good idea?

roberto16:05:31

I don’t know, but that is the approach I would take

roberto16:05:20

I generally don’t read files with cljs, never had the need. Mostly do that with clojure.

miguelb16:05:54

I was trying to load json via via a clj file and then requiring the file as normal just like the how :require-macros works but cljsbuild doesn’t like that

miguelb16:05:37

ok, thanks @roberto i’ll try that suggestion

jonathandale19:05:42

Anyone have experience using Hipo cljs templating library? I’m trying to get an element with inline styles, but they’re not getting added. So I would expect this: (hipo/create [:div {:style {:background-color "white"}}])) To produce <div style=“background-color:white;”></div>, but instead produces <div></div>

rauh19:05:31

@jonathandale: You need the attribute handlers. Its in the main readme

jonathandale19:05:41

@rauh, I’ll explore, was hoping it’d be more inline with hiccup/reagent. But thanks.

miguelb19:05:33

after starting a fresh figwheel template, lein new figwheel hello-world, getting into a cljs repl, and entering a protocol, `cljs.user=> (defprotocol SpecialNumber #_=> (plus [this other]) #_=> (canonical [this]))` I get clojure.lang.ExceptionInfo: Can't change/establish root binding of: *unchecked-if* am I missing something?

fabrao20:05:04

Hello all, I´m trying to generate a jar file from lein uberjar. I have some .js files in resources/public/js like jquery and other stuffs. I see the uberjar include the compiled app.js like file into the generated jar. What is the uberjar configuration to I include all the resources/public/js/* files into the jar file?

dnolen20:05:58

@fabrao: I think just happens if you specify :resource-paths

benzap20:05:18

@fabrao, make sure you include a hook to cljsbuild within your project.clj --> :hooks [leiningen.cljsbuild]

benzap20:05:16

also, include ':jar true' within the given cljsbuild

benzap20:05:38

I'm speaking with respect to a deployment, which i'm thinking is similar to an uberjar

jeluard21:05:24

@jonathandale: hipo follows hiccup syntax so this specific hook is not configured by default. I agree it would make more sense to align with other ClojureScript libraries.

dsouth21:05:41

Not really a ClojureScript question, but I was wondering if someone could point me to a resource that would help me ‘decode’ what JavaScript object I have in ClojureScript. At the moment, when I get my reference and log it I get #object[Object [object Object]], but I’m not really sure how I can get the data out of that object… 😕

roberto21:05:32

(clj->js my-obj) ??

risto21:05:55

@dsouth: You can use clj->js and js->clj

dsouth21:05:00

type gives me the JS code, but I’m lacking JS knowledge 😉

dsouth21:05:15

right, I’ll try that and see if it helps, thanks!

roberto21:05:57

you can also use this (enable-console-print!)

dsouth21:05:17

thanks, yeah I’ve got that at the moment :thumbsup:

roberto21:05:29

then whenever you call prn on a cljs map/vector, etc, it will print it as js obj in the console

dsouth21:05:06

right, that’s my problem, I don’t have the JS knowledge to figure what it’s telling me 😉

dsouth21:05:51

I just need the spec to see how JS is stringified for the toString so I can then map that back to some understanding so that I can play with my data.

dsouth21:05:18

Like I said, not really a ClojureScript question

lewix21:05:07

(.stringify js/JSON (clj->js object) ) ?

dsouth21:05:46

nope, but thanks for the help

risto21:05:58

I think your object is a JS object, correct?

risto21:05:00

try something like:

risto21:05:24

(println (js/JSON.parse myobject nil 2))

dsouth21:05:33

I get errors on both those suggestions 😕

dsouth21:05:48

anyway, I gotta run, but thanks again!

dsouth21:05:29

OK, tried one more quick thing. When I log the object in JS I get [object Object], so how in ClojureScript do I unwrap or get to the object data in #object[Object [object Object]]

dsouth21:05:07

or is the #object[Object [object Object]] ClojureScript toString and not JS toString which probably is the case and I’m just totally confused? 😉

dnolen21:05:51

@dsouth: or just console.log that value

dnolen21:05:06

if it’s a JS thing, JS tooling will be more useful anyway

dnolen21:05:26

wrt. inspection

dsouth21:05:57

yeah, I’m using Chrome, which is helping a bit

risto21:05:14

@dnolen: Are there any plans to get rid of clj->js/`js->clj` and just have complete parity with JS types?

dsouth21:05:32

Probably just some I’m missing that I don’t know yet. 😕

dnolen21:05:36

it’s extensible for a reason, users can make it do what they want

dnolen21:05:30

it also exists primarily as a convenience, so many perf bug reports that boil down to incorrectly using clj->js etc. on larger amounts of data

risto21:05:21

@dnolen What's the advantage of keeping them separate?

dnolen21:05:53

@risto I don’t know what you are asking

dnolen21:05:06

sorry I missed the part about “parity with JS types” what does that mean?

risto21:05:38

Sorry, I guess that wasn't clear. I meant just to have all of the ClojureScript types be JavaScript types, so that they don't need the conversion

risto21:05:57

Or at least the vector == array, string == string, map == map, etc

dsouth22:05:20

And I’ve just realised that I’m dealing with a JS type. I’m so slow… 😉

risto22:05:05

@dsouth: Yeah, @lewix answer w/o the clj->js part should work

dnolen22:05:28

@risto JS arrays & maps are mutable - I doubt Clojure programmers will want that

risto22:05:55

Yeah, but I guess make them immutable by doing a deep Object.freeze

dnolen22:05:44

@risto Object.freeze is currently very ineffecient

dnolen22:05:04

even if it wasn’t it does not support immutable updating rendering it useless to most Clojure programmers

dsouth22:05:04

Converting circular structure to JSON ouch 😞

risto22:05:12

@dnolen: I thought I saw some technique for Redux that "updates" the data structures that are frozen by creating a new one. I forgot how it worked though.

risto22:05:36

I saw some benchmarks where v8 seemed to process frozen objects faster

dnolen22:05:48

@risto we don’t care about V8 specifically

dnolen22:05:07

and Redux isn’t trying to solve the generic data structure problem

dnolen22:05:34

there’s a lot of interesting stuff beyond UI stuff

risto22:05:56

You mean for the backend?

risto22:05:35

I don't know... I feel like in theory it should be easier to optimize for immutable objects over mutable ones. Which makes me think that if frozen objects are slower, then it's just because the engine hasn't optimized for them yet.

risto22:05:43

And NodeJS is v8

risto22:05:03

I might be wrong though

risto22:05:13

My knowledge is fairly superficial on a lot of this stuff

dnolen22:05:36

@risto I mean Object.freeze is just unacceptable for many algorithms

dnolen22:05:07

ClojureScript data structures are some of the fastest immutable implementations out there

dnolen22:05:40

and they are fast on all the major JS engines

risto22:05:14

I guess it does has an intrinsic performance hit just by running it... I can see that

risto22:05:01

I saw this talk between Rich Hickey and Brian Beckman about Clojure: https://www.youtube.com/watch?v=wASCH_gPnDw

risto22:05:46

Rich was talking about some kind of tree data structure (forgot it's name) that keeps track of the immutable data structure's changes which still keeps things efficient for lookup. Does ClojureScript also use that under the hood?

thachmai22:05:55

I wonder the same thing... though I'm curious how to pull it off in javascript

danielcompton22:05:04

Does anyone know of a pluggable EDN editor you can use to write/complete EDN data?

dnolen22:05:33

@risto yes we implement the same immutable trie data structures as Clojure

dnolen22:05:49

@thachmai: Immutable.js copies the approach taken in Clojure

fabrao23:05:51

@dnolen: and @benzap I changed the *.js files to folder vendor and include :resource-paths ["resources/public/vendor"] to :cljsbuild and the ended jar came with all the files, thanks a lot !!!

thachmai23:05:59

@dnolen: do you have an example of the implementation? How does cljs implement a map for example?

dnolen23:05:23

@thachmai: read the Clojure or ClojureScript source if you’re interested in the gory details

dnolen23:05:42

PersistentHashMap is the type, the implementation is quite sophisticated, not light reading

thachmai23:05:44

thanks a lot. The detail does look gory (10k file!) but I'll definitely try to go through it.