This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-07-28
Channels
- # announcements (21)
- # beginners (12)
- # calva (16)
- # cider (3)
- # clj-commons (23)
- # clojure (32)
- # clojure-europe (8)
- # clojure-norway (3)
- # clojure-uk (3)
- # clojurescript (12)
- # conjure (2)
- # cursive (6)
- # data-science (15)
- # datomic (5)
- # dev-tooling (10)
- # emacs (13)
- # events (3)
- # lsp (36)
- # missionary (6)
- # off-topic (22)
- # portal (46)
- # releases (1)
- # shadow-cljs (15)
- # slack-help (7)
- # sql (3)
- # squint (1)
- # timbre (5)
how can I know if a function is defined in cljs? I want to define it only if it's not defined. I tried:
(try
(js/clickNode "test")
(.log js/console "clicknode exists")
(catch :default _e
(.log js/console "defining callback")
(set! js/clickNode (fn [node-id]
(.log js/console "clicked node" node-id)))))
But I'm still seeing an (uncaught?) ReferenceError in the browser console and clickNode is not defined.If you can help it, it's better not to change global things.
If you can't help if, you can set a global with (set! js/window -clickNode (fn ...))
.
Thanks, both seem to work but they didn't fix my problem 😞
Not expecting an answer but for the curious:
I'm trying something kind of niche - use mermaidjs node click events in clojurescript (specifically through hyperfiddle). It's not wotking. I thought it's related to the callback not being defined "in time" but it seems like it's a different problem.
I also tried defn ^:export clickNode ...
but that also didn't work.
I have a java promise that returns an object with keys svg
and bindFunctions
. I need to call bindFunctions
to make the svg clicks operate properly (probably to bind the functions to the svg elements).
SVG is mounted and looks find but the bindfunctions thing is not working:
(when (exists? (.-clickNode js/window))
(println "defining clickNode")
(set! js/window -clickNode (fn [node-id]
(println "clicked node" node-id))))
(.then
(.render js/mermaid "dummy" mmd)
(fn [res]
;; (println mmd)
(let [e (.getElementById js/document "mermaid")
svg (.-svg res)
bind-functions (.-bindFunctions res)]
(set! (.-innerHTML e) svg)
(when bind-functions
(println "binding functions" bind-functions)
(bind-functions e)))))
nil))))))
It could also be a problem of the library I'm using (hyperfiddle)in the graph definition, it's a line that says something like: click A clickNode And it means that when the node on svg is clicked it should invoke clickNode
To my understanding that's why you get a callback to bind functions after the svg has been generated
this is the library if you're interested: https://mermaid.js.org/config/usage.html
Those docs don't really say anything about the callbacks, or I didn't notice it. The "Binding events" section is as bare-bones as it gets and also has an incorrect explanation at the bottom.
yeah I had to dig into the code to understand some things. I'll debug it and I hope I remember to update here if it works. It's probably something in my code.
I'm also not usually using clojurescript or javascript so it's challenging.
updating that I decided to move to cytoscape for now