DynamicForm.Lifecycle.Debounce (DynamicForm v1.0.0)

Copy Markdown View Source

Timer and token mechanics for debouncing DynamicForm.Renderer.LiveComponent's change pass (change_debounce_in_ms).

LiveComponents have no handle_info/2, so a scheduled run arrives back through update/2 as a :run_change action carrying a token. Canceling a timer can't recall a message already sitting in the process mailbox, so the token is what makes a superseded run a no-op when it arrives: cancel/1 bumps it, and current?/2 compares.

Internal module — not part of the public API.

Summary

Functions

Drops any pending debounced run and issues the token the next one will carry. Canceling the timer is the fast path; the token is what makes a run already in the mailbox a no-op when it arrives.

Whether a delivered run's token matches the one currently issued — a mismatch means the run was superseded and must be dropped.

The debounce interval for the change pass, or nil when it runs inline: nothing to defer, no interval, or an interval of zero.

Debounces the change pass: drops the run this change supersedes and schedules a fresh one.

Functions

cancel(socket)

Drops any pending debounced run and issues the token the next one will carry. Canceling the timer is the fast path; the token is what makes a run already in the mailbox a no-op when it arrives.

current?(socket, token)

Whether a delivered run's token matches the one currently issued — a mismatch means the run was superseded and must be dropped.

interval(socket)

The debounce interval for the change pass, or nil when it runs inline: nothing to defer, no interval, or an interval of zero.

schedule(socket, interval)

Debounces the change pass: drops the run this change supersedes and schedules a fresh one.