This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-08
Channels
- # architecture (8)
- # aws (25)
- # babashka (9)
- # beginners (57)
- # calva (16)
- # cider (16)
- # clj-kondo (3)
- # cljdoc (13)
- # cljsrn (6)
- # clojure (272)
- # clojure-europe (36)
- # clojure-losangeles (1)
- # clojure-nl (8)
- # clojure-poland (3)
- # clojure-spec (4)
- # clojure-uk (8)
- # clojuredesign-podcast (9)
- # clojurescript (92)
- # code-reviews (1)
- # conjure (8)
- # core-async (1)
- # cursive (13)
- # datalog (1)
- # datascript (35)
- # datomic (76)
- # duct (10)
- # emacs (5)
- # events (7)
- # figwheel-main (1)
- # fulcro (35)
- # graalvm (20)
- # graphql (6)
- # jobs (3)
- # klipse (1)
- # london-clojurians (1)
- # malli (3)
- # off-topic (223)
- # pathom (2)
- # pedestal (13)
- # portal (1)
- # reitit (6)
- # remote-jobs (1)
- # shadow-cljs (21)
- # specter (2)
- # sql (63)
- # tools-deps (85)
- # tree-sitter (4)
- # xtdb (6)
i'm following this: https://www.learn-clojurescript.com/section-2/lesson-14-performing-io/ . under "Handling Events", when i try point 2, (gevents/listen input gevents/EventType.KEYUP update-target)
, i get WARNING: Use of undeclared Var goog.events/EventType at line 2 <cljs repl>
Testing in a repl led me to:
goog.events/EventType.KEYUP
;; => nil
goog.events.EventType.KEYUP
;; => "keyup"
(.-KEYUP goog.events.EventType)
;; => "keyup"
/
to be a function not an attribute lookup.Scratch that. Actually running it gives me the same results as the course.
(require '[goog.events :as gevents])
gevents/EventType.KEYUP
;; => "keyup"
and this https://google.github.io/closure-library/api/goog.events.EventType.html seems to be saying that goog.events.EventType.KEYUP
exists
however, if i replace gevents/EventType.KEYUP
with "keyup"
, things work as expected. what's wrong with gevents/EventType.KEYUP
?
it mostly allows the code to be minified more. ie. when closure minifies goog.events.EventType.KEYUP
it turns into aB
or so which is much shorter than "keyup"
in the final release build. doesn't really matter much but thats the reason I believe.
Hello everyone! I'm just trying to follow the steps here: https://clojurescript.org/guides/quick-start , but i'm on windows and I get an error if I try a PRODUCTION build, normal build works OK, but on Production build I get this:
Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/Users/ascheinert/Downloads/cljs_hw/out/cljs/core.js
at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229)
at com.google.javascript.jscomp.SourceMapResolver.getRelativePath(SourceMapResolver.java:102)
at com.google.javascript.jscomp.SourceMapResolver.extractSourceMap(SourceMapResolver.java:63)
at com.google.javascript.jscomp.JsAst.parse(JsAst.java:168)
at com.google.javascript.jscomp.JsAst.getAstRoot(JsAst.java:55)
at com.google.javascript.jscomp.CompilerInput.getAstRoot(CompilerInput.java:133)
at com.google.javascript.jscomp.Compiler.parseInputs(Compiler.java:1720)
at com.google.javascript.jscomp.Compiler.parseForCompilationInternal(Compiler.java:939)
at com.google.javascript.jscomp.Compiler.lambda$parseForCompilation$4(Compiler.java:922)
at com.google.javascript.jscomp.CompilerExecutor$2.call(CompilerExecutor.java:102)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:835)
Hello : ) I want to convert 1 clojure function to 1 "standalone" javascript function. I want to use this function inside mongoDB,that only allows 1 function without extra dependencies. Is it possible to do it with Clojurescript? If its not possible any alternative way?
@takis_ You can export the function and compile it with CLJS. A very hacky way is this (from planck):
cljs.user=> (defn foo [x] (inc 1))
#'cljs.user/foo
cljs.user=> (str foo)
"function cljs$user$foo(x){\nreturn ((1) + (1));\n}"
i am new with clojurescript,the times that i compliled it,it produces many large javascript files
@takis_ You'll have to use advanced compilation, so it cuts away everything that's not used
If someone experienced in clojurescript can convert this function to 1 "standalone" javascript function, it will be helpful, of how he did it
(defn mygroupby [v k]
(reduce (fn [grouped-array doc]
(let [cur-key (str (get doc k))]
(if (contains? grouped-array cur-key)
(update grouped-array cur-key conj doc)
(assoc grouped-array cur-key [doc]))))
{}
v))
@takis_ put your file in a src folder, add ^:export
to it, like:
(ns my.cljs)
(defn ^:export mygroupby [v k]
(reduce (fn [grouped-array doc]
(let [cur-key (str (get doc k))]
(if (contains? grouped-array cur-key)
(update grouped-array cur-key conj doc)
(assoc grouped-array cur-key [doc]))))
{}
v))
Then compile with:
$ clojure -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.597"}}}' -m cljs.main -O advanced -c my.cljs
Find the compiled asset in out/main.js
Looking at the output size this will probably make you write this function in JS instead, but that's up to you :)
Hey, 🙂 It seems to me that there is some problem with name resolution in defrecord
when defining method named delete
. In the following code it fails with a type error saying that delete
is not a function. However when I rename it to del
or something else it works as expected. Also I am able to call it like ((:delete foo))
. Does anyone knows what is going on? Thx 🙂
(defn make
[ddb-client]
(map->DBClient {:get #(-> ddb-client .get .promise)
:put #(-> ddb-client .put .promise)
:query #(-> ddb-client .query .promise)
:delete #(-> ddb-client .delete .promise)}))
(def foo (make client))
(.delete foo)
most likely https://clojure.atlassian.net/browse/CLJS-871 since delete
is also a reserved word
@takis_ :
> require('./out/main')
{ my: { cljs: { mygroupby: [Function: Ee] } } }
This is in node1)created a folder jsgen 2)created a folder jsgen/src 3)put my.cljs inside jsgen/src 4)cd jsgen 5)clojure -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.741"}}}' -m cljs.main -O advanced -c my.cljs Execution error (FileNotFoundException) at http://java.io.FileInputStream/open0 (FileInputStream.java:-2).-Sdeps (No such file or directory) Full report at: /tmp/clojure-11667070442944232008.edn
1)created a folder jsgen 2)created a folder jsgen/src/my 3)put my.cljs inside jsgen/src/my 4)cd jsgen 5)clojure -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.741"}}}' -m cljs.main -O advanced -c my.cljs Execution error (FileNotFoundException) at http://java.io.FileInputStream/open0 (FileInputStream.java:-2). -Sdeps (No such file or directory) Full report at: /tmp/clojure-6401545215020083189.edn
"-Sdeps (no such file or directory)" - I bet your "clojure" isn't the one that uses deps.edn
check out which clojure
it's saying that it wants to open -Sdeps
as a file, which probably means someone's old useless bundling of clojure
deps.edn isn't a version of clojure, what I'm saying is there are CLI tools called "clojure" that don't use deps.edn, the which
tool will help you figure out what actually runs if you run clojure
at the command line
eg. debian has a "clojure" that just runs java and loads the clojure library and runs clojure.main
which isn't what most people would want these days
here's me verifying that my "clojure" knows what Sdeps means
$ grep Sdeps $(which clojure)
-Sdeps)
-Sdeps EDN Deps data to use as the last deps file to be merged
clojure -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.741"}}}' -m cljs.main -O advanced -c my.cljs Execution error (AssertionError) at cljs.closure/build (closure.clj:3098). Assert failed: No file for namespace my.cljs exists uri Full report at: /tmp/clojure-17078041070905694243.edn
if the ns is my.cljs
you need to have src/my/cljs.cljs
cljs is a weird name for an ns btw
If you read the get started article it should go over all this. If you create an advanced optimizations build you will have only a single file as output
i just runned clojure -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.741"}}}' -m cljs.main -O advanced -c my.cljs
Your steps above with advanced should have produced a single output. Probably you have some remnants from past compilation hanging around. Delete the output directory and run it again and I suspect you will be fine. Alternatively give a new output location and you should see the single generated file I suspect
thank you for your patience , you helped me alot, dpsutton ,noisesmith , borkdude 🙂
@takis_ you can do const { my } = require("./out/main");
which will give you my.cljs.yourfunction
as the one function
$ node
Welcome to Node.js v14.5.0.
Type ".help" for more information.
> const { my } = require("./out/main");
undefined
> my.cljs.mygroupby
[Function: Ee]
perfect 🙂 thats exactly what i need it , thank you alot i was thinking that no way i can clean all those code
weird, i'm getting this at the cljs repl: cljs.user> gevents/EventType
WARNING: Use of undeclared Var goog.events/EventType at line 1 <cljs repl>
#js{:INPUT "input", :SUSPEND "suspend"
what is going on here?
cljs.user> (goog.object/get gevents/EventType (clj->js :KEYUP))
WARNING: Use of undeclared Var goog.events/EventType at line 1 <cljs repl>
"keyup"
how are you requiring gevents
?
@smith.adriane thanks for looking
i'm trying to see if I see the same issue, but I just updated my OS and nothing is working atm ¯\(ツ)/¯
figured out a fix, still not sure what's going on, but this works:
(require '[goog.events.EventType :refer [KEYUP] :rename {KEYUP keyup}])
the difference is between (require '[goog.events] ...)
, versus (require '[goog.events.EventType] ...)
but i'm not sure how that would "work" and give a warning.
it probably works without optimizations, but might not work under advanced compilation
I understand how an atom interacts on top of the jvm (multithreaded compare and swap) but on the browser what role does it play? I imagine conceptually it could be used with web workers
an atom is pretty much just an object with a state
property that gets changed on swap!
/ reset!
, and calls watchers on update
I don’t think the atom API could be used with web workers because it’s expected that reset!
and swap!
will block until the value is updated, but that’s impossible to do in a JS environment + web workers
that would be a classic example of https://blog.izs.me/2013/08/designing-apis-for-asynchrony