Fork me on GitHub
#clojurescript
<
2023-10-02
>
Can11:10:02

Hello! I am not able to work this code Can anyone take a look please.? -->

(js->clj (.getElementsByTagName js/document "tr") :keywordize-keys true)
it is retuns to me: "[Object HTMLCollection]" You can see my table here: https://gist.github.com/Bariscanates404/4992ef969eccba965ec348838371bf0b

p-himik12:10:00

js->clj only works with plain objects and some specific types. The type returned by getElementsByTagName is HTMLCollection and it's not handled by js->clj.

p-himik12:10:11

What exactly do you want to get?

Can12:10:50

I wanted to write a function which is going to sort my table by cell

Can12:10:11

But stuck at first line 🙂

p-himik12:10:11

Oh, don't manipulate the DOM directly then. I'm not sure what the dom alias is in your code, but it's much better to handle such things at the level of the UI library.

Can12:10:33

I using Hyperfiddle Electric, Which is why things getting much harder than normal, I can find some examples of standard Clojurescript usage but sometimes I am not able to use them in Electric.

p-himik12:10:36

E.g. in Reagent your data drives the UI. So in order to reorder a table you'd just reorder the data.

Can12:10:26

Nice idea, I can try to do that in Electric. My table data comes from a query, if I sort query maybe I can able to sort table.

p-himik12:10:12

Well, then you'd have to re-request the data. If it'll be the same data just in different order, I'd reorder it with some CLJS code without issuing a new request. No clue whether it's possible in Electric since I don't use it.

grav16:10:56

I'd say one of the value propositions of Electric is that you don't need to think about client versus server state. So I would expect implementing your query with a kind of "sorting parameter" should do the trick 🙂 Sorting client-side would be an optimization, which I'd avoid unless the query was expensive

âś… 1
grav16:10:31

Could be interesting to post this in #hyperfiddle and see what peoples' thoughts are

Can20:10:57

Thanks for sharing your time, I am going to try @U2FRKM4TW and @U052XLL3A yours advices. 🙂

đź‘Ť 1
quoll17:10:19

Sorry to ask such a simple question, but I figured it might save time asking here rather than testing with trial and error… Does definline get treated similarly to a macro in ClojureScript? i.e. do I need to put it in a separate file?

🙏 1
dnolen17:10:42

there is no definline in CLJS, we do have “inlining” macros, i.e. that’s how we generate primitive + when you use cljs.core/+

dnolen18:10:08

this works because there are two namespaces, one for macros, one for functions

dnolen18:10:38

because macros are compile time only so can’t conflict really w/ runtime stuff, so they can share names

quoll19:10:34

This is great, thank you!