Fork me on GitHub
#reagent
<
2015-08-02
>
danielcompton03:08:18

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

danielcompton03:08:38

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

darwin08:08:58

@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

darwin08:08:59

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

darwin08:08:08

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

darwin08:08:58

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

ulsa08:08:16

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.

ulsa08:08:41

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

michaelr13:08:25

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

michaelr13:08:47

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

mikethompson13:08:26

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

michaelr13:08:30

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

mikethompson13:08:39

You don't have to

mikethompson13:08:10

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

mikethompson13:08:13

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

michaelr13:08:13

i'll take a closer look at re-frame

michaelr13:08:41

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

michaelr13:08:56

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

mikethompson13:08:20

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

mikethompson13:08:02

But, its my understanding that they work fine.

pupeno14:08:18

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?

michaelr14:08:57

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

pupeno14:08:53

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.

michaelr14:08:24

sorry not aware of such framework for clojurescript

pupeno14:08:19

Yeah, it seems there are none 😞

michaelr14:08:24

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

pupeno14:08:13

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

darwin14:08:16

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.

michaelr14:08:06

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

darwin14:08:02

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

michaelr14:08:52

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

darwin14:08:12

I would suggest profiling it under Chrome devtools

michaelr14:08:01

using the profiler?

darwin14:08:37

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

darwin14:08:57

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

michaelr14:08:08

i'll give it a shot

michaelr15:08:36

darwin: thanks, it helped simple_smile

gadfly36116:08:14

@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 :)

michaelr16:08:11

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

gadfly36116:08:36

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.

michaelr16:08:13

what's that bug?

michaelr16:08:50

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

michaelr16:08:38

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

gadfly36116:08:52

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

gadfly36116:08:50

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

michaelr16:08:09

maybe this was one of the strange problems I experienced

gadfly36116:08:11

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

lucien.knechtli20:08:06

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

gregg22:08:22

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: https://github.com/Day8/re-com/blob/master/project.clj#L37-L48. 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.

lucien.knechtli22:08:29

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