Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does re-rendering work? #224

Closed
ccorcos opened this issue Mar 31, 2016 · 4 comments
Closed

How does re-rendering work? #224

ccorcos opened this issue Mar 31, 2016 · 4 comments

Comments

@ccorcos
Copy link

ccorcos commented Mar 31, 2016

What does this mean?

Any component that uses an atom is automagically re-rendered when its value changes.

https://reagent-project.github.io/

How does a function know to re-render?

@zjhmale
Copy link

zjhmale commented Mar 31, 2016

@ccorcos just like the example shows that

(defn counting-component []
  [:div
   "The atom " [:code "click-count"] " has value: "
   @click-count ". "
   [:input {:type "button" :value "Click me!"
            :on-click #(swap! click-count inc)}]])

the div display the internal value of the atom click-count and there is a button down below to change the value of the atom. everytime you click the button to inc the value of click-count, the counting-component component will be automagically re-rendered.

@ccorcos
Copy link
Author

ccorcos commented Mar 31, 2016

I get that it does, but my question is how? How does the function know it
needs to be re-run? This isn't something that's built into clojure is it?
On Wed, Mar 30, 2016 at 20:54 (λ . λ) notifications@github.com wrote:

@ccorcos https://github.com/ccorcos just like the example shows that

(defn counting-component []
[:div
"The atom " [:code "click-count"] " has value: "
@click-count ". "
[:input {:type "button" :value "Click me!"
:on-click #(swap! click-count inc)}]])

the div display the internal value of the atom click-count and there is a
button down below to change the value of the atom. everytime you click the
button to inc the value of click-count, the counting-component component
will be automagically re-rendered.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#224 (comment)

@mike-thompson-day8
Copy link
Member

Github issues for Reagent are for bug reports and feature requests. Support requests and usage questions should go to the Clojure Slack channel, the ClojureScript mailing list, or the Reagent mailing list.

Your questions above will be answered if you read these 3 pages:

  1. https://github.com/Day8/re-frame/wiki/Creating%20Reagent%20Components
  2. https://github.com/Day8/re-frame/wiki/Using-%5B%5D-instead-of-%28%29
  3. https://github.com/Day8/re-frame/wiki/When-do-components-update%3F

@ludbek
Copy link

ludbek commented Oct 11, 2020

@ccorcos
To understand how Reagent knows which component to re render when a value changes, I think you should look at following places.

  1. https://github.com/lynaghk/reflex/blob/master/src/cljs/reflex/core.cljs#L18
  2. https://repl.it/@ludbek/HighFractalRefactoring#main.clj

My guess is, when Reagent renders a component it keeps track of the reagent/atoms that are being dereferenced by the component. The answer to how Reagent knows which atoms are being dereferenced, see how the code in the first link extends atom to notify when it is dereferenced.

The code in the 2nd link is trying to mimic how https://github.com/mobxjs/mobx works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants