Skip to content

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

Closed

Description

@UrKr

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.

Activity

  1. mike-thompson-day8 commented on Apr 9, 2017

    @mike-thompson-day8
    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.

  2. pesterhazy commented on Apr 9, 2017

    @pesterhazy

    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
    
  3. pesterhazy commented on Apr 9, 2017

    @pesterhazy

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

  4. mike-thompson-day8 commented on Apr 9, 2017

    @mike-thompson-day8
    Contributor
  5. UrKr commented on Apr 9, 2017

    @UrKr
    Author

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

  6. locked and limited conversation to collaborators on Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions