This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-22
Channels
- # announcements (1)
- # babashka (94)
- # beginners (11)
- # biff (9)
- # calva (21)
- # clj-kondo (14)
- # clojure (12)
- # clojure-europe (56)
- # clojure-nl (1)
- # clojure-norway (41)
- # clojure-uk (4)
- # clojurescript (4)
- # core-logic (2)
- # gratitude (12)
- # honeysql (1)
- # hoplon (3)
- # hugsql (7)
- # introduce-yourself (2)
- # jobs-discuss (23)
- # leiningen (3)
- # malli (11)
- # off-topic (1)
- # pedestal (11)
- # reagent (3)
- # squint (8)
- # vim (9)
- # xtdb (3)
Submitted first biff pr 🎉
I'm using ApexCharts inside of Biff after converting them to hiccup. The chart values are supplied by js. I could include the js from a file with the values baked in but I need to fetch them on the fly from the db. How do I create a function that returns a [:script ...] tag with the modified js? https://flowbite.com/docs/plugins/charts/
in general what I tend to do for this kind of stuff is I serialize the data to json and store it on an element attribute, then have the js read it from the attribute.
so for the rendering part you'd have something like [div#chart {:data-chart-contents (cheshire/generate-string ...)}]
with hyperscript you can also do something like :_ "init call renderChart(this)"
, then define a renderChart js function that looks up the data-chart-contents attribute on the element that gets passed in
ok. grokking. like molasses.
btw, had started down string-interpolation-hell with
(defn dynajs [x]
[:script (str "alert('Hello, " x " world!');")])
;; (dynajs "cruel")
but of course the single quotes behaved badly on the page.ha yeah, that's why I like just putting the json on an attribute, no need to deal with escaping anything yourself
That worked perfectly.