Fork me on GitHub
#clojurescript
<
2017-09-16
>
arkh00:09:45

I've used cljsjs libraries before but I've recently started to try [cljsjs/react-transition-group "2.2.0-0"] and at runtime get "Uncaught ReferenceError: cljsjs is not defined". Anyone know what would cause that?

arkh00:09:08

my ns statement includes a (:require [cljsjs.react-transition-group :as rct] ... )

arkh00:09:47

(defn line-wrapper
  [children]
  (js/React.createElement rct/CSSTransitionGroup
      #js {:transition-name "asdf"}
      (clj->js children)))

tomjkidd12:09:52

I am using leiningen to attempt to provide an edn-file as a string using :closure-defines, tried

:closure-defines {
  "gallery.core.COLOR_EDN" #= (eval (slurp ( "resources/public/gallery-color-data-test.edn")))
}
and it compiled fine, but
(require '[gallery.core]) gallery.core/COLOR_END
from the repl and I get`“”`. Any suggestions?

tomjkidd12:09:28

The goal is to have this edn config file slurped in at compile time, and available in cljs as and edn string

tomjkidd12:09:32

In gallery.core, I have a (goog-define COLOR_EDN "") as well

tomjkidd12:09:04

probably doing something silly, but just curious if anyone has any ideas

erwinrooijakkers14:09:37

@tomjkidd it is better to use clojure.edn/read-string to obtain the EDN and not call eval. E.g., (edn/read-string (slurp "resources/public/gallery-color-data-test.edn")). Then you have EDN. I don’t think you need to turn it into a string, but if you do, you can call str on the last result:

(-> "resources/public/gallery-color-data-test.edn"
    slurp
    edn/read-string
    str)

darwin14:09:55

@tomjkidd I personally prefer to ignore complexity of closure-defines and simply use macros to do any compile-time EDN preparation and then emit it into cljs code as data, e.g. https://github.com/binaryage/cljs-devtools/blob/b42ad914da02cd71d9765d32f54007cb9e2ca68f/src/lib/devtools/prefs.clj#L33

tomjkidd12:09:15

Thanks @U08E3BBST, using something along the lines of what you shared worked like a charm!

tomjkidd14:09:49

Thanks guys, I'm away from the computer right now, but I'll try it out and see if I can get it working.

richiardiandrea18:09:28

is there any situation when js->clj cannot convert a js object?

richiardiandrea18:09:57

I have a case where an js object goes in and a js object comes out

thheller19:09:29

@richiardiandrea yes there are many cases, especially in node. some objects appear as objects but are in fact something native that just looks like a object

thheller19:09:44

process.env is one of those I think

richiardiandrea19:09:16

this object comes with as part of an http request

thheller19:09:50

I’d suggest just using js interop and not worrying about it too much. or write a http->clj helper fn to do it 😉

richiardiandrea19:09:07

ok yeah because it seems js->clj in ineffective in this case

richiardiandrea19:09:42

weirdly typeof(x) returns object

noisesmith19:09:50

goog.object makes this stuff much nicer to deal with I think

thheller19:09:55

yeah converting is pretty much always ineffective. especially if you only use a few properties.

richiardiandrea19:09:39

yeah ok, good to know that's a lot folks

aleph19:09:13

(def ^{:private true} reader (transit/reader :json))
(def ^{:private true} writer (transit/writer :json))

(t/deftest test-transit
  (let [p {1.5 1}
        serialized (transit/write writer p)
        p' (transit/read reader serialized)]
    (t/is (= p p'))))


FAIL in (test-transit) (:)
expected: (= p p')
  actual: (not (= {1.5 1} {1 1}))
is this a bug in transit-cljs?

noisesmith19:09:53

wow - I Have never seen this and I use transit extensively

aleph19:09:46

it surfaced while testing some stuff with test.check

aleph20:09:20

hmm I guess it’s not… I can’t reproduce this on transit-cljs master

aleph20:09:21

wait I’m doing something wrong… it doesn’t run my test

aleph20:09:37

now I can reproduce it..

aleph20:09:15

is this expected behaviour or should I submit an issue with a PR including my test?

leontalbot20:09:44

in project.clj, how can I specify to figwheel multiple ring-handlers and associate one with a specific cljsbuild config?

:figwheel {:css-dirs ["resources/public/css"]
             :ring-handler myapp.handler/dev-handler-1}

leontalbot20:09:13

:figwheel {:css-dirs [“resources/public/css”]
             :ring-handler myapp.handler/dev-handler-2}

leontalbot20:09:58

I read we can accomplish this with profiles but I can’t find out how? https://github.com/weavejester/lein-ring/issues/47

aleph20:09:21

Apparently I’m not the only one with this issue: https://github.com/cognitect/transit-cljs/issues/31

aleph20:09:28

@mroerni fwiw I was able to reproduce your transit-cljs issue and added a test that exposes the bug.

aleph20:09:21

I can’t even locate the code in transit-cljs that handles decimals

aleph20:09:52

I have to go, taking a stab at this later

leontalbot20:09:30

Found my answer.

dfcarpenter21:09:57

So i'm new to clojurescript and i'm trying to use the animated library https://github.com/animatedjs/animated which is normally packaged with React Native but instead i'm using it in a browser setting. I have my project.clj settings in the compiler like this:

:npm-deps {:animated "0.2.0"} 
                    :install-deps true
And I can see that the node_modules dir is present as well as a package.json. Now the specific problem is how to correctly (:require) the code. Here is how one has to import it in react if using it in the browser.
import * as Animated from 'animated/lib/targets/react-dom';
What would be the equivalent for cljs?

thheller23:09:13

@dfcarpenter (:require ["animated/lib/targets/react-dom" :as animated]) should work

dfcarpenter23:09:36

@thheller Thanks, but I now get an error

java.lang.AssertionError: Assert failed: cljs.analyzer/foreign-dep? expected symbol got "animated/lib/targets/react-dom" (symbol? dep)