This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-01
Channels
- # announcements (14)
- # aws (1)
- # babashka (22)
- # beginners (105)
- # biff (12)
- # calva (1)
- # cider (7)
- # cljsrn (1)
- # clojure (33)
- # clojure-europe (22)
- # clojure-germany (1)
- # clojure-uk (3)
- # clojurescript (28)
- # component (15)
- # copenhagen-clojurians (1)
- # core-typed (29)
- # cursive (8)
- # data-science (2)
- # datomic (2)
- # emacs (16)
- # gratitude (3)
- # humbleui (3)
- # introduce-yourself (4)
- # lsp (1)
- # other-languages (3)
- # rdf (3)
- # sci (6)
- # shadow-cljs (9)
- # spacemacs (12)
- # tools-build (1)
- # tools-deps (5)
- # vim (3)
- # vscode (1)
Hi guys! I'm trying to test calling a clojurescript function compiled into js by shadow-js. On the js side i'm providing a json object, and trying to parse it as clojure map on the CLJS side. It's printed as
#js {:name #js {:first John, :last Doe}, :email }
How to do access it beyond the "#js" at the beginning?
If I use js->clj then the keys become strings instead of keywords, which is not desired.Hi everyone 👋 whats the best/latest tutorial/repo to get started with clojurescript?
If I wanted to start a new project and use a js lib like this: https://github.com/zerodevx/zero-md what would be the best, build tool setup? lein? tool deps?
Hi guys, there is a javascript library for Pusher (realtime websocket connection) that I wanna use in clojurescript. How do i integrate and use an npm library in clojurescript syntax? For example
var pusher = new Pusher("APP_KEY", {
cluster: "APP_CLUSTER",
});
Not clear how to use in cljs
Thank you!You need to learn about JS interop. There's a cheatsheet here https://cljs.info/cheatsheet/ and there's plenty of articles and videos on the topic.
So that code above would be
(def pusher (Pusher. "APP_KEY" #js {:cluster "APP_CLUSTER"}))
Right i'm beginning to understand how it works! @U2FRKM4TW going with this logic, can you please give an example for how to transfer the following code?
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert(JSON.stringify(data));
});
First line would be something like this i guess?
(def channel (.-subscribe pusher) "my-channel")
And all global JS values can be access by adding js/
in front of all. Also, for such values you can leave the .
usage as it is.
So e.g. JSON.stringify(data)
will be either (-stringify js/JSON data)
or even (js/JSON.stringify data)
.
Oh, also a correction on my previous message - that -
is not needed in your CLJS code. Use .
instead of .-
.
How do you add code in the componentDidMount lifecyle in reagent, other than the verbose form-3 ?
A slightly less verbose solution is to add :component-did-mount
metadata on the returned Hiccup.
But I'd stick to a form-3 component - I myself don't like using metadata when there are alternatives.
Another solution would be to use a form-2 component, add a ref function to the top level Hiccup item, and do the work in that function. But it's quite "dirty" since that's not what the refs are for.
Although my bad - not to the Hiccup vector but to an extra function, so it'll be a form-2 component.
You mean this part? https://cljdoc.org/d/reagent/reagent/1.1.0/doc/tutorials/creating-reagent-components?q=with-meta#:~:text=It%20is%20possible%20to%20create%20Form%2D3%20components
Quoting https://reactjs.org/docs/refs-and-the-dom.html#when-to-use-refs:
> Avoid using refs for anything that can be done declaratively.
And :component-did-mount
is, I would argue, a more declarative approach.
The next section at the link above is also relevant.
Apart from that:
> ref updates happen before componentDidMount or componentDidUpdate lifecycle methods.
which might create issues with nested form-3 components which will be hard to debug.
Took the @thheller repo next-cljs
upgraded to nextjs 12. Then modified the output hook a bit. And now got nextjs
+ serverSideProps
working 😎
Going to take the code and modify it a bit soon to be able to support Remix. Then we have a good isomorphic / ssr solution for clojurescript It's promising.
I wonder if the nextjs edge runtime could run in graaljs and therefore make normal clojure interop possible from serversideprops