Add app
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// Reactive "telemetry" helper: returns an object whose .value drifts around a
|
||||
// base value on an interval, so static dummy data feels like a live readout.
|
||||
// Call inside a component's script (it registers an $effect for cleanup).
|
||||
|
||||
export function useJitter(base, { amp = 1, decimals = 0, every = 2000 } = {}) {
|
||||
let value = $state(base)
|
||||
|
||||
$effect(() => {
|
||||
const id = setInterval(() => {
|
||||
const delta = (Math.random() - 0.5) * 2 * amp
|
||||
value = Number((base + delta).toFixed(decimals))
|
||||
}, every)
|
||||
return () => clearInterval(id)
|
||||
})
|
||||
|
||||
return { get value() { return value } }
|
||||
}
|
||||
Reference in New Issue
Block a user