Git Product home page Git Product logo

Comments (5)

shaunlebron avatar shaunlebron commented on June 7, 2024

Here’s an OrgPad for tracing this: https://orgpad.com/s/n3W2BotZfA_?open=all

CleanShot 2022-08-24 at 16 24 12@2x

from reagent.

mike-thompson-day8 avatar mike-thompson-day8 commented on June 7, 2024

@shaunlebron
I'm struggling to remember the flow of control right now (I knew it well in 2015!) , but from memory, I feel this is a key line of code:

https://github.com/reagent-project/reagent/blob/master/src/reagent/ratom.cljs#L466

Note the = check.

Given your investigation (it looks like you have your head wrapped around the code) does that make any sense?

from reagent.

mike-thompson-day8 avatar mike-thompson-day8 commented on June 7, 2024

I wrote the docs which you are questioning, so I'm feeling like I should be able to answer you definitively, BUT it is all a long time ago ... so all I can add for the moment is a further fact I can remember ... there was a time when identical? was used but that lead to programmers being "surprised", so we switched to = (which actually does an identical? check internally anyway but moves on to deeper, recursive comparison on false)

This breaking change is documented in the change log for v6.0.0. Note the line:

Reactions now only trigger updates of dependent components if their value change, as reported by = (previously, identical? was used).

from reagent.

Deraen avatar Deraen commented on June 7, 2024

There is also = check on Reaction _run method: https://github.com/reagent-project/reagent/blob/master/src/reagent/ratom.cljs#L436 This is called either directly from handle-change or through the queue.

But yes, looks like if the component is directly dereffing a Ratom, the component will be rendered even if reset/swap doesn't change the value.

Component dereffing a RAtom:
ratom reset/swap -> notify the render reaction -> queue-render

Component dereffing a Reaction depending on a RAtom:
ratom reset/swap -> notify reaction -> run -> IF result changed -> notify the render reaction -> queue-render

from reagent.

shaunlebron avatar shaunlebron commented on June 7, 2024

@mike-thompson-day8 Not a bad memory for seven years ago! I currently understand only how ratoms trigger a specific kind of reaction— the one created for a component’s render function. Looking at your reference, I think that = is related to a lazily evaluated reaction (?), wherein a Deref notifies its watchers, but only if it has changed in value.

I don’t think the reaction created purely for a component’s render function is ever deref’d like that. The only path to its auto-run function (i.e. batch/queue-render) is in handle-change, which I think only fires in response to:

  • a dependent ratom being reset to a non-identical? value or,
  • a dependent reaction being reset to a non-= value

NEW EDIT FOR THE DOCS?
“The ‘changed?’ semantics that make a component re-render are: identical? for ratoms, and = for reactions.

I don’t know yet if this is accurate or desirable, but that’s how I currently understand it.

@Deraen Thank you, I think you summarized it well, except for the last “reaction reset” is supposed to be “ratom reset”?— since the atom triggers the first reaction, which triggers the render reaction.

from reagent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.