dphfox / Fusion

A modern reactive UI library, built specifically for Roblox and Luau.
https://elttob.uk/Fusion/
MIT License
530 stars 91 forks source link

Lazy evaluation / hybrid push-pull execution model #323

Open dphfox opened 2 months ago

dphfox commented 2 months ago

Closes #144. Implements Reactively's hybrid push-pull algorithm for Fusion's graph objects, as described on Technical Fluff and as described by Reactively's author.

dphfox commented 2 months ago

Closes #303.

dphfox commented 2 months ago

Diverged a bit from the algorithm as written. Now, it only paints validity/invalidity, as well as storing a change time for avoiding computations for non-meaningful changes.

dphfox commented 2 months ago

New algorithm documented on Technical Fluff: https://fluff.blog/2024/04/16/monotonic-painting.html

dphfox commented 2 months ago

The new execution model exposed a shortcoming of the existing For internals, where there was an infinite loop between pair processors and the main object.

So I've been mulling over the problem for a few days, and I realised that I probably should have a better mental model of what should be going on inside a For object.

This is the structure I landed on:

image

dphfox commented 1 month ago

image

It's been so long.

dphfox commented 1 month ago

Tweens are now up and running, and alongside them, there is a bevy of new internal utilities for managing timing based objects. This will make some other things much easier to implement in the future!

The system is designed to work with custom time sources too, so it should be flexible.

dphfox commented 2 weeks ago

So I've been playing around with the bugs in this branch for a short while this evening. As best as I can tell, this branch messes up the lifetimes of something somehow - I suspect something that promises to create a new inner scope for a callback is instead returning an outer scope somewhere. Just a hunch.

dphfox commented 2 weeks ago

Fixed some of the major lifetime issues - after a lot of diagnosis, it turns out the issue was that New calls were being cached, which is incorrect because scope upvalues were being used in the cached functions.

dphfox commented 2 weeks ago

image

Ported the Word Game example just fine... so looks like I'll need a more complex example to figure out what's going wrong.

dphfox commented 1 week ago

if you create a tween with a repeat count of -1 then the first time its evaluated self._activeFrom is nil so it sets self._activeElapsed to self._activeDuration (which is infinity) which then causes getTweenRatio to return nan so it gives a warning

Will need to fix this

dphfox commented 1 week ago

Will also need to fix the infinite loop check in change to allow for cyclic changes if they happen through a dependency that doesn't meaningfully change (likely, this just means allowing cycles in change).