Fork me on GitHub
#clojurescript
<
2016-06-30
>
rohit07:06:15

@venantius: i think you can specify :es6 as an option for :module-type for a foreign-lib. I haven’t personally used it. So can’t vouch for it. https://github.com/clojure/clojurescript/wiki/Compiler-Options#foreign-libs

martinklepsch08:06:58

Anyone aware of a library that let's you describe a set of derived atoms based on one atom (ideally allowing dependencies between the derived atoms)?

metametadata08:06:50

the similar stuff off the top of my head: Javelin, freactive.core, reagent (reactions/ratoms) and maybe frozenlock/entanglement

metametadata08:06:47

and also funcool/lentes

martinklepsch08:06:54

@metametadata: these are all fine to get a new atom based on one or more other atoms but I want to construct many of these derived atoms based on some description. Maybe combining derived-atom + component will allow me to achieve that

crankyadmin08:06:40

Hi, whats the best way to go from a JSON object to a native Clojurescript Hashmap?

crankyadmin09:06:15

(GET "/accounts/user-stats"
     {:handler #(do (println "results: " (js->clj  % :keywordize-keys true) )
                    (reset! user-stats (js->clj % true)))
      :format :json
      :response-format :json})

crankyadmin09:06:20

{"username":"crankyadmin"} <--- that the server returns.

crankyadmin09:06:33

js->clj appears to returning a vector.

crankyadmin09:06:55

I'd really like it to look like {:username "crankyadmin"}

martinklepsch09:06:13

If a reference to an atom is "lost" i.e. it can be GC'ed does this also remove watches?

kevin4209:06:11

any recommendation for a game engine for game like mario in clojurescript? So far I found https://github.com/alexkehayias/chocolatier which looks promising

crankyadmin09:06:44

I equally don't understand why its trying to turn {"username":"crankyadmin"} into a array...

metametadata09:06:18

@martinklepsch yeah, atom should be gc'ed with all its fields. I guess I even tested it some time ago with devtools in browser 🙂

martinklepsch10:06:27

In CLJS apps we often have derived atoms/reactions/`track` etc. Most of the times we just def. these things but I thought maybe it's nice to represent this as a dependency graph which allows construction of these interrelated references without globals, came up with this: https://gist.github.com/martinklepsch/c5a2feacc63ce08565fcffe37951ab64 — any feedback/thoughts welcome! /cc @metametadata

vandr0iy10:06:53

Hi! Has anyone ever encountered this error:

user-error: `cider-load-buffer' needs a ClojureScript REPL.
If you don't know what that means, you probably need to jack-in (`C-c M-J').
It appears when I regularly open a .cljs file and try to compile it with C-c C-k.

metametadata10:06:37

@martinklepsch: looks neat! do you plan using this in Reagent apps somehow?

vandr0iy10:06:00

Also, every clojurescript file ever starts in clojure major mode, instead of the clojurescript one. Do somebody know why?

martinklepsch10:06:28

@metametadata: Considering it for a Rum app for now but could be used in Reagent as well. Drawback to something like re-frame's subscribe is that the deriving is always done no matter if a component actually uses the derived data

metametadata10:06:23

Yeah, good point. I also think reagent component won't be able subscribe to a plain atom, it needs ratoms/reactions.

martinklepsch10:06:39

@metametadata: right but that's a matter of swapping rum/derived-atom with reaction or track

Andy13:06:49

Hi, I could not find explanation in clojurescript wiki for above, so was wondering if somebody from this # could help me.

rorydouglas14:06:17

for Google Closure libraries does :import only work for things that have been provide()-ed?

rorydouglas14:06:02

i’m working with goog.ui.KeyboardShortcutHandler, it provides goog.ui.KeyboardShortcutHandler.EventType enum & I can :import that, but it also has goog.ui.KeyboardShortcutHandler.Modifiers that it doesn’t provide (but example JS code clearly accesses)

rorydouglas14:06:20

attempting to :import goog.ui.KeyboardShortcutHandler.Modifiers results in an error

rohit14:06:38

I am able to do:

(ns example.core
  (:import [goog.ui KeyboardShortcutHandler]))

(println KeyboardShortcutHandler.Modifiers)

rohit14:06:36

@rorydouglas: what you say does seem true though.

rorydouglas14:06:35

yeah it seems i can access them, just can’t access them the same way i do from imported Enums (e.g.. can’t do Modifiers.CTRL)

rohit14:06:58

@rorydouglas: seems that way. you could raise an issue with closure-library. imho, it should have been provided here as you observed: https://github.com/google/closure-library/blob/master/closure/goog/ui/keyboardshortcuthandler.js#L22

rorydouglas14:06:19

will do - thanks!

rohit14:06:39

neat. 👍:skin-tone-3:

kino17:06:41

Hello All 🙂 Would someone be able to help guide me through the following function? I've been using ClojureScript for a few days now, but can't seem to get my head around the bit-or method being used?

(defn get-uuid []
  (apply
   str
   (map
    (fn [x]
      (if (= x \0)
        (.toString (bit-or (* 2 (.random js/Math)) 2))
        x))
    "00000000-0000-4000-0000-000000000000")))
I understand that x is being used to generate a .random int that is being multiplied by 2 using the js/Math library. It is then converted to a string. I also understand that the map may be applying the randomly generated ints to the string 00000000-0000-4000-0000-000000000000… However, are there any simpler alternatives to doing something similar without the bit-or? I assume the bit-or are key here. Sorry for the newbie question.

pat18:06:41

It is unclear what you are asking..how the code works or how to get a uuid? You are mapping the inner fn over the "0000..." and swapping out the zero characters with your bit-or result.

pat18:06:06

Your x arg is only used as a character check, is not involved in random int generation

bhauman20:06:51

@ojd look up bitwise-or somewhere, hints you have an random number and you are trying to pull a hexadecimal value (0-F) out of that random number

bhauman20:06:02

@kino: so (rand-nth ["0" ... "f"]) would work

bhauman20:06:37

you would need to fill in the dots

manutter5120:06:34

Yeah, not sure what’s going on with that code, the (.toString (bit-or (* 2 (.random js/Math)) 2)) seems to be generating random 2’s and 3’s only.

bhauman20:06:33

oh shoot I didn't even look at it 😞

wildermuthn20:06:20

Can goog-define be used with advanced compilation? Docs say not so with whitespace, but don’t mention advanced

peterschwarz20:06:08

@manutter51: Most likely, JS bit-wise or operator is coercing the arguments to unsigned integers, basically looking like:

(2 * Math.random()) >>> 0
which bounces around between 1 and 0. If you or that with 2, you'll just get your 2 and 3 result

peterschwarz20:06:06

Or at least, it's converting it to a signed int: see here: http://www.ecma-international.org/ecma-262/5.1/#sec-11.10

bhauman21:06:15

yeah it seems like the code isn't working as intended at all

kino21:06:44

@bhauman @manutter51 @wildermuthn thanks guys. I was unsure when I saw it as well. Will try researching @peterschwarz alternative as well.

bhauman21:06:28

this seems to work (Math.floor(Math.random() * 16) | 0x1).toString(16)

kino21:06:48

@pat thank you Pat. Yes, I was just trying to figure what the code was trying to do and any alternatives that make sense.

kino21:06:04

@bhauman: awesome. Will give this a go. 😊👌

bhauman21:06:42

or Math.floor(Math.random() * 16).toString(16)

bhauman21:06:04

but I would check the distribution

bhauman21:06:37

I just got caught up in the implementaion and forgot to mention that

blance21:06:16

there are no lint for clojurescript?

henry22:06:44

Anyone have an example repo where you use your custom javascript in your cljs app? Like.. https://github.com/clojure/clojurescript/wiki/Dependencies#user-content-google-closure-compiler-compatible-code I’m using reagent / figwheel and following those directions. Created a build.clj as suggested, compiled my app, but nothing happens, output isn’t generated.

pat23:06:39

@henry is your build configured to load the js? Either :libs or :foreign-libs

henry23:06:37

Yeah I tried both build.clj and project.clj, Do you know which one it should be?

pat23:06:38

You can get your build config to the compiler both ways. A build script is more manual

pat23:06:08

Try a '$lein new figwheel yourapp'

pat23:06:35

Configure your javascript. If it works, you know its a problem in your build script

henry23:06:55

The app works, but once I add this into my project.clj, it doesn’t

:compiler     {:main                 reagent-closure-compatible-js.core
                    :libs [{:file "yayquery.js" :provides ["yq"]}]}
                    :output-to            "resources/public/js/compiled/app.js"
                    :output-dir           "resources/public/js/compiled/out"
                    :asset-path           "js/compiled/out"
                    :source-map-timestamp true}}

henry23:06:42

I’m just trying to replicate the clojurescript wiki with yayquery

pat23:06:23

Yeah you gotta have your external js keyed into your build configs

pat23:06:35

:libs if closure compatible

henry23:06:29

in the project.clj? under :compiler?

henry23:06:02

Hmm now it throws an exception when I run lein figwheel dev. I added this to project.clj https://github.com/hzhu/reagent-closure-compatible-js/blob/master/project.clj#L29

henry23:06:11

Exception is pretty unintelligible

clojure.lang.ExceptionInfo: Error in component :figwheel-system in system com.stuartsierra.component.SystemMap calling #'com.stuartsierra.component/start {:reason :com.stuartsierra.component/component-function-threw-exception, :function #'com.stuartsierra.component/start, :system-key :figwheel-system, :component #figwheel_sidecar.system.FigwheelSystem{:system #object[clojure.lang.Atom 0x2835de0c {:status :ready, :val #<SystemMap>}]}, :system #<SystemMap>}

pat23:06:34

I am afk atm but try given the full path in your :libs, add :verbose true & build without fw, see what happe s

pat23:06:01

$lein cljsbuild once dev

henry23:06:02

:thumbsup: thanks I’ll give that a shot