Derived values
Display twice the count. Declare a computed store that depends on count, rather than keeping another writable field in sync.
Step 1 / 2
setup(self) {
const increment = action(() => { self.count.value++; });
const doubled = computed(() => self.count.value * 2);
return { increment, doubled };
}
The computation reads count; Core tracks that dependency.
countsource valuedoubledcount × 2count → doubled
Import computed from @virentia/ui. Its function reads count.value, which Core tracks as a dependency. Pass the resulting doubled store to view.
One click now updates two texts: the button's count and its doubled result. No handler needs to assign doubled manually.
Change the calculation to the square of the count. Only the model computation changes, not view.