clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
ozzloy 2020-09-27T04:42:19.096200Z

@lilactown thanks!

ozzloy 2020-09-27T04:44:07.097900Z

when do you deref? do you wait until you absolutely need to, or do you do it as soon as you possibly can?

ozzloy 2020-09-27T04:45:07.098900Z

initially i was derefing as soon as i could, but then i found i was losing track of when i had an atom coming into a function, and when i had its contents

p-himik 2020-09-27T12:50:21.103200Z

Usually you want to deref as close to the actual usage as possible to avoid any updates of the parent components. Note that if your ratom is actually a re-frame sub, then you should not deref it in a callback or event handler function. You have to deref it exactly inside the body of the component. Otherwise, there will be a memory leak.

ozzloy 2020-09-27T22:26:46.104600Z

oh wow, thanks. so dereferencing to get the value also marks a function for update inspection?

p-himik 2020-09-28T05:46:12.109Z

Not just any function but a view component, yes. And you also pass that value down a chain of components - they will all be updated if the value changes.

ozzloy 2020-10-02T01:25:18.252800Z

thanks

ozzloy 2020-09-27T04:46:52.100300Z

i'm considering using 2 identifiers, like maybe state-atom and state, but that ... idk, seems kinda meh. i feel like there's probably a good heuristic i'm missing.

p-himik 2020-09-27T07:23:09.101400Z

re-com has a deref-or-value function for that that's just used on almost every input value.

ozzloy 2020-09-28T00:52:29.108500Z

that seems worse

p-himik 2020-09-28T05:47:13.109200Z

I disagree - when you only read from atoms, it's nice if you don't even need to remember if you have to pass a ratom or a value somewhere.

p-himik 2020-09-28T05:47:51.109400Z

re-com splits reading and writing - usually the corresponding arguments are :model and :on-change.

ozzloy 2020-10-02T01:36:47.253400Z

thanks!

ozzloy 2020-09-27T04:47:29.101Z

the code could also just leave the atom alone until its actually grabbing something out of the map inside the atom

ozzloy 2020-09-27T04:47:48.101300Z

"you" as in the whole channel, not just lilactown

schmee 2020-09-27T23:36:00.105900Z

does anyone know of a way to display EDN data with folding, max length for arrays etc in the browser? Iā€™m using reagent

victorb 2020-09-28T08:40:19.113400Z

@smith.adriane adding reader functions is easy!

(read-string {:readers {'crux/id identity}}
               "{:id #crux/id \"hello\"}")

šŸ‘ 1
victorb 2020-09-28T08:40:47.113600Z

(obviously you might want to change identity to something proper, if you expect it to actually do something more useful than just returning whatever it is)

souenzzo 2020-09-29T15:19:09.167700Z

btw for "generic EDN" may be a good idea use :default

(clojure.edn/read-string 
  {:default tagged-literal}
  "#any :litteral")

phronmophobic 2020-09-29T16:50:26.168500Z

cool. the demo no longer chokes on tagged literals and will print parse errors should they occur. thanks for the tips!

phronmophobic 2020-09-27T23:37:49.106Z

how large is your edn data? I've been working on https://blog.phronemophobic.com/treemap/treemaps-are-awesome.html for medium to largish data

schmee 2020-09-27T23:41:36.106200Z

looks cool, thanks for sharing!

schmee 2020-09-27T23:46:07.107400Z

@smith.adriane when I try to load some test edn data I get Uncaught SyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data

šŸ‘€ 1
phronmophobic 2020-09-27T23:52:36.108100Z

ok, I don't have any error printing on the deployed demo, but i'm getting:

No reader function for tag object
when I try it locally

phronmophobic 2020-09-27T23:57:02.108300Z

it works when I get rid of the #object tagged objects