Fork me on GitHub

Can someone explain when and why to use the auto-run parameter in reaction?


Alternatively, when and why should you use run! instead of reaction?


@danielcompton: I might be wrong, but I use run! for code which should run reactively and is outside of reagent component, usually top-level-form code which has some derefs and should be run in reaction to changes in those derefs


auto-run is related, when you create reactive piece of code (for example with run!), you want it to run once when code is executed, without it, the reactions inside would not be created/tracked, it would be just a dead piece of code


a different view: reaction is a special function which “depends” on other reactions, this gives you direct acyclic graph of reactions, you want auto-run the reactions which are at the top (they don’t depend on any other reaction, just ratoms), normally this is hidden from you, because you are building inner reactions and the top reaction is created by reagent from components


but I might be wrong, reading reagent source is quite challenging


Finally had the chance to test what @antishok suggested, and indeed run! works where reaction didn't. It's apparently perfect for my use case, where I want to call very side-effecty revalidate on some other field as a response to a ratom changing.


I'm so happy now. Thank you everyone that were involved.


working on a reagent project now and worked on Om projects before, so cursors were a natural choice


now, I wonder if i should not choose cursors in reagent


If you reject cursors (good decision!), then an FRP approach like re-frame or zelkova might be a good choice. (I am the author of the former, and so hopelessly biased :-))


i'm reluctant to give up on the single atom state thing


You don't have to


Both re-frame and zelkova encourge a single-source-of-truth


Remember that Hoplon was doing single-source-of-truth well before OM showed up (they call them stem cells)


i'll take a closer look at re-frame


right now what bothers me the most is that cursors don't seem to work so well in reagent


not sure if i'm doing something wrong or a bug in my code


I'm not the best guy to ask about Cursors. I'll hand over to others.


But, its my understanding that they work fine.


I just spend a couple of hours looking at reframe and it seems it completely ignores URLs, that is, as the app state changes it doesn’t update the URL and vice-versa. Is that correct?


pupeno: i think it's not in the scope of what re-frame does/is. check secretary


michaelr: I know about secretary and bidi and silk… they are only part of the picture, the wiring between those and the app state is far from trivial hence I was looking for a framework that does it, like EmberJS does.


sorry not aware of such framework for clojurescript


Yeah, it seems there are none 😞


in the general picture of an SPA application updating the browser history is just a small piece, once you get it figured out it mostly goes out of your way


I have no idea how big or small it is, I never built one (and generally, I try to build as little as possible, that is, reuse as much as possible).


I personally like separation of concerns in this case, I want to be able to combine different libraries depending on app's current needs. Building one monolithic framework trying to solve everything is probably not justified. ClojureScript community is pretty small. But we will see in the future, maybe there will be big enough demand for ClojureScript’s Angulars, Embers or Meteors.


anyone knows why would there be a significant render delay after a state change?


@michaelr: any idea how many watchers do you have on your root ratom?


just a few direct watchers but the rest are watching cursors derived from it


I would suggest profiling it under Chrome devtools


using the profiler?


yes, newly it is now also integrated with timeline view, I forgot the name of the graph, but you can see colored functions as bars and depth of calls


it is pretty easy to spot performance bottlenecks in your code this way


i'll give it a shot


darwin: thanks, it helped simple_smile


@michaelr I use cursors in production and have had no problems with them. That said, I still prefer the re-frame pattern and recommend that approach if you are starting a new project :)


i'm already a bit in so changing will cost some..


Only advice is if you do go with cursors, id recommend using a 100% cursor approach to access your data..instead of mixing cursors and also accessing your single atom directly. There is a bug that exists currently, but should be fixed in next reagent release.


what's that bug?


actually I'm doing most updates by dispatching an event and then updating the single atom simple_smile


so if I'm using SNAPSHOT I should be safe?


The title is misleading. It says on-blur, but its just a bug with cursors (nothing to do with on blur)


Im not certain about whether or not you will be safe. I am not sure Dan has added his fix yet for that.


maybe this was one of the strange problems I experienced


Yeah, it's possible - this definitely bit me before


uhg... i'm an idiot. I've spent the last 5 hours trying to figure out why I can't get re-com to work properly, and only just thought it would be a great idea to look at the re-com css file I have in my assets folder. First line in the file: <!DOCTYPE html> I downloaded the actual github page, and not the css file...


Yeah @lucien.knechtli, that wouldn't work, but don't feel bad. I'm sure you're not the first one to do that. It would be great if, when you add a library dependency to your project, any additional resources included in that library could automatically be directed to the right place in your project. We looked at various way to achieve this a while back but couldn't find a good one. The closest we got was lein-unpack-resources but this didn’t allow you to specify WHERE to put them. You can see our thoughts on the matter here: We have never got back to solving this one but it IS on the list. Would be grateful for any good ideas for achieving this.


I'll put some thought into it and tell you if I come up with something