Comments (2)
The new execution model should help solve for this. Invalidation is a completely controlled process; no state objects are invoked during that stage. Eager objects are only revalidated after all invalidation is complete.
Revalidation is a little more interesting. It's conceivable that, during revalidation, an object can cause state objects to become invalidated. In particular, an object might invalidate itself, or it might be transitively invalidated if it invalidates a state object it transitively depends on.
For example:
local foo = scope:Value(2)
local bar = scope:Computed(function(use)
return use(foo) * 2
end)
-- imagine this ran synchronously
local baz = scope:Observer(bar):onBind(function()
foo:set(peek(foo) + 1)
end)
The specific question we should ask here is: what should happen when a state object becomes invalid during revalidation?. Seemingly, the answer would be "revalidate itself again", but this could easily lead to infinite loops. Really, what we're dealing with here is a "hidden cycle" in the reactive graph.
So, I would propose we add an error for this case:
Detected an infinite loop. Consider adding an explicit breakpoint to your code to prevent a cyclic dependency.
Notably, this can happen during invalidation too, if the graph has an explicitly-modelled cycle in it. However, we should be careful - unlike revalidation, objects being invalid is not itself an invalid state for the invalidation process, because objects can be invalidated multiple times by design. We'd likely need to track state inside the invalidation process to catch this.
However - if you noticed the 'synchronous' stipulation above - this would only really catch errors in the implementations of state objects. We'd need something more sophisticated to solve for user-introduced loops from asynchronous sources like Observers.
Overall, I think that tracking infinite loops during invalidation is a bit of a distraction, since the process can be implemented in a way that trivially supports cyclic graphs by merely terminating when encountering an already-transitively-invalidated graph object, which the invalidation process is marking out anyway. So revalidation is the only part I think we need to care about, which is good because it makes all the scary questions go away.
from fusion.
Solved in #323
from fusion.
Related Issues (20)
- Fusion.Children should parent things in batching order HOT 7
- Allow T everywhere we publicly accept StateObject<T> HOT 1
- Dissolve state objects that don't deal with state HOT 4
- Rename CanBeState<T> to be more concise HOT 7
- Introduce a more efficient connector between state and data model properties
- Heuristic memoisation for state objects HOT 1
- Add debugging protocol for non-invasive inspection
- Change design of Observer to allow pooling listeners HOT 1
- Reuse scopes from primitive computed objects HOT 3
- Test what an ideal scope pool size is HOT 1
- Integrate under-documented APIs into tutorials
- Explore safer interpretations of `deriveScope` HOT 1
- Spring setters don't work immediately after construction
- Memoise special key generation functions
- Poor typechecking for use functions with UsedAs<T>
- Derive scopes with additional methods HOT 2
- Standard set of reactive graph shapes for testing HOT 1
- Write tutorial for `Safe` expressions
- Broken default props link (still uses .lua)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fusion.