reagent

A minimalistic ClojureScript interface to React.js http://reagent-project.github.io/
EmmanuelOga 2020-07-03T05:10:21.311100Z

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 McCormick 2020-07-03T05:20:58.312600Z

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.

EmmanuelOga 2020-07-03T05:29:15.313500Z

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

EmmanuelOga 2020-07-03T05:30:35.313700Z

also found this https://github.com/borkdude/re-find.web/blob/master/src/re_find/web.cljs#L371-L410

EmmanuelOga 2020-07-03T05:30:54.314300Z

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

Chris McCormick 2020-07-03T06:18:18.315Z

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

Chris McCormick 2020-07-03T06:18:33.315500Z

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

Chris McCormick 2020-07-03T06:19:13.316200Z

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

EmmanuelOga 2020-07-03T08:12:02.318Z

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?

EmmanuelOga 2020-07-03T08:14:08.318600Z

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

p-himik 2020-07-03T08:52:07.318700Z

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

p-himik 2020-07-03T08:52:55.318900Z

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

EmmanuelOga 2020-07-03T09:01:31.319100Z

yeah if I remove console logs nothing renders

EmmanuelOga 2020-07-03T09:01:52.319300Z

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

p-himik 2020-07-03T09:03:16.319500Z

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.

EmmanuelOga 2020-07-03T09:04:07.319700Z

right...

EmmanuelOga 2020-07-03T09:04:24.319900Z

is it too dirty to manually call render sometimes?

EmmanuelOga 2020-07-03T09:04:49.320100Z

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

p-himik 2020-07-03T09:05:23.320300Z

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

EmmanuelOga 2020-07-03T09:05:30.320500Z

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...

gleisonsilva 2020-07-03T17:32:13.322500Z

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-himik 2020-07-03T17:33:42.322600Z

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

1👍
p-himik 2020-07-03T17:34:18.322900Z

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

gleisonsilva 2020-07-03T17:38:52.323100Z

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...

gleisonsilva 2020-07-03T17:45:40.323400Z

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

2020-07-03T19:05:29.323600Z

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.