This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-26
Channels
- # announcements (1)
- # atom-editor (7)
- # babashka (9)
- # beginners (46)
- # cider (1)
- # circleci (2)
- # clj-on-windows (1)
- # cljdoc (5)
- # cljsrn (2)
- # clojure (25)
- # clojure-austin (8)
- # clojure-brasil (4)
- # clojure-europe (52)
- # clojure-nl (1)
- # clojure-norway (162)
- # clojure-uk (2)
- # cursive (3)
- # datalevin (134)
- # datomic (16)
- # defnpodcast (8)
- # graphql (9)
- # honeysql (5)
- # hoplon (26)
- # hyperfiddle (18)
- # introduce-yourself (1)
- # lsp (4)
- # malli (19)
- # nbb (16)
- # nrepl (1)
- # practicalli (3)
- # releases (3)
- # shadow-cljs (36)
- # tools-deps (7)
- # vim (2)
- # xtdb (9)
Headed to Clojure Conj, who else is going?
Im going
Myself and some of the Juxt/XTDB team will be there! Already had a few conversations with people here about electric
I’m trying to incorporate plotly into a sample electric app. I’m trying to set up plotly click events to drive electric functions so I can easily call the server, change state, etc.
When the “plotly_click” e/fn handler is called on line 15 (new V1 …)
, I get an invalid arity exception
What am I doing wrong?
I have a feeling that the proper way to do this is that the plotly callback should mutate some atom and then the electric fn should watch that atom
I think you can only call electric functions from within an electric function body or an e/def, and the problem is that plot! Is a regular cljs function and in it you are trying to call V!
What’s the story around interop? Plotly needs a plain javascript fn to handle its callback
oh, maybe i get it… instead of (.on div ….) use dom/on
?
I’ve updated the code to try dom/on
. Now, I get a compiler warning Cannot infer target type in expression (. inst__30182__auto__ newPlot G__46562 G__46563)
and it doesn’t seem that the callback is getting invoked at all.
Here’s a working version. The big realization for me is that new
is a special form (hence all the electric macros). This approach relies on plain Clojurescript for the interop and state atoms to get reactivity with electric.
Adding a ^js
type hint to js/Plotly
where you call .newPlot
may help with the warning. That shouldn't affect behavior in development but will probably break things when you try to compile with advanced optimizations
Thanks!
we have a convention to name electric functions capitalized. Electric functions are called with new
. Therefore if you want to run electric code on a DOM event you call
(dom/on div "plotly_click" (e/fn [data] ... (new V! ...)))
dom/on
will call new
on your e/fn
If a clojure function suffices you can use dom/on!
(dom/on! div "plotly_click" (fn [data] ...))