Introduce Signal Effects #945
Labels
a-core
Relates to the core package
b-enhancement
New feature or request
c-accepted
The issue is ready to be worked on
Description
The value of a signal is calculated only when something requests it by invoking it.
This works great with the current architecture because, during rendering, all signals necessary to display the animation will be invoked and therefore updated. It also automatically skips expensive calculations like matrix propagation (calculating the global matrix of a node) unless something actually needs it.
This approach, however, makes it impossible to "observe" for changes in signals. To do that, one would need to write a loop that accesses the signal in each frame. There should be a built-in, simpler way to achieve this.
Proposed solution
Most UI libraries have a concept of
effect
that does exactly this. While their signal implementation is usually different than ours (relying on registration rather than laziness), we should be able to replicate a familiar API.This is when signals in MC are computed:
And here's how the
createEffect
function would work:Additionally it would be useful to have a variant of effect that is deferred until the end of the frame:
The text was updated successfully, but these errors were encountered: