computed() is one of Vue's most powerful primitives. It creates a lazy, cached derived value that automatically re-evaluates when its reactive dependencies change.
const state = reactive({ n: 5 });
const doubled = computed(() => state.n * 2);
doubled.value; // → 10 (getter runs once)
doubled.value; // → 10 (cached — getter does NOT run again)
state.n = 20;
doubled.value; // → 40 (cache invalidated → getter re-runs)
doubled.value; // → 40 (cached again)| Property | Meaning |
|---|---|
| Lazy | Getter is NOT called until .value is first accessed |
| Cached | Subsequent reads reuse the result — getter runs at most once per dirty cycle |
| Reactive | When a tracked dependency changes, the cache is invalidated (dirty) |
Implement computed(getter), reactive(obj), effect(fn), and _reset().
The solve(op, ...args) harness is provided — do not modify it.
Sample tests