GithubHelp home page GithubHelp logo

Comments (2)

justin-schroeder avatar justin-schroeder commented on May 5, 2024 5

Good question. However, the halting problem need not apply since we actually run the codeΒ β€” there is no static analysis or deterministic algorithm. Conceptually this is not that complicated (it is also, by the way, how signals work and how vue works β€”Β it is a clever trick though), in your example:

function total () {
  if (data.logTotal == ifMathTheoremIsTrue()) {
    console.log(`Total: ${data.price * data.quantity}`);
  }
}

we start by running the function and observing which properties are touched. Given a state of:

data = {
  logTotal: 1,
  price: 1,
  quantity: 10
}

And given that ifMathTheoremIsTrue() has no dependencies on data and returns 1, then the dependencies of the first run are:

data.logTotal, data.price, data.quantity

The only time we need to re-run this function are if any of those dependencies are changed. Lets say logTotal now changes to 1. We re-run the function and the dependencies are:

data.logTotal

we can now diff the dependency results:

| data.logTotal, data.price, data.quantity
|---------------------------------------
| data.logTotal
|---------------------------------------
call $off on data.price, data.quantity

Hope that helps clear up how this works πŸ‘

from arrow-js.

Clonkex avatar Clonkex commented on May 5, 2024

Ah, that's very helpful! I also had this question. When I first read the documentation it seemed like magic, but now I see it just tracks the dependencies from each run. If logTotal changes to false, the function will run again and now it will know that price and quantity are no longer relevant. If logTotal changes back to true, it will know to start tracking price and quantity again. Very clever indeed!

from arrow-js.

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.