This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-06
Channels
- # aws-lambda (8)
- # beginners (49)
- # boot (13)
- # braveandtrue (2)
- # cider (12)
- # cljs-dev (15)
- # cljsrn (2)
- # clojure (143)
- # clojure-italy (8)
- # clojure-nl (17)
- # clojure-spec (22)
- # clojure-uk (21)
- # clojurescript (145)
- # code-reviews (1)
- # cursive (33)
- # data-science (14)
- # datomic (25)
- # emacs (3)
- # events (1)
- # fulcro (48)
- # graphql (1)
- # onyx (15)
- # perun (5)
- # play-clj (2)
- # protorepl (1)
- # re-frame (27)
- # remote-jobs (3)
- # ring (3)
- # rum (7)
- # shadow-cljs (87)
- # specter (4)
- # test-check (14)
- # testing (2)
- # tools-deps (9)
I've run into a few issues regarding cljs.main
, :npm-deps
, and :foreign-libs
.
Let me know if any more information is needed.
If there aren't already Jira tickets for these, I can create them. If there are, links are appreciated, so I can follow them. 🙂
Note: I've also tested these with the latest master (`1.10.358`).
1. When using -co
, cljs.main
seems to default to repl mode (`-r`), however it exits immediately. It does, however, open up http://localhost:9000/.
clj -Sdeps "{:deps {org.clojure/clojurescript {:mvn/version \"1.10.339\"}}}" -m cljs.main -co "{}" && echo exited $?
exited 0
Does this command immediately exit for others?
(It doesn't matter if the -co
has properties or is an empty map.)
2. In order to use :npm-deps
from the command line, it seems -c
is required. (`-c` then -r
)
Starting a REPL with left-pad
as an example:
clj -Sdeps "{:deps {org.clojure/clojurescript {:mvn/version \"1.10.339\"}}}" -m cljs.main -co "{:npm-deps {left-pad \"1.3.0\"} :install-deps true}" -r
cljs.user=> (require '[left-pad])
cljs.user=> (left-pad "test" 5)
ReferenceError: module$home$garrett$node_modules$left_pad$index is not defined
(<NO_SOURCE_FILE>)
I recall something about module names being in two different formats in a recent Jira ticket.
This is looking for the full module$home$garrett$node_modules$left_pad$index
(I'm running this in my home directory /home/garrett
.) instead of the shorter/simpler module$left_pad$index
. I assume this is a related issue.
A workaround is to use -c
.
-c
requires :main
, so let's make the main file:
mkdir -p src/example
echo "(ns example.core)" > src/example/core.cljs
Starting a new REPL:
clj -Sdeps "{:deps {org.clojure/clojurescript {:mvn/version \"1.10.339\"}}}" -m cljs.main -co "{:npm-deps {left-pad \"1.3.0\"} :install-deps true :main example.core}" -c -r
cljs.user=> (require '[left-pad])
cljs.user=> (left-pad "test" 5)
" test"
Note: It seems that once the above command has been run, the original -r
-only command can be run. (Removing the out
folder causes the issue again.)
Original REPL invokation after previous 'fix':
clj -Sdeps "{:deps {org.clojure/clojurescript {:mvn/version \"1.10.339\"}}}" -m cljs.main -co "{:npm-deps {left-pad \"1.3.0\"} :install-deps true}" -r
cljs.user=> (require '[left-pad])
cljs.user=> (left-pad "test" 5)
" test"
3. Using :foreign-libs
along with :npm-deps
seems to be broken.
Starting a REPL with both :npm-deps
and :foreign-libs
(without the -c
/`:main` 'fix' for now):
clj -Sdeps "{:deps {org.clojure/clojurescript {:mvn/version \"1.10.339\"}}}" -m cljs.main -co "{:npm-deps {left-pad \"1.3.0\"} :install-deps true :foreign-libs [{:file \"
cljs.user=> (require '[left-pad])
This fails of course, but the following call fails regardless of if this is called.
cljs.user=> (left-pad "test" 5)
ReferenceError: module$home$garrett$node_modules$left_pad$index is not defined
(<NO_SOURCE_FILE>)
When this is called after the (require '[left-pad])
call, it fails.
cljs.user=> (require '[google.api])
java.io.FileNotFoundException: /home/garrett/https:/apis.google.com/js/platform.js (No such file or directory)
... (See for full stack-trace)
If the :foreign-lib
library is required before the :npm-deps
dependency, it will work.
Previous REPL invokation (with -c
/`:main` 'fix' to make left-pad
work, though the result is the same with or without—`google.api` can be required.):
clj -Sdeps "{:deps {org.clojure/clojurescript {:mvn/version \"1.10.339\"}}}" -m cljs.main -co "{:npm-deps {left-pad \"1.3.0\"} :install-deps true :foreign-libs [{:file \"" :provides [\"google.api\"] :global-exports {google.api gapi}}] :main example.core}" -c -r
cljs.user=> (require '[google.api])
cljs.user=> (require '[left-pad])
cljs.user=> (left-pad "test" 5)
" test"
@ghopper https://dev.clojure.org/jira/browse/CLJS-2666 might be a generalization of your item (2) above
Nice, -d out
does indeed fix the issue.
For item (1), -co
is an init option, its behavior is analogous to clj
vs. clj -e 3
vs. clj -e 3 -r
That makes sense. Shouldn't it either throw an error or be ignored instead of what it's doing now?
Thanks, Mike, I've created https://dev.clojure.org/jira/browse/CLJS-2809.
is there a way to write this (apply js/Math.min '(0 1 2))
without abusing the .
syntax? i.e. I usually invoke functions like this using the (.min js/Math 0 1 2)
syntax, but I can’t figure out how that works with apply
now I understand what you ask
Not sure if you can do it. .
is a special form.
In cljs we can do (apply (.-min js/Math) #js [1 2 3])
@souenzzo thanks! I didn’t think about using the .-
form. this is what i ended up with (defn mymin [& xs] (apply (.-min js/Math) xs))
seems to work
Hey folks, I’m trying to read and process a CSV in a macro so that I just get edn loaded into my clojurescript, but I keep getting arity <number of lines of csv + 6>
errors. Anybody know what’s going on?
In cljs:
(def csv-data
(dm/read-csv-file "data/awesome.csv")))
In dm.clj:(ns demo.macros
(:require [clojure-csv.core :as csv]))
(defmacro read-csv-file [file]
(doall (csv/parse-csv (slurp file))))
I see the file parsed in the compiled js, but I don’t know how I’m reading it wrong.The generated Javascript has this form:
devcards.core_card.csv_data = cljs.core.first((function (){
var G__31138 = cljs.core.PersistentVector.fromArray(["things","in","the","csv"], true);
......
var fexpr__31137 = cljs.core.PersistentVector.fromArray(["other","things","in","csv"], true);
return (fexpr__31137.cljs$core$IFn$_invoke$arity$1090 ? fexpr__31137.cljs$core$IFn$_invoke$arity$1090(G__31138,......,G__32227));
})());
I have the feeling I’m not getting the data type I expect to be getting from this, but I’m not exactly sure how to find out and what do do about it.
What is the best way to slurp in a file, process it, and just load it into your clojurescript without having it be re-processed each time?
I also asked on clojureverse, if people could possibly answer there and keep the solution for the ages: https://clojureverse.org/t/loading-a-csv-into-clojurescript-with-macros/2420
have you seen this? @clashthebunny
I’ve had things like that working if I preprocess data into edn in a separate process, but I’d like to have the data in a csv and then have the macro both slurp and parse it.
@clashthebunny dumping a CSV file into the code is a terrible idea and you should load if via ajax request instead.
So, you would make a program to parse and dump the CSV to edn, and then you would load that via ajax? Just write two “programs”?
Wouldn't frameworks be against the general philosophy of clojure? I understand that the philosophy is to have a simple and flexible language and grow it with libraries. Frameworks strict you more than libraries and then is difficult to use more than 1 framework. Using a framework like Re-Frame in clojurescript can be more composable than using a framework like Angular in javascript?
I have a re-frame app and I'm moving to fulcro. ATM I have a re-frame event that works like transact, I use some fulcro functions to do the query->db->tree normalization but still on re-frame. I already tested that fulcro components can be used mixed with reagent. Both are pretty modular, can be used together and can be extended without problems.
I have a re-frame app and I'm moving to fulcro. ATM I have a re-frame event that works like transact, I use some fulcro functions to do the query->db->tree normalization but still on re-frame. I already tested that fulcro components can be used mixed with reagent. Both are pretty modular, can be used together and can be extended without problems.
@clashthebunny if the csv file is static data that you are including on the page this is a fine technique
It does seem like something that would add to load time.
That totally makes sense.
Yep, it's returning code and the JavaScript I pasted sure seems like it's calling the last list as a function.
I make this mistake all the time, so when I see a wrong arity
error or a is not a function
error it is the first thing I look for
Yeay! I learned the syntax and many of the functions of Clojure, but I still feel like there are so many gotchas I haven't learned. The hidden power rears its head!
That makes sense. Shouldn't it either throw an error or be ignored instead of what it's doing now?
It does make it behave differently though. See above ^
@dfcarpenter stenciljs looks great, but when I look at the list of “wins” I do not see much that cljs and its web frameworks do not already supply. Just my take, though.
Ok đź‘Ť:skin-tone-2:
and if you want a certain behavior you should always supply a main option -c
-r
etc, and if you want -co
compile options to take effect you probably always want to use the -c
option.
Yeah, I'm using it during development. :) It's excellent. For actual builds I'm going with cljs.main
to keep things simple and consistent.
I originally ran into these issues with figwheel, I just dropped down to cljs.main
to make the bug reports.
first just trying to figure out structure for configuration that is expressive enough to cover most of the cases
@bhauman Yeah, I am. 🙂 I didn't like having my builds in the root directory though, so I've been falling back to -co @$build.edn -c
.
Oh, nice. That would be useful. 🙂
Huh, I didn't try that. I just tried with the actual path including the .cljs.edn
. That may work.
@bhauman It's definitely not a normal usage of tagged-literals. I was basically looking for a way to conditionally do requires in certain namespaces, depending on project config, similar to how @thheller described here: https://dev.clojure.org/jira/browse/CLJS-2396
So, basically, now I can just tuck a #mything/node
before a particular require vector, which only returns the vector when some some closure-defines
of some node
keyword is present
Actually, bad idea, since the nils fail spec for the ns
form. This works though:
;; /co.edn
{:main "my.core"
:watch "src"
:output-dir "out"
:output-to "out/main.js"
:asset-path "/out"
:optimizations :none
:source-map true
:browser-repl true
:closure-defines {my.require/opts false}}
;; src/data_readers.cljc
{my/if-env my.impl/if-env}
;; src/my/impl.clj
(ns my.impl
(:require [cljs.env :as env]))
(defn if-env [[if-str? then? else?]]
(if (-> env/*compiler* deref :options :closure-defines (get if-str?))
then?
else?))
;; src/my/core.cljs
(ns my.core
#my/if-env ["my.require.opts"
(:require [cljs.pprint :as pp]
[cljs.reader :as reader])
(:require [cljs.reader :as reader])])
(println "cljs.reader:" reader/read-string)
(println "cljs.pprint:" pp/pprint)
;=> Uncaught ReferenceError: pp is not defined
hey, dumb question. Why is it that in react based cljs wrappers, you never specify that you're writing to the body tag? Is the virtual dom always expecting one form that will be used to render the <body> tag of the html doc?
you always specify which element to render into. could be body typically is some div
rendering into the body might do funny things if you’re loading your script from a script
tag in the body (which is recommended, for parse/load times): <body><script src="my-app.js"></script></body>
after you render your app into the body tag, the script tag loading the app would be removed by React
also, if you have some static content “around” your app (headers, footers, etc that don’t need to be dynamically controlled by the app code), you can just have it in the HTML and not waste cycles rendering it via react
Huh, good insight, thanks @tstephens
idiomatic way to add event listener to fairly simple html/cljs page? wanting to use goog.events but not sure if i'm missing something in project.clj or what
Can :foreign-libs
be used without :file
defined? This seems to indicate that it can in order to use :global-exports
: https://clojurescript.org/news/2017-07-30-global-exports.
Building client...
Exception in thread "main" java.lang.Exception: No :file provided for :foreign-libs spec {:provides ["google.api"], :global-exports {google.api gapi}, :foreign true}
at cljs.js_deps$build_index$fn__1074.invoke(js_deps.cljc:183)
lol i had my javascript embedded in the head tag so it never saw the dom elements load... doi..
and that doesn’t really have anything to do with :global-exports
per se, it’s just a useful feature
@dnolen Overriding from where? I'm not quite following.
Well, it would only make sense if you were using :global-exports
. Otherwise, there's no point.
So the example I linked to is no longer valid?
:foreign-libs [{:provides ["cljsjs.react"]
:global-exports '{cljsjs.react React}}
{:provides ["cljsjs.react.dom"]
:global-exports '{cljsjs.react.dom ReactDOM}}]
I want to :provides
a namespace with a global export from the page. I'll provide the <script>
on the page, and I want to use it from Clojurescript. Is there no way to do that, since I can't use :foreign-libs
without a :file
?
It seems like that's what's being done here: https://clojurescript.org/news/2017-07-30-global-exports.
Ok :thumbsup:
@ghopper you can in the same externs do multiple bindings https://gist.github.com/souenzzo/7f376efca955660e6221bca7827164ba#file-build-clj-L21
@souenzzo Oh, interesting. So I could just use a dummy :file
for all my exports?
grrr... can't get figwheel-sidecar css reloading... it claims the watcher exists/has been set up, but changes don't seem to send any messages!
...
Figwheel: Starting server at
Figwheel: Watching build - dev
Compiling "resources/public/js/compiled/app.js" from ["src/cljs"]...
Successfully compiled "resources/public/js/compiled/app.js" in 8.368 seconds.
Figwheel: Starting CSS Watcher for paths ["resources/public/css"]
Launching ClojureScript REPL for build: dev
Figwheel Controls:
(stop-autobuild) ;; stops Figwheel autobuilder
...
is the link supposed to be autogenerated? I included it explicitly as <link href="css/style.css" rel="stylesheet" type="text/css">
which is what the figwheel documentation says to do... https://github.com/bhauman/lein-figwheel/wiki/Quick-Start#auto-reloading-css
there must be something I'm missing. The default figwheel sidecar system definitely includes a CSS watcher component...
@ghopper now that you’ve explained what you are trying to do I understand and yes you misunderstood what was being shown before
Sorry it wasn't clear at first. I'm still not seeing how the example I linked to is overriding anything.
Provided in the same way :foreign-libs
provides the namespace, or just that the namespace exists elsewhere?
Ok, thanks :thumbsup: 🙂
Gotcha :thumbsup:
Will do
:foreign-lib
w/o :file
, motivation being support :global-exports
on external libs which are not part of any build
@idiomancy any luck?
in project clj:
:figwheel {:css-dirs ["resources/public/css"]
:ring-handler understanding-re-frame.handler/dev-handler}
in index.html:
<head>
<meta charset='utf-8'>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
repl startup command:
(use 'figwheel-sidecar.repl-api)
(start-figwheel!) ;; <-- fetches configuration
(cljs-repl)
then when clean and recompile, you look in the devtools console to see the messages coming from figwheel
oh weird... its... its working now? But only after I have made some change to the dom...
@dnolen Thanks again 🙂 I've created https://dev.clojure.org/jira/browse/CLJS-2810 I was mainly just trying it to work around https://dev.clojure.org/jira/browse/CLJS-2809, so I guess I'll have to find something else.
huh, thanks @bhauman that's a really good tool. I can see the order of operations here this way.
Well, doing the requires in the other order fixes the problem. I'm not sure why requiring a local :npm-dep
would break the requiring of a remote file.
You've got point though. I could just use a local file for now.
I may have made a bad assumption. When a remote file is used in :foreign-libs
, is it downloaded at compile time or runtime?
In that case, I shouldn't be using this at all, since I need to always have the latest of the library in case the APIs change. Yeah, I'm sure it's something simple. In any case, I suppose I don't need to worry about it after all. 🙂
Actually, bad idea, since the nils fail spec for the ns
form. This works though:
;; /co.edn
{:main "my.core"
:watch "src"
:output-dir "out"
:output-to "out/main.js"
:asset-path "/out"
:optimizations :none
:source-map true
:browser-repl true
:closure-defines {my.require/opts false}}
;; src/data_readers.cljc
{my/if-env my.impl/if-env}
;; src/my/impl.clj
(ns my.impl
(:require [cljs.env :as env]))
(defn if-env [[if-str? then? else?]]
(if (-> env/*compiler* deref :options :closure-defines (get if-str?))
then?
else?))
;; src/my/core.cljs
(ns my.core
#my/if-env ["my.require.opts"
(:require [cljs.pprint :as pp]
[cljs.reader :as reader])
(:require [cljs.reader :as reader])])
(println "cljs.reader:" reader/read-string)
(println "cljs.pprint:" pp/pprint)
;=> Uncaught ReferenceError: pp is not defined