Understand Vue reactivity: 18 levels predicting fire counts for ref, reactive, computed, watch, toRefs, readonly, deep watch, effectScope and Pinia stores.
ref(0) holds one value; read and write it through .value. watch(source, (next) => …) records its source's first value without sounding, then sounds every time the value changes. Writing a value equal to the old one tells nobody.
reactive({ … }) returns a Proxy of its object. Every property a watcher's getter reads is recorded as a source, properties of objects inside it included. A write to another property does not tell that watcher.
computed(() => …) is a lazy, cached derived value: it computes when read, and computes again only if read after its sources changed. A default watcher (flush: 'pre') does not run when a post is written: it is queued, and Vue runs the queue once after the writing code has finished.
A reactive() Proxy records only reads that go through it. const { name } = object reads once, right then, and keeps the text in a plain variable; that variable does not know when object.name changes.
shallowReactive() makes a Proxy for the first-level properties only. Objects inside come back as they are, so changes inside them tell no watcher. It is for large objects that are only ever replaced whole.
toRef(object, 'key') makes a ref connected to one property of a reactive object; toRefs(object) does it for every property at once. Such a ref keeps no value of its own: it reads and writes through its source's Proxy, so it is safe to destructure.