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 🙂
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.
thx Chris, though I don't quite get how / when do you pickup the text value from the editor
also found this https://github.com/borkdude/re-find.web/blob/master/src/re_find/web.cljs#L371-L410
I wonder if you may be leaking CM instances if you don't call .toTextarea to "kill" them
hm could be. i should double check that. i think when the dom element is destroyed the CM instance will be garbage collected.
the text value is being set at instantiation time: :value (or src "")
ah yes and it's never used until the user hits ctrl-S when it's pulled directly from CodeMirror
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?
(i'm not derefencing any atoms in the logging, just printing the parameters to the function that calls create-class)
Does it stop rendering when you remove console.log
again?
Also, "just printing the parameters" may do other things. Like realizing lazy collections.
yeah if I remove console logs nothing renders
if I keep the console logs but close the console, nothing renders
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.
right...
is it too dirty to manually call render sometimes?
if I call render in the right place it renders everything as expected
Absolutely, don't do that. You have some underlying problem, and anything but fixing it will almost definitely bring some pain later on.
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...
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?
There are cursors, reactions, and tracks. Maybe some other things. Some info here: https://reagent-project.github.io/news/news060-alpha.html
If you tend to put everything in a single atom, maybe #re-frame (built on top of Reagent) would be useful for you.
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...
But, for this case in particular, r/cursor has make it. Tks, @p-himik
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.