This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-27
Channels
- # aleph (1)
- # aws (2)
- # beginners (69)
- # boot (79)
- # braid-chat (1)
- # cider (221)
- # clara (13)
- # cljs-dev (9)
- # cljs-edn (1)
- # cljsrn (7)
- # clojure (128)
- # clojure-chicago (1)
- # clojure-russia (196)
- # clojure-sanfrancisco (1)
- # clojure-uk (13)
- # clojurescript (166)
- # community-development (2)
- # css (2)
- # cursive (8)
- # datomic (4)
- # emacs (11)
- # hoplon (54)
- # instaparse (2)
- # jobs (16)
- # jobs-discuss (54)
- # jobs-rus (7)
- # luminus (4)
- # off-topic (33)
- # om (37)
- # onyx (8)
- # proton (10)
- # quil (8)
- # re-frame (29)
- # reagent (7)
- # remote-jobs (2)
- # untangled (140)
- # yada (1)
@ghaskins: do you have something like [org.clojure/tools.cli "0.3.3”]
in your deps in project.clj
or build.boot
file ?
@superstructor: yeah, i have the lein-dep in place, and I can see it when I do lein deps :tree
is there some extra step you need to do to get cljsbuild to process the deps perhaps?
@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
@ghaskins: but the ns would be cljs.tools.cli
@ghaskins: yes, if you use that ns it should work I think
@ghaskins: the general answer to your question “is each library generally required to be explicitly ported to cljs” is that “it depends”
@ghaskins: yes you still need the lein dep
@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
@ghaskins: for some libs, it is sufficient to use .cljc
implementation 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
@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.
is it safe to use (js*)
in production?
is there a documentation for it somewhere?
@superstructor: wow, thanks for posting instaparse. That library looks amazin
is it possible to use prismatic/schema in clojurescript to verify that something is a function? I'm failing at this exercise
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))}}
@sickill: have you tried? http://plumatic.github.io/schema/schema.core.html#var-protocol
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?
@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?
@fasiha: Not sure if it works with Figwheel, but :repl-requires
is a standard REPL opt.
exposition: http://blog.fikesfarm.com/posts/2015-12-02-clojurescript-repl-auto-require.html
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))}}
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?
@fasiha: Looks like it was undocumented. Fixed: https://github.com/clojure/clojurescript/wiki/REPL-Options#repl-requires
@bojan.matic: fn?
works. There's also function?
in clojure.test
and cljs.test
I thought using protocol as a schema would be the best but apparently one needs to use s/pred in this case
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.
(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)))
damn, (s/pred fn?) is not enough for me as I'm also using hash-set as a callable here and (fn? #{}) => false
Me neither until I made CIDER dig through the docs to see how fn?
was defined and that's right above it
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
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
@pdlug: cljsjs doesn’t provide any real namespaces, everything will get imported under js/
@pdlug: i.e. (:require [cljsjs.thing :as t])
isn’t really supported.
instead use js/thing.things_function
@martinklepsch: yes I’ve tried that (js/AWS.S3.)
results in the same error
@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?
@pdlug: do you have a require cljsjs.aws thing?
@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
@martinklepsch: yes, (ns myproject.core (:require [cljsjs.aws-sdk-js]))
@pdlug: check if the compiled javascript actually loads the file containing your AWS object.
@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.
sure. @xcthulhu do you know what it gets us to specify module type? will the get full converted somehow?
Umm... not every library implements commonjs. Basically those that are generated via browserify --standalone
will do this: https://github.com/substack/node-browserify#usage
@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
@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).
@pdlug: if you look at the resources panel when working with`:none` you should see the file loaded as well.
Maybe you’re just referencing the wrong global object?
@martinklepsch: This is running in nodejs as an AWS Lambda function so I have somewhat limited visibility
@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
I use Markdown-CLJ: https://github.com/yogthos/markdown-clj
And for reagent I wrap this with [:div {:dangerouslySetInnerHTML {:__html (md->html text)}}]
Bruce Hauman apparently wraps Showdow.js : https://github.com/bhauman/devcards/blob/master/src/devcards/util/markdown.cljs#L27
@hjrnunes: I've been fixing to use this: https://github.com/reagent-project/reagent-cookbook/tree/master/recipes/markdown-editor
hey guys
is there any good library you are suggesting to create hexagon which i can edit with texts ?
honey grid
shape
but that's generally the go-to library for when you want to manipulate vector graphics (SVG) based on data
@abdullahibra: what do you mean "edit with texts"?
when you press the cell then you can add text inside it
and each cell should have some label
field_name: value
the same effect of forms, but in hexagon shape
and edit occurs ajaxy
if the hexagon will be complex it maybe just normal circles
squares
any shape
i'm search the simplest solution to do this
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)
and you can use the svg foreignObject tag to add a html <textarea> element in your box when you click on it
@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.
lining a bunch of inputs up in slightly offset rows you could do pretty easily in just flexbox css
@amonks: thanks man
@abdullahibra: 😄 not sure if that was helpful at all; lmk if you want flexbox examples!
how can i do this in clojurescript $('div').attr('contenteditable','true'); ?
thanks
@abdullahibra: function/method names always come first, method names start with a dot
http://codepen.io/team/css-tricks/pen/EKEYob what i'm actual do is make cells editable with texts, when it's clicked
can you help with this?
i'm trying something like: (events/listen link "click" (fn [event] (.attr (js/$ "span") "contentEditable" "true")
but span approach won't work correctly for multiple cells, how can i get the text from link and li ?
(let [link (dom/getElement "editable")] (events/listen link "click" (fn [event] (.attr (js/$ "span") "contentEditable" "true")))))
that's the code
borkdude: my final goal is get editable cells when i press them, am i on the right way?
@abdullahibra: I'm sorry, don't have the time right now to look into that specifically
borkdude: thank you anyway
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?
I tried passing my own goog.ENV var using :closure-defines, but it seems that only the predefined goog.X vars can be used.
I'm aware that I could make everything dependent on the goog.DEV flag, but I want more granular control (similar to env vars)
@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
Definitely might be a better way, but worked for my use case
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!!
@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
something like this: https://github.com/binaryage/dirac/blob/master/src/settings/dirac/settings.clj#L28
here is probably a better example: https://github.com/binaryage/dirac/blob/master/src/runtime/dirac/runtime/prefs.clj
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)
maybe nodejs or some other js platforms could offer some apis, but that is not general assumption
those env vars get resolved during compilation time and then their values get baked into cljs sources
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
yeah, I've already bumped into the weird behavior of closure DCE. It even led to an enhancement pull request https://github.com/google/closure-compiler/issues/1722
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