Fork me on GitHub
#clojurescript
<
2020-09-27
>
ozzloy04:09:07

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

ozzloy04:09:07

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-himik12:09:21

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.

ozzloy22:09:46

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

p-himik05:09:12

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.

ozzloy04:09:52

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-himik07:09:09

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

ozzloy00:09:29

that seems worse

p-himik05:09:13

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-himik05:09:51

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

ozzloy04:09:29

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

ozzloy04:09:48

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

schmee23:09:00

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

phronmophobic23:09:49

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

schmee23:09:36

looks cool, thanks for sharing!

schmee23:09:07

@U7RJTCH6J 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

šŸ‘€ 3
phronmophobic23:09:36

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

phronmophobic23:09:02

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

victorb08:09:19

@U7RJTCH6J adding reader functions is easy!

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

šŸ‘ 3
victorb08:09:47

(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)

souenzzo15:09:09

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

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

phronmophobic16:09:26

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