On Saturday, March 14, 2015 at 2:52:45 PM UTC+11, AndyR wrote: > On Friday, March 6, 2015 at 11:28:59 PM UTC-5, Mike Thompson wrote: > > re-frame is a pattern for writing SPAs, using Reagent. > > https://github.com/Day8/re-frame > > [...] > > - pushes Reagent's FRP capabilities (via use of reaction) > "The magic thing about a reaction is that the computation it wraps will be > automatically re-run whenever 'its inputs' change, producing a new output > (return) value." > > What if I have a heavy computation in there and I don't actually display that > value right now in my app. Will it still be computed? Or is that something to > take special care of? So only lightweight computations in reactions? > > If that's the case, would it make sense to also create a lazy reaction that > only get's realized/computed when it's deref'ed? >
reactions are only ever used in subscriptions, which are the "query layer" of re-frame. They do not create new data. Instead, their job is to reactively supply "views" (queries) across existing data (in "app-db", the single source of truth ratom). The CPU intensive calculation of new values happen in event handlers, using this sort of a pattern: https://github.com/Day8/re-frame/wiki/Solve-the-CPU-hog-problem Clarification: sometimes a query delivers "derived data" (a kind of materialised view) which DOES involves CPU intensive work. For example, a query might involve sorting a collection of items and finding the top 20 items (so they can be displayed in the view). That's something that would happen inside a reaction. But in this case there's no new data being created (the collection of items doesn't change), just a derived version of that data is being created for view purposes. Regarding lazy calculation: you can certainly do that. You'd wait for the right trigger to perform the calculation - but the calculation would happen in an event handler. Only event handlers can "update" app-db (providing new data to the application). -- Mike -- Mike -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojurescript+unsubscr...@googlegroups.com. To post to this group, send email to clojurescript@googlegroups.com. Visit this group at http://groups.google.com/group/clojurescript.