Fork me on GitHub
#clojurescript
<
2016-03-31
>
zcaudate08:03:15

Iā€™m wondering if anyone can help me with this:

zcaudate08:03:57

(ns one.query-test
  (:require  [cljs.analyzer.api :as analyze]
             [cljs.compiler.api :as compiler]))

(def one (assoc-in (analyse/empty-env) [:ns :name] 'one))

(let [ast (analyze/analyze one '(defn plus [a b] (+ a b)))]
  (compiler/emit ast))
=> "one.plus = (function one$plus(a,b){\nreturn (a + b);\n});\n"

(let [ast (analyze/analyze one '(fn [a b] (+ a b)))]
  (compiler/emit ast))
=> "ā€

zcaudate08:03:42

the defn form compiles to the right definition

zcaudate08:03:57

but the fn form compiles to an empty string

zcaudate08:03:15

I was hoping to get (function (a,b){\nreturn (a + b);\n})

slotkenov09:03:37

Iā€™m a bit lost; how to go from a js array containing objects, to a clj vector with maps?

slotkenov09:03:59

I want to map over each object changing some keys, but canā€™t seem to just map over the js array

johannesgu09:03:38

Perhaps something like this? (mapv #(js->clj %) (js->clj jsArray))

slotkenov09:03:15

@johannesgu: seems to work nice, still running in some other problems though

martinklepsch10:03:07

without optimizations the compiled js looks as it should

martinklepsch11:03:48

Ignore everything I said, externs were not in place... šŸ˜…

pbostrom14:03:33

I'm working with a JS lib (`aws-sdk`) where every api takes a 2-arg (err, data) callback. Anyone have have good advice for unraveling this flow? I'm thinking something like this is the way to go: http://bryangilbert.com/code/2013/07/19/escaping-callback-hell-with-core-async/ but wondering if anyone has any other ideas

dialelo14:03:37

note that channels don't have error semantics, if you want an error-aware asynchronous abstraction i'd recommend promises

dialelo14:03:47

they are available in Google Closure library

dialelo14:03:10

or you can use https://github.com/funcool/promesa for nice syntactic abstractions and a richer API

pbostrom14:03:01

yeah if I go the channel route I was thinking I need an additional error channel

pbostrom14:03:08

promises look promising though

jiyinyiyong14:03:24

How is core.typed for ClojureScript now, is it suggested to use?

bbss14:03:01

Or go for a stream abstraction, I like those better than promises

dialelo14:03:27

@jiyinyiyong: not sure but i don't know anybody who uses it, neither in Clojure nor ClojureScript

dialelo14:03:17

@bbss: streams also have first-class error semantics but are overkill for just one result in my opinion

bbss14:03:20

Oh yeah for sure, but aws made me think of a network connection

bbss14:03:51

which can of course have one result

dialelo14:03:06

@jiyinyiyong: i'd ask in #C051QCQUF, hopefully someone can give you better info on ClojureScript support

dialelo14:03:52

note that you can use Google Closure Compiler's type annotations, see https://github.com/clojure/clojurescript/wiki/Compile-Time-Type-Checking

darwin14:03:21

@pbostrom: ad additional error channel, another possible technique to signal errors is to install global error handler and then just simply throw errors from within your go blocks. this is not as clean as rigorously supporting error channels, but can be more practical if you have full control over top application context

richiardiandrea14:03:19

Channels can contain any error semantic (and mapped over to obtain a Monad like behavior), I would just pass back a map with :result and :error if I understood the problem correctly

escherize16:03:11

I found a weird easter egg with cljsfiddle you might enjoy: http://cljsfiddle.com/#gist=f3dc62fc941aee78dba5020dc5dcbdcb