home/ atoms/ hydra-thunk-for-reactivity

Hydra reactive values must be wrapped in () => thunks; bare expressions are evaluated once at boot

A common Hydra reactivity bug: passing an expression like 0.6 + a.fft[0]*2.5 directly as a Hydra argument evaluates the expression at the moment the code runs (once, at boot) and passes the resulting constant number. The value is then frozen regardless of what a.fft[0] subsequently does. To make the value reactive, it must be wrapped in an arrow function thunk: () => 0.6 + a.fft[0]*2.5. Hydra calls the thunk every frame, reading the current FFT value each time.

Examples

osc(10, 0.1, 0.6 + a.fft[0]*2.5) — frozen at boot value. Fix: osc(10, 0.1, () => 0.6 + a.fft[0]*2.5).

Assessment

Predict what value a.fft[0]*2.5 evaluates to at boot when the rig just loaded, and explain why wrapping it in () => fixes reactivity.

“`() =>` vs constant** (reactivity dead) | `osc(10,0.1, 0.6 + a.fft[0]*2.5)` — bare expression, no thunk | **No throw**; value frozen at boot, no reaction”
context/ · L5-debug/hydra.md · chunk 1