Batching
When updates run, and how to group them.
Updates run in a microtask
A signal write does not touch the DOM right away. Signy collects the changes and applies them in a microtask, so several writes in a row cause one update.
batch()
batch() groups writes explicitly. Readers run once, after
the function returns, and see the final values.
batch(() => {
this.firstName.value = 'Ada';
this.lastName.value = 'Lovelace';
});
flushAll()
flushAll() runs every pending notification, effect and DOM
update right away. Use it in tests after a write. See
Testing.
count.value = 2;
flushAll();
expect(root.textContent).toBe('2');
flushSync() only delivers signal notifications. It does not
run effects or DOM updates, so prefer flushAll().