This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-15
Channels
- # admin-announcements (1)
- # announcements (8)
- # babashka (6)
- # beginners (70)
- # bristol-clojurians (1)
- # chlorine-clover (15)
- # cider (3)
- # cljs-dev (2)
- # cljsrn (27)
- # clojure (249)
- # clojure-europe (19)
- # clojure-italy (2)
- # clojure-nl (12)
- # clojure-spec (11)
- # clojure-uk (42)
- # clojuredesign-podcast (6)
- # clojurescript (39)
- # community-development (1)
- # conjure (43)
- # cursive (37)
- # data-science (1)
- # datomic (3)
- # duct (16)
- # figwheel-main (23)
- # fulcro (3)
- # instaparse (5)
- # java (5)
- # jobs (1)
- # jobs-discuss (1)
- # malli (11)
- # off-topic (27)
- # re-frame (32)
- # reagent (5)
- # reitit (2)
- # rum (15)
- # shadow-cljs (24)
- # spacemacs (7)
- # sql (5)
- # test-check (3)
- # tools-deps (5)
Can someone please explain what set!
does in this example ? It's from this blog : https://tonsky.me/blog/acha-acha/
(let [socket (js/WebSocket. url)]
(set! (.-onmessage socket)
(fn [event]
(let [tx-data (read-transit (.-data event))]
(d/transact! conn tx-data)))))
Ah! thank you. I'm not well versed with javascript...so was confused. So the function is set to socket.onmessage event ..right ?
I would phrase it a little differently. When that socket receives a message, it will trigger the fn
Yep..that's what i meant..but phrased it poorly 🙂 .. thank you
https://cljs.info/cheatsheet/ see js-interop section
It's also nice paste code here and see what it's done in cljs http://app.klipse.tech/
Hey everyone. Quick question: I initialised a new figwheel-main project with reagent. Then, I tried following https://figwheel.org/docs/npm.html to add an npm dependency. I get this error, however:
Configuration error in CLJS compile options: dev.cljs.edn
-- Spec failed --------------------
{:main ..., :target :bundle, :bundle-cmd ...}
^^^^^^^
should be one of: :nodejs, :webworker
-- Doc for :target -----
If targeting nodejs add this line. Takes no other options at the
moment. The default (no :target specified) implies browsers are being
targeted. Have a look here for more information on how to run your
code in nodejs.
:target :nodejs
I searched online for a while but couldn't find any solutions to this problem. Does anyone know what might be the problem?My project.clj
:
(defproject weather-app "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url ""
:license {:name "Eclipse Public License"
:url ""}
:min-lein-version "2.7.1"
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.10.520"]
[reagent "0.8.1"]]
:source-paths ["src"]
:aliases {"fig" ["trampoline" "run" "-m" "figwheel.main"]
"fig:build" ["trampoline" "run" "-m" "figwheel.main" "-b" "dev" "-r"]
"fig:min" ["run" "-m" "figwheel.main" "-O" "advanced" "-bo" "dev"]
"fig:test" ["run" "-m" "figwheel.main" "-co" "test.cljs.edn" "-m" "weather-app.test-runner"]}
:profiles {:dev {:dependencies [[com.bhauman/figwheel-main "0.2.3"]
[com.bhauman/rebel-readline-cljs "0.1.4"]]
}})
And dev.cljs.edn
^{:watch-dirs ["test" "src"]
:css-dirs ["resources/public/css"]
:auto-testing true}
{:main weather-app.core
:target :bundle
:bundle-cmd {:none ["npx" "webpack" "--mode=development" :output-to "-o" :final-output-to]}}
Your ClojureScript version is too old. Bump it up to at least the versions in the article
I see, thanks. I was hoping the template would setup everything with working versions 😅 I'll bump up the versions and try again
Well, I can build without errors but now, lein fig:build
cannot with to browser, so no repl propmt shows up. Also, the browser page is empty and console shows a 404 error
I'm trying to get the ASCII value of a character in a cljc file. How would I code the reader conditional for cljs?
(defn get-ascii
"Gets the ASCII code of a char"
[c]
#?(:clj (int c)
:cljs (. c charCodeAt 0)))
Right now I have this but it doesn't seem/look rightchanged it to
(.charCodeAt c 0)
and it looks pretty good, but can someone look over that?Good morning Clojurians, I am new to frontend and I am pulling my hair out trying to access a function. Following example on this https://clojurescript.org/guides/quick-start, and looking at this code:
(ns hello-world.core)
(println "Hello world!")
;; ADDED
(defn average [a b]
(/ (+ a b) 2.0))
Is it possible to render the output of the average
function to html? Firstly, I tried it like this:
<script src="out/main.js" type="text/javascript"></script>
<script type="text/javascript">hello_world.core.average(1,2);</script>
but it complains that it is not defined. I tried both hello-world
and hello_world
but it keeps complaining that it is not defined. Nevertheless, I can type in the google chrome console hello_world.core.average(1,2)
and it does return 1.5.Tried it, no luck. The error on the Chrome console is:
(index):10 Uncaught ReferenceError: hello_world is not defined
at (index):10
My full html listing:
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<script src="out/main.js" type="text/javascript"></script>
<div>
<script type="text/javascript">hello_world.core.test_fn();</script>
Welcome Home</div>
</body>
</html>
Something tells me that it is not picking up the hello_world namespace.Ah, so it's hello_world
that's undefined. Then it seems like your out/main.js
doesn't contain the required namespace.
I followed the example very closely
so looking at the main.js
listing:
var CLOSURE_UNCOMPILED_DEFINES = {};
var CLOSURE_NO_DEPS = true;
if(typeof goog == "undefined") document.write('<script src="out/goog/base.js"></script>');
document.write('<script src="out/goog/deps.js"></script>');
document.write('<script src="out/cljs_deps.js"></script>');
document.write('<script>if (typeof goog == "undefined") console.warn("ClojureScript could not load :main, did you forget to specify :asset-path?");</script>');
document.write('<script>goog.require("process.env");</script>');
document.write('<script>goog.require("clojure.browser.repl.preload");</script>');
document.write('<script>goog.require("hello_world.core");</script>');
looks like it is trying to source it.you can see that it’s loading things asynchronously - adding script tags. it’s not defined at the time where you call it but subsequently becomes defined once the script loads. i think.
how do i get :`ignoreLogs` from this?
=> react/LogBox
#js{:ignoreLogs #object[ignoreLogs],
:ignoreAllLogs #object[ignoreAllLogs],
:uninstall #object[uninstall],
:install #object[install]}
not sure why i can’t get a hang of this type of js interactions but thanks again @thheller!
is there any documentation for the special form js*
I see it used internally in cljs.core
and i know we're not supposed to use it, but i'm just curious how it works
if you use set!
you only need to change it once, it's not a per-file variable
you could use binding
or set!
to override the value wherever needed, as with any dynamic var
hmm actually the doc explicitly mentions "for the remainder of the file", but that's not how any vars that I know of actually work(?) > Once set the compiler will warn for the remainder of the file anytime it cannot determine the types involved in a dot form, whether property access or method invocation. https://clojurescript.org/guides/externs#externs-inference
I guess it is important to note that if you set it after the ns
form, it won't effect the files required by that ns - you need it before ns
to do that