Fork me on GitHub
#reagent
<
2020-07-03
>
EmmanuelOga05:07:21

can anybody recommend some wrapper for reagent+codemirror? I was trying to roll my own out of https://gist.github.com/jaredly/3d227a0275a66dcfb1f3 but I'm getting some strange behaviors... would rather not skin this yak right now 🙂

Chris McCormick05:07:58

not sure if it will help but here's what i did recently when integrating codemirror with reagent: https://github.com/chr15m/slingcode/blob/master/src/slingcode/main.cljs#L443-L454 the tl;dr is i don't try to manage it much, just create an instance and attach a reference to the dom. if the reference is still on the dom element during re-render then it just uses the existing CM instance rather than creating a new one. a bit hacky with aset etc. but works well.

EmmanuelOga05:07:15

thx Chris, though I don't quite get how / when do you pickup the text value from the editor

EmmanuelOga05:07:54

I wonder if you may be leaking CM instances if you don't call .toTextarea to "kill" them

Chris McCormick06:07:18

hm could be. i should double check that. i think when the dom element is destroyed the CM instance will be garbage collected.

Chris McCormick06:07:33

the text value is being set at instantiation time: :value (or src "")

Chris McCormick06:07:13

ah yes and it's never used until the user hits ctrl-S when it's pulled directly from CodeMirror

EmmanuelOga08:07:02

what could be the cause of a component created with reagent.core/create-class that doesn't render, but if I add a console.log in :component-did-mount, it does?

EmmanuelOga08:07:08

(i'm not derefencing any atoms in the logging, just printing the parameters to the function that calls create-class)

p-himik08:07:07

Does it stop rendering when you remove console.log again?

p-himik08:07:55

Also, "just printing the parameters" may do other things. Like realizing lazy collections.

EmmanuelOga09:07:31

yeah if I remove console logs nothing renders

EmmanuelOga09:07:52

if I keep the console logs but close the console, nothing renders

p-himik09:07:16

Most definitely some lazy sequence or something else that gets evaluated when printed out. You have to inspect the data carefully. Hard to suggest anything else without the code.

EmmanuelOga09:07:24

is it too dirty to manually call render sometimes?

EmmanuelOga09:07:49

if I call render in the right place it renders everything as expected

p-himik09:07:23

Absolutely, don't do that. You have some underlying problem, and anything but fixing it will almost definitely bring some pain later on.

EmmanuelOga09:07:30

the thing about those automatic renders when derefing is that it builds this invisible dependency graph I need to recreate in my head by reading the code...

gleisonsilva17:07:13

Hello, guys! May you can help me... Given that I've a Reagent Atom "app-state" with many nested maps, how to avoid a re-rendering of a component where the related map has not changed?

p-himik17:07:42

There are cursors, reactions, and tracks. Maybe some other things. Some info here: https://reagent-project.github.io/news/news060-alpha.html

👍 3
p-himik17:07:18

If you tend to put everything in a single atom, maybe #re-frame (built on top of Reagent) would be useful for you.

gleisonsilva17:07:52

I have an old dilema about that... because I've a lot of small independent apps (SPA, dashboard like), so I'm always in doubt if re-frame would be "too much" for each of these individual little SPA...

gleisonsilva17:07:40

But, for this case in particular, r/cursor has make it. Tks, @U2FRKM4TW

Pavel Klavík19:07:29

I don't think overhead of Re-frame is very big. There is little bit of learning curve there, but it does not blow the code size that much.