Fork me on GitHub
#clojurescript
<
2016-04-27
>
superstructor00:04:31

@ghaskins: do you have something like [org.clojure/tools.cli "0.3.3”] in your deps in project.clj or build.boot file ?

ghaskins00:04:23

@superstructor: yeah, i have the lein-dep in place, and I can see it when I do lein deps :tree

ghaskins00:04:36

I am also using cljsbuild, not sure if that is relevant

ghaskins00:04:02

is there some extra step you need to do to get cljsbuild to process the deps perhaps?

superstructor00:04:51

@ghaskins: parse-opts specifically has definitely been ported to cljs as of 0.3.0 which you can see here: https://github.com/clojure/tools.cli/blob/master/src/main/clojure/cljs/tools/cli.cljs#L301

ghaskins00:04:24

ah, ok, i was referencing clojure.tools.cli

superstructor00:04:25

@ghaskins: but the ns would be cljs.tools.cli

ghaskins00:04:32

so i need to fix the ns

superstructor00:04:43

@ghaskins: yes, if you use that ns it should work I think

ghaskins00:04:52

ok, cool, i will try that

ghaskins00:04:06

so, i assume i still need the lein-dep, and then referencing the right ns

superstructor00:04:11

@ghaskins: the general answer to your question “is each library generally required to be explicitly ported to cljs” is that “it depends”

ghaskins00:04:23

hehe, i was afraid of that

superstructor00:04:24

@ghaskins: yes you still need the lein dep

superstructor00:04:12

@ghaskins: there is .cljc (used to be .cljx) files which work for both JVM Clojure or JS CLJS with reader conditionals, which you can read about here: https://github.com/clojure/clojurescript/wiki/Using-cljc

ghaskins00:04:49

awesome, thank you so much for the help

superstructor00:04:40

@ghaskins: for some libs, it is sufficient to use .cljcimplementation and one ns. For other libs, there are two ns one clojure. and one cljs., for other libs like instaparse there are entirely different projects + clojars; e.g. https://github.com/Engelberg/instaparse vs https://github.com/lbradstreet/instaparse-cljs

ghaskins00:04:13

ah, good to know, i use instaparse in some of my jvm-clj projects

ghaskins00:04:50

thanks again, really appreciated

superstructor00:04:23

@ghaskins: your welcome. Happy to be able to help someone, usually I’m asking questions as relatively new to CLJ/CLJS as well! I think one of the best things about Clojure is the community.

ghaskins01:04:39

that did the trick, by the way (s/clojure/cljs on the ns)

Yehonathan Sharvit06:04:30

is it safe to use (js*) in production?

Yehonathan Sharvit06:04:49

is there a documentation for it somewhere?

risto07:04:22

@superstructor: wow, thanks for posting instaparse. That library looks amazin

sickill11:04:26

is it possible to use prismatic/schema in clojurescript to verify that something is a function? I'm failing at this exercise

sickill11:04:29

I have this:

sickill11:04:31

(deftest foo
   (s/validate cljs.core/IFn identity))

sickill11:04:51

and it gives:

sickill11:04:53

ERROR in (foo) (#error {:NaN:NaN)
Uncaught exception, not in assertion.
expected: nil
  actual: #error {:message "Value does not match schema: (not (instance? #object[Function \"function () {}\"] a-function))", :data {:type :schema.core/error, :schema #object[Function "function () {}"], :value #object[cljs$core$identity "function cljs$core$identity(x) {
return x;
}"], :error (not (instance? #object[Function "function () {}"] a-function))}}

sickill11:04:08

this works fine in Clojure (using clojure.lang.IFn there)

niwinz12:04:30

@sickill: is more cheap just using fn? predicate

fasiha13:04:43

It appears that I cannot use #?(…) reader conditionals in my lein user profile (at $HOME/.lein/profiles.clj) to specify when loading a cljs/figwheel REPL to inject a require for some cljs namespaces, and specify other clj-specific ones for Clojure REPLs. How do people usually do this?

nberger13:04:25

@fasiha: not sure what you are using to inject the requires, and if it's even supposed to work on cljs (is it?), but maybe you can inject the same require to some namespace for both and then use reader conditionals in that namespace to do the specific platform thing?

mfikes13:04:00

@fasiha: Not sure if it works with Figwheel, but :repl-requires is a standard REPL opt.

sickill13:04:39

martinklepsch: it didn't do the trick

sickill13:04:53

(deftest foo
   (s/validate (s/protocol cljs.core/IFn) identity))

sickill13:04:56

ERROR in (foo) (#error {:NaN:NaN)
Uncaught exception, not in assertion.
expected: nil
  actual: #error {:message "Value does not match schema: (not (satisfies? cljs.core/IFn a-function))", :data {:type :schema.core/error, :schema #schema.core.Protocol{:p #object[Function "function () {}"]}, :value #object[cljs$core$identity "function cljs$core$identity(x) {
return x;
}"], :error (not (satisfies? cljs.core/IFn a-function))}}

sickill13:04:21

so I'll probably go with fn? predicate

bojan.matic13:04:15

that’s strange that there isn’t a unified way that works the same in both clj and cljs of checking if x is a function…or am I misunderstanding something?

xcthulhu13:04:56

@bojan.matic: fn? works. There's also function? in clojure.test and cljs.test

xcthulhu13:04:25

@sickill: (schema.core/validate (schema.core/pred fn?) identity) works for me

sickill13:04:32

maybe it's schema specific thing

sickill13:04:42

yes, just tried and it works fine, thx

sickill13:04:49

I thought using protocol as a schema would be the best but apparently one needs to use s/pred in this case

sickill13:04:16

(I work on clj+cljs lib)

sickill13:04:30

having this test and schema in .cljc files

xcthulhu13:04:33

Eh, would be nice... but I find myself falling back on schema.core/pred all the time when I'm doing what you're doing.

xcthulhu14:04:24

I have this sad little bit of code in my utils:

xcthulhu14:04:31

(defn boolean?
  "Predicate identifying if an object is a boolean"
  [x]
  #?(:cljs ((js* "function(x){ return typeof(x) === \"boolean\"; }") x))
  #?(:clj (= (class x) java.lang.Boolean)))

sickill14:04:12

yeah, I have similar things

xcthulhu14:04:32

I think it's suppose to be making its way into the next Clojure(Script) release

xcthulhu14:04:48

There you go

sickill14:04:14

damn, (s/pred fn?) is not enough for me as I'm also using hash-set as a callable here and (fn? #{}) => false

sickill14:04:48

that's why I went for IFn in the first place 😐

xcthulhu14:04:18

Ahhh... try ifn?

sickill14:04:41

oh, I didn't know this one!

xcthulhu14:04:01

Me neither until I made CIDER dig through the docs to see how fn? was defined and that's right above it

sickill14:04:42

xcthulhu: (pred ifn?) did the trick, thx!

fasiha14:04:36

What's the opinion on using cljs.pprint/cl-format in production? I need to produce SVG path strings like M10 10 H 90 V 90 H 10 Z and cannot be having with (str "M " start-x " " start-y " H " …). I'm also a bit leery of (string/join " " ["M" start-x start-y "H" …]). The cl-format function will do the trick neatly but I'm wondering if it's expensive

pdlug15:04:11

Does anyone have an example of using packages from cljsjs? Specifically cljsjs-aws-sdk-js? I’ve required it but keep getting the error “AWS is not defined”, not sure what I’m doing wrong

xcthulhu15:04:47

@fasiha: You could try goog.string/format

martinklepsch15:04:18

@pdlug: cljsjs doesn’t provide any real namespaces, everything will get imported under js/

martinklepsch15:04:03

@pdlug: i.e. (:require [cljsjs.thing :as t]) isn’t really supported.

martinklepsch15:04:21

instead use js/thing.things_function

pdlug15:04:39

@martinklepsch: yes I’ve tried that (js/AWS.S3.) results in the same error

xcthulhu15:04:33

@martinklepsch: I've sort of wondered about this... is there a real reason why the deps.clj file can't have :module-type :commonjs in it when the library implements a commonjs interface?

xcthulhu15:04:50

I've never seen a single cljsjs library use this

martinklepsch15:04:43

@pdlug: do you have a require cljsjs.aws thing?

martinklepsch15:04:14

@xcthulhu: I’m not up to speed on tighter module integration stuff. generally what works with the compiler can be done in cljsjs packages as well. I guess people not using :commonjs could be caused by all references being without explicit module type specification

pdlug15:04:18

@martinklepsch: yes, (ns myproject.core (:require [cljsjs.aws-sdk-js]))

martinklepsch15:04:50

@pdlug: check if the compiled javascript actually loads the file containing your AWS object.

xcthulhu15:04:04

@martinklepsch: Yeah probably. Last time I played with it was back in August and it wasn't ready. I'll probably play with again soon and see if I can get it to work, maybe make a pull to cljsjs if I can figure it out.

martinklepsch15:04:04

sure. @xcthulhu do you know what it gets us to specify module type? will the get full converted somehow?

xcthulhu15:04:13

Umm... not every library implements commonjs. Basically those that are generated via browserify --standalone will do this: https://github.com/substack/node-browserify#usage

xcthulhu15:04:21

That includes d3 and react

pdlug15:04:03

@martinklepsch: I do see the line in the compiled JS (unoptimized): goog.addDependency("../aws-sdk-js.inc.js", ['cljsjs.aws_sdk_js'], []); in the optimized version I see it inline the definitions so that seems OK

xcthulhu15:04:27

Erm maybe not... d3 still implements commonjs however

martinklepsch15:04:17

@xcthulhu: question was more about what’s the improvement for users on a per library basis (if they are available in a supported module type).

martinklepsch15:04:54

@pdlug: if you look at the resources panel when working with`:none` you should see the file loaded as well.

martinklepsch15:04:09

Maybe you’re just referencing the wrong global object?

xcthulhu15:04:45

Ah, I think you can get more savings with :advanced compilation

pdlug15:04:56

@martinklepsch: This is running in nodejs as an AWS Lambda function so I have somewhat limited visibility

pdlug15:04:03

@martinklepsch: Not sure why I can’t get the cljsjs version to work, I was able to work around it because AWS provides the aws-sdk in their nodejs runtime, so (def aws (js/require "aws-sdk”)) and then (let [s3 (aws.S3.)] …) works

hjrnunes15:04:55

hi guys, wondering what do people do if they want to render markdown on a cljs app?

xcthulhu15:04:02

And for reagent I wrap this with [:div {:dangerouslySetInnerHTML {:__html (md->html text)}}]

abdullahibra17:04:50

is there any good library you are suggesting to create hexagon which i can edit with texts ?

risto17:04:58

what's hexagon?

risto17:04:57

do you just mean the shape?

risto17:04:03

or some sort of library or algo?

risto17:04:43

there's D3, but that might be overkill for that

risto17:04:40

but that's generally the go-to library for when you want to manipulate vector graphics (SVG) based on data

fasiha18:04:23

@abdullahibra: what do you mean "edit with texts"?

abdullahibra18:04:49

when you press the cell then you can add text inside it

abdullahibra18:04:05

and each cell should have some label

abdullahibra18:04:16

field_name: value

abdullahibra18:04:45

the same effect of forms, but in hexagon shape

abdullahibra18:04:02

and edit occurs ajaxy

abdullahibra18:04:23

if the hexagon will be complex it maybe just normal circles

abdullahibra18:04:46

i'm search the simplest solution to do this

risto18:04:02

the simplest solution is probably to not use a library

risto18:04:20

and just open up inkscape and draw a hexagon, save it, and use it in your html inline

risto18:04:06

and then add a textbox in your hexagon, save that shape, and compare the difference between the two (it should have something like a text element in the second one)

risto18:04:40

and you can use the svg foreignObject tag to add a html <textarea> element in your box when you click on it

risto18:04:54

or you could use JS canvas if you want to avoid SVG

fasiha18:04:16

@abdullahibra: but you want a grid of these shapes, each of which you can click on and edit? I'm trying to see where the need for shapes (circles, hexagons) come from.

amonks18:04:34

lining a bunch of inputs up in slightly offset rows you could do pretty easily in just flexbox css

amonks18:04:04

if you need the hexagonal lines, you’ll maybe want to use canvas

amonks18:04:07

or actually

amonks18:04:23

you could line up hexagon.jpg behind the lined up inputs

amonks18:04:29

also with css

amonks18:04:49

but canvas feels “more correct"

amonks19:04:48

@abdullahibra: 😄 not sure if that was helpful at all; lmk if you want flexbox examples!

abdullahibra20:04:06

how can i do this in clojurescript $('div').attr('contenteditable','true'); ?

borkdude20:04:58

(.attr (js/$ "div") "contentEditable" "true")

borkdude20:04:40

@abdullahibra: function/method names always come first, method names start with a dot

abdullahibra20:04:03

http://codepen.io/team/css-tricks/pen/EKEYob what i'm actual do is make cells editable with texts, when it's clicked

abdullahibra20:04:08

can you help with this?

abdullahibra20:04:53

i'm trying something like: (events/listen link "click" (fn [event] (.attr (js/$ "span") "contentEditable" "true")

abdullahibra20:04:00

but span approach won't work correctly for multiple cells, how can i get the text from link and li ?

borkdude20:04:09

via the event?

abdullahibra20:04:41

(let [link (dom/getElement "editable")] (events/listen link "click" (fn [event] (.attr (js/$ "span") "contentEditable" "true")))))

abdullahibra20:04:44

that's the code

abdullahibra20:04:17

borkdude: my final goal is get editable cells when i press them, am i on the right way?

borkdude20:04:14

@abdullahibra: I'm sorry, don't have the time right now to look into that specifically

abdullahibra20:04:48

borkdude: thank you anyway

vincentdm22:04:39

Hi guys, can anyone point me to the best practice to include env vars in my :cljsbuild profiles? For example, how do I make the URL of my API backend dependent on whether I'm using Figwheel in dev mode, as opposed to the real API in a production build?

vincentdm22:04:25

I tried passing my own goog.ENV var using :closure-defines, but it seems that only the predefined goog.X vars can be used.

vincentdm22:04:47

I'm aware that I could make everything dependent on the goog.DEV flag, but I want more granular control (similar to env vars)

jonathandale22:04:16

@vincentdm: You can make your own vars and use :closure-defines to override. I’m using it for a base-url setting in a cljs project. I followed this post: https://www.martinklepsch.org/posts/parameterizing-clojurescript-builds.html

jonathandale22:04:31

Definitely might be a better way, but worked for my use case

vincentdm22:04:23

Thanks for pointing me towards that article, I didn't know about it. I'll see how I can fit it into my workflow. Thanks!!

darwin22:04:16

@vincent: I usually prefer to stay away from :closure-defines and use macros + environ library to “export” compile-time env settings into my cljs code

darwin22:04:58

I export the value via a macro, so that it can be consumed both in clj and cljs code

darwin22:04:23

I tend to use lein-env plugin for leiningen to specify env parameters for my builds, (but it gets more tricky when one starts using multiple lein profiles in parallel: https://github.com/weavejester/environ/pull/53)

vincentdm22:04:08

didn't know I could also use environ in cljs. Will check it out. Thanks!

darwin22:04:37

no, environ is used in clj files, resulting values are exposed to cljs code as macros

vincentdm22:04:00

ok, I see. so it is used at compile time?

darwin22:04:48

sure, access to environment during runtime is not something you could do in browsers

darwin22:04:18

maybe nodejs or some other js platforms could offer some apis, but that is not general assumption

darwin22:04:57

those env vars get resolved during compilation time and then their values get baked into cljs sources

vincentdm22:04:12

By the way: thanks for making cljs-devtools. I'm using it as we speak!

darwin22:04:07

btw. if you decide to go :closure-defines route and you will want to use the env settings to elide some debug code in :advanced mode, be aware of type hints. I wrote about it here: https://github.com/binaryage/cljs-devtools/releases/tag/v0.5.3

vincentdm22:04:38

yeah, I've already bumped into the weird behavior of closure DCE. It even led to an enhancement pull request simple_smile https://github.com/google/closure-compiler/issues/1722

darwin22:04:05

yeah, DCE can be tricky sometimes, in chromex I wanted to elide some (configurable) logging code in advanced builds and I had to carefully generate my cljs config maps via a macro[1]. The issue: when you have a static config map literal in cljs and you put a function reference under some key, and although you never access that particular key in your code, closure compiler does not understand the function will be never called and assumes it is a live code. [1] https://github.com/binaryage/chromex/blob/master/src/lib/chromex/config.clj#L62