Bi-directional Data Flow
By default, Signals are uni-directional but can be used in a bi-directional way if needed.
Consider the following example:
In this example, a
and b
are two signals that are dependent on each other. When a
changes, b
should update, and when b
changes, a
should update.
This however can lead to an infinite loop and will throw a EffectCycleDetectionError
. To prevent this, you can use the untracked
method to prevent the signal from updating itself.
This will prevent the infinite loop and allow the signals to update each other without causing an error.
Signals are synchronous and will update immediately when the value is set. This means that the value will be updated before the next effect is run. This allows you to create bi-directional data flow in a predictable way.