However, it seems that effects that observe computed signals fire when the underlying signals change, even if the computed value stays the same, so the following code
const a = signal(0);
const b = computed(() => 0 * a.value); // always returns zero
effect(() => console.log("b updated:", b.value));
a.value = 1;
a.value = 1;
Prints this, with one line per unique value of a, even though the values of b are the same every time:
b updated: 0
b updated: 0
I was wondering – is this intentional? I could potentially imagine use cases for it, but reading the docs I did not see this difference discussed and wanted to check.
Thanks for your work on Signals, by the way – I came across them via Ryan Carniato and it seems like a great library!
Thanks for checking out signals! No, this is not intentional and a regression when we rewrote the internals recently. The fix has been merged #205 and we'll cut a new release shortly.
Hi, I'm playing around with Preact Signals and have a question about an interesting behavior I noticed.
The behavior is a difference between
signal
andcomputed
.Effects that observe
signal
s only fire when the signals they observe change in value, so the following code:prints this, with one line per unique value of
a
:However, it seems that effects that observe computed signals fire when the underlying signals change, even if the computed value stays the same, so the following code
Prints this, with one line per unique value of
a
, even though the values ofb
are the same every time:I was wondering – is this intentional? I could potentially imagine use cases for it, but reading the docs I did not see this difference discussed and wanted to check.
Thanks for your work on Signals, by the way – I came across them via Ryan Carniato and it seems like a great library!