Fork me on GitHub
#clojurescript
<
2016-07-27
>
twashing07:07:18

With cljs and core.async if I have (go (<! my-ch)) , can I consume the value from that channel outside of a go block?

twashing07:07:32

I want to avoid passing around channels to code that doesn’t care about it.

darwin09:07:44

@twashing: no, it is not possible, you can covert go channels back to callbacks/promises/etc. and pass around those, if more suitable

dimovich09:07:06

how can I translate this to cljs: var draw = SVG('drawing').size(300, 300)

darwin09:07:24

(let [draw (.size (js/SVG. “drawing”) 300 300)] …)

darwin11:07:42

@dimovich: ah, should be (let [draw (.size (js/SVG "drawing") 300 300)] …)

twashing14:07:45

@darwin Sweet. Thanks man 👍

si1416:07:28

how do you usually splice items into hiccup/reagent vectors? E.g.

[:ul [:li "foo"] (if smth? [:li "bar"] MAGIC_NEEDED_HERE: [[:li "baz] [:li "baq"]] )]

si1416:07:46

this particular example won't work because vectors have a special meaning; I can create a seq, but suddenly keys and doall will be needed, so it's less than ideal

martinklepsch16:07:11

@si14: (into [:ul [:li "foo"]] (if smth? [[:li "bar"]] [[:li "baz] [:li "baq"]] )])

jiangts18:07:47

any examples on cljs.clojure/js-transforms? I just found it for the :preprocess option on the cljs compiler for :foreign-libs it seems new.

tel18:07:16

Is there a good way to write a macro which can be used in both clj and cljs?

tel18:07:41

In particular, I’ve got this one

tel18:07:45

(defmacro spec-cmds
  "Convenient shorthand for descibing specs of the form of an s/or
  combination of tuples, each beginning with a unique first keyword and then
  followed by a variable number of arguments. (spec-cmds [cmd1 arg11 arg12]
  [cmd2 arg21]) matches tuples of the form [cmd1 arg11 arg12] or [cmd2 arg21]."
  [& cmds]
  (let [or-spec (mapcat
                  (fn [[cmd-name & arg-specs]]
                    (assert (keyword? cmd-name)
                            (str "spec-cmds expected a keyword cmd name, saw " cmd-name))
                    [cmd-name `(cljs.spec/tuple #{~cmd-name} ~@arg-specs)])
                  cmds)]
    `(cljs.spec/or ~@or-spec)))

tel18:07:53

in a cljc file

tel18:07:59

but I need to specify cljs.spec

jiangts18:07:25

no expert at all, but i believe reader conditionals solve the problem

tel18:07:46

If I try to write it for clojure, and do something like #?(:clj (:require [clojure.spec :as s]) :cljs (:require [cljs.spec :as s])) then it’ll include the wrong symbol in cljs

tel18:07:07

since the macro is interpreted at runtime as :clj

tel18:07:19

jiangts: I’m using reader conditionals, but still facing this problem

jiangts18:07:46

can you use a reader conditional at the calling site(s) instead?

tel18:07:21

I’d like to write the macro just once

tel18:07:32

Right now I write a macro with that same name in two files

tel18:07:38

and import one or the other using reader conditionals

tel18:07:12

which is about the same as using a conditional at call site, but perhaps a little less burdensome

tel18:07:17

though it’s still very subpar

tel18:07:23

unless I’m misunderstanding what you’re proposing

jiangts18:07:42

I was thinking something more along the lines of

jiangts18:07:11

#?(:clj `(clojure.spec/or ~@or-spec) :cljs `(cljs.spec/or ~@or-spec))

ghaskins18:07:39

hey all, this is perhaps a stupid question, but what is the standard way to package cljs code as a library such that multiple projects can use it as a lein coordinate?

ghaskins18:07:58

i know how to do this for normal clojure (e.g. clojars) but not as clear for cljs

ghaskins18:07:36

i dont necessarily even need it to be a distinct coordinate, just need two different projects in the same git tree to share a little code

ghaskins18:07:05

fwiw, i am using lein/cljsbuild…I suppose I could just adjust the cljsbuild->builds->source-paths

ghaskins18:07:13

but not sure if that is idiomatic

madstap18:07:47

@tel: Here's an example https://github.com/tonsky/rum/blob/gh-pages/src/rum/core.clj#L85 . It seems you can use the &env special param like (boolean (:ns &env)) which will be true for cljs and false for clj

martinklepsch18:07:27

@ghaskins: very much the same as for clojure

martinklepsch18:07:48

@ghaskins: you put a bunch of cljs files in a jar, put the jar on clojars, done 🙂

ghaskins18:07:21

@martinklepsch: ah, so simple, should have thought of that

ghaskins18:07:23

heh, thank you

tel19:07:26

madstap: that’s excellent! thanks

tel19:07:52

mfikes: yeah! I should have mentioned I saw that

tel19:07:06

I read the post, got excited, and went and tried that method

tel19:07:28

only to later re-read and notice it was still "coming to a ClojureScript compiler near you"

tel19:07:45

but env will work for now at least

tel19:07:04

super exciting though