Fork me on GitHub
#scittle
<
2023-05-18
>
chromalchemy12:05:46

What is the most efficient way to pass data from html to scittle cljs? I could read some json from a string. Can I pass EDN data as a string?

borkdude12:05:56

Not sure what you mean exactly

ray13:05:06

If you pass EDN you can read it directly rather than going via JSON

borkdude13:05:22

I didn't understand the "from HTML" part

borkdude13:05:31

how do you "pass from HTML"?

2
ray20:05:44

I was guessing he meant http fetch

chromalchemy18:05:41

Sorry for late response.. On my stack I have a Handlebars.js HTML templating language with some data-store access patterns built into syntax. I can access the data in the Handlebars code and render it in HTML in the same .html template file. What if I want to use that (indirectly sourced) data in Scittle? Currently I am rendering a string in a html data attribute, then in Scittle cljs, accessing that dom node, reading the data value, and parsing the string into a cljs data structure… Is there a more direct way? If I “print” an EDN literal into this html, can Scittle cljs “read” that as cljs data directly somehow? I think technically it would still be a string coming into cljs runtime. Is there a read-edn fn? I could render an additional Scittle <script> tag in the html, with a def’d EDN value, and Scittle could likely just see that as named data. But then the placing of the script tag might be complicated…? I would probably be better off trying to get the json data more directly (from fetch or something), but I was curious what was supported?

borkdude18:05:32

> is there a read-edn fn? yes, this function is in clojure.edn/read-string?

borkdude18:05:49

perhaps if you have github project + index.html page I could look at locally, I could say more

chromalchemy19:05:39

Thanks for the feedback. read-string sounds most appropriate for this case. I will try that. I’ll make a simplified repo later for public consideration…