Fusion icon indicating copy to clipboard operation
Fusion copied to clipboard

Lock state objects from updating multiple times simultaneously

Open dphfox opened this issue 1 year ago • 0 comments

Right now, it's possible for updateAll() to spawn more calls to updateAll() from within itself. This is often fine (e.g. updating a disconnected subgraph instantiated inside of a Computed) but sometimes it can be the result of a reactive graph modifying itself during an update. Code acting like this is considered to be poorly behaved and non-idiomatic because it can easily lead to infinite recursion, and often indicates poor programming practice.

If it is possible to do so without hurting performance or breaking correct programs, it would be a good idea for updateAll() to error if it encounters a state object which is already in the process of updating.

This change implies that state objects that run code with side-effects such as Observer must defer those calls until later on in the invocation step, so as to avoid all current update processes.

dphfox avatar Jan 21 '24 07:01 dphfox