This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-19
Channels
- # 100-days-of-code (5)
- # announcements (1)
- # aws (1)
- # beginners (112)
- # cider (135)
- # cljdoc (6)
- # clojure (111)
- # clojure-dev (8)
- # clojure-italy (3)
- # clojure-nl (5)
- # clojure-sweden (3)
- # clojure-uk (152)
- # clojurescript (101)
- # datascript (14)
- # datomic (61)
- # editors (1)
- # emacs (29)
- # events (7)
- # figwheel (3)
- # figwheel-main (15)
- # fulcro (18)
- # funcool (2)
- # graphql (1)
- # juxt (2)
- # off-topic (51)
- # om (1)
- # overtone (28)
- # perun (2)
- # reagent (1)
- # reitit (6)
- # ring-swagger (5)
- # shadow-cljs (112)
- # spacemacs (49)
- # tools-deps (10)
- # unrepl (11)
- # yada (10)
Does anyone know what is the simplest way to traverse a <select multiple…> ’s options? It is not a seqable, or even a JS array - I can’t (aget .. ) on it. I would hope to avoid having to use jayq…maybe goog closure? Thanks for any suggestion..
you can always (aclone ...)
a HTMLCollection (returned by (.-options select-elem)
and then it's seqable and a JS array
array-seq
transforms ArrayLike JS structures into a sequence
assuming I have a project A that is only backend only
and a project B which can be used as a dependency of A to give some extra functionality, but uses Clojurescript
the actual JS asset is generated when B builds its jar file, I wonder does A really also need to have Clojurescript as dependency?
is there a way to avoid getting that extra dependency if it's not really actually used anyway in A?
@andrea.crotti technically no library needs a clojurescript dependency. you only need it when building.
yes ok cool @thheller but it will still be included in A jar right?
it's a transitive dependency since A depends on B
so if you include the compiled .js
file and use that you no longer need clojurescript dependency at all
yeah but B doesn't just build a single js file, it's also a backend server, and A depends on B
and yes I agree, but still leiningen would include it in A uberjar as far as I understood
with all the other transitive dependencies inherited from B
ah ok if that's how it works cool
if you just put clojurescript
into your normal :dependencies
then it will end up in your uberjar
ah ok I got it, I think in none of the projects we do it that way
so ok that's the solution
thanks
interestingly I can't find any place where this "advice" is actually documented
seems like an easy and straightforward thing to do
I tried on a couple of projects already though and uberjar
doesn't work
$ lein with-profile dev uberjar
Compiling ClojureScript...
WARNING: It appears your project does not contain a ClojureScript dependency. One will be provided for you by lein-cljsbuild, but it is strongly recommended that you add your own. You can find a list of all ClojureScript releases here:
so I guess something else is missing
the uberjar task should just copy files from the classpath into the final .jar
. you probably want to create the .js
file in a separate task.
ah ok good point
ah actually I forgot I had that already
:uberjar {:hooks []
:source-paths ["src/clj" "src/cljc"]
:prep-tasks [["compile"]
["garden" "once"]
["cljsbuild" "once" "min"]]
:omit-source true
:aot :all
:main elo.api}
maybe doesn't work simply because cljsbuild
running there doesn't pick up the right profile
ah yes this fixed it - ["cljsbuild" "once" "min"]] + ["with-profile" "dev" "cljsbuild" "once" "min"]]
even though it didn't work the jar is even bigger now 😄
ah ok I see, I think I just originally did it this way because Heroku simply runs lein uberjar
by default at least there might be a way to change the build command
# cljs_opts.edn
{:output-dir "resources/web/js/out"
:output-to "resources/web/js/announcements.js"
:optimizations :none
:asset-path "resources/web/js/out"
:verbose true
:pretty-print true
:main app.announcements
:target :nodejs
:modules
{:ws {:entries #{}
:output-to "resources/web/js/ws.js"}}}
(ns app.announcements
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :as a :refer [<! >!]]
[time.core :as t]
[async.http :as http]
[clojure.string :as str]
[cljs.reader :refer [read-string]]
["nodemailer" :as mail]
["sqlite3" :as sqlite])
(:import [goog.string format]))
(ns
(:require ["ws" :as WebSocket]
["pako" :as pako]))
# compiler command
clj -A:cljs -m cljs.main -co cljsc_opts.edn -w src/cljs -c
# throws:
java.lang.Exception: No input matching "pako"
at cljs.module_graph$canonical_name.invokeStatic(module_graph.cljc:179)
at cljs.module_graph$canonical_name.invoke(module_graph.cljc:173)
at cljs.module_graph$inputs__GT_assigned_modules$canon__4705$fn__4706.invoke(module_graph.cljc:216)
at clojure.core$map$fn__5583$fn__5584.invoke(core.clj:2734)
at clojure.core.protocols$fn__7852.invokeStatic(protocols.clj:168)
at clojure.core.protocols$fn__7852.invoke(protocols.clj:124)
at clojure.core.protocols$fn__7807$G__7802__7816.invoke(protocols.clj:19)
at clojure.core.protocols$seq_reduce.invokeStatic(protocols.clj:31)
at clojure.core.protocols$fn__7835.invokeStatic(protocols.clj:75)
at clojure.core.protocols$fn__7835.invoke(protocols.clj:75)
at clojure.core.protocols$fn__7781$G__7776__7794.invoke(protocols.clj:13)
at clojure.core$transduce.invokeStatic(core.clj:6804)
at clojure.core$into.invokeStatic(core.clj:6819)
at clojure.core$into.invoke(core.clj:6807)
at cljs.module_graph$inputs__GT_assigned_modules$canon__4705.invoke(module_graph.cljc:216)
at cljs.module_graph$inputs__GT_assigned_modules$assigns__4709$fn__4711.invoke(module_graph.cljc:225)
at clojure.core$fn__8072$fn__8074.invoke(core.clj:6760)
at clojure.core.protocols$iter_reduce.invokeStatic(protocols.clj:49)
at clojure.core.protocols$fn__7839.invokeStatic(protocols.clj:75)
at clojure.core.protocols$fn__7839.invoke(protocols.clj:75)
@dnolen this is my ns files & my compiler-options file@isaac you don't usually use :modules
for :nodejs
builds. just :main
should be enough
I'm not sure if this is a hiccup thing, and I can't find anything in its documentation, but I've seen code using syntax like:
[:> someComponent ...]
@temporal.pl its a reagent thing for native react components
with that hint, I found https://github.com/reagent-project/reagent/blob/master/doc/InteropWithReact.md
Odd question: I have a macro which can be called from ClojureScript. This macro expects a basic function as an argument, which it then calls during macro-expansion (calling must happen at expansion time, not run time). Passing a function and evaling works in Clojure. In ClojureScript, I get a Unable to resolve symbol: SYM in this context
for every SYM
that is unqualified. Is there a good technique for passing a CLJ function to a CLJ macro from CLJS?
Perhaps if you control the macro you can make it resolve to the function given some symbols
Thanks for all of the responses.
@mfikes Yes, I do control the macro's implementation.
@thheller It seems at least sort-of possible because eval will work correctly if I fully qualify relevant symbols. For example, passing the function in like (clojure.core/fn [arg] ...)
.
@polymeris It depends which symbol, see above.
well you can do it in a rather limited fashion since the CLJ side can't see anything from the CLJS side
Yeah, understood, that's what I am trying to do. Just having issues with eval of what should be purely clojure code.
question would be why you'd want to do this in the first place. seems mind bending just thinking about it?
I am compiling clojure.specs inside of a macro. It has to be in a macro because clojure.spec relies on macros (especially CLJS clojure.spec due to registering specs during macro-expansion for use by instrument
). The function passed in is a basic function that can cause the macro to alias some specs. As such, it has to be called from Clojure during macro-expansion.
Thanks @mfikes. Yeah, that will work. That's the fully-qualified and resolvable case. But what if the macro is called like (foo.core/bar (fn [x] ...))
?
Exactly, and that requires qualifying every non-local symbol. A test function I am using is:
(clojure.core/fn [kw]
#{(clojure.core/keyword
(clojure.core/namespace kw)
(clojure.core/str (clojure.core/name kw) "-alias"))})
That works but if any of the syms are unqualified it will fail. I just don't understand why evaling the following in a macro works in Clojure but not ClojureScript:
(fn [kw]
#{(keyword
(namespace kw)
(str (name kw) "-alias"))})
I'm trying to do basic json based HTTP calls in a re-frame app using the cljs-ajax library. Is there a generally recommended way I should be marshaling data into and out of json?
It seems there is a mode of the cljs-ajax library that avoids core.async. Is that worth using if I don't need it elsewhere in the app?
Does anyone know how to reference an extern? I am using jayq, but keep getting the ‘can’t find jquery.js’. I am not using optimizations - I’ve tried :compiler {:infer-externs true…}, but to no avail..What’s the simplest way to get this done? Thanks for any comment..
Thanks @isak, I got the externs file but don’t know where to drop it…should it be inside public/js/? Will read through the docs, but it seems complicated and I am trying to save time….
can someone explain to me a piece of the . dot
special form that doesn’t make sense? why are these equivalent:
(. js/document hasFocus)
(. js/document (hasFocus))
it can’t have something to do with argument grouping (i think), because you’re not currying arguments
for example:
document.foo = (x, y) => { console.log(x, y); return function(a) { console.log(a)}}
i cannot invoke
(. js/document (foo 1 2) 3)
as if it were somehow curried (it’s a “dot with extra arguments” error)
> a plain symbol is equivalent to that symbol wrapped in a list oh. is this just part of the macro’s definition?
that clarifies things a lot, thanks. i’m working on an internal blog post to help out some newbies to the interop stuff
@lwhorton It appears that the ability to optionally use parens (your example (. js/document (hasFocus))
) is useful when writing macros. (I'm curious to see this in practice.)
This is from https://www.clojure.org/reference/java_interop#dot where it has the sentence "Note that placing the method name in a list with any args is optional in the canonic form, but can be useful to gather args in macros built upon the form."