Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Since components have callbacks as arguments, do they always rerender? #146

Closed
UrKr opened this issue Apr 9, 2017 · 5 comments
Closed

Comments

@UrKr
Copy link

UrKr commented Apr 9, 2017

Since reagent using identical? to see if it has to rerender a component, does the fact that recom components take callbacks as arguments mean that this optimization can never work, even if all the other props are identical?

If this is true, I suppose a solution is to pass in globally defined functions. That is a bit inconvenient however, because you can't close over local variables.

@mike-thompson-day8
Copy link
Contributor

If you create the callback in-line, then it will not test identical? to previously. But if you create a Form-2 reagent function, and create the callback in an outer function for use within the renderer, then it will test identical? each time.

@pesterhazy
Copy link

Note that if you re-create the same anon fn twice, not only will it be not identical? but also not =:

> (def x (atom nil))
> (defn foo [] (let [f (fn [] (println "foo"))] (prn (= @x f)) (reset! x f) nil))
> (foo)
false
> (foo)
false

@pesterhazy
Copy link

I've created a live demo of @UrKr's difficulty: https://gist.github.com/pesterhazy/36b56d1bd8b424abef81adbb5a392d93 (scroll down for the link)

@mike-thompson-day8
Copy link
Contributor

@UrKr
Copy link
Author

UrKr commented Apr 9, 2017

@mike-thompson-day8
Yes. Thank you both for the quick replies!

@day8 day8 locked and limited conversation to collaborators Mar 29, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants