lightspeed/form_compat
LiveView-style form change/submit compatibility semantics.
Types
Client-side rate limit mode for one input.
pub type ChangeMode {
Immediate
Debounce(wait_ms: Int)
DebounceBlur
Throttle(window_ms: Int)
}
Constructors
-
Immediate -
Debounce(wait_ms: Int) -
DebounceBlur -
Throttle(window_ms: Int)
Deterministic dispatch decision.
pub type Dispatch {
DispatchChange(input: String, payload: form.FormData)
DispatchSubmit(payload: form.FormData)
Queued(input: String)
Suppressed(input: String, reason: String)
NoDispatch
}
Constructors
-
DispatchChange(input: String, payload: form.FormData) -
DispatchSubmit(payload: form.FormData) -
Queued(input: String) -
Suppressed(input: String, reason: String) -
NoDispatch
Input registration used by the form compatibility runtime.
pub type InputConfig {
InputConfig(name: String, mode: ChangeMode)
}
Constructors
-
InputConfig(name: String, mode: ChangeMode)
Runtime
opaqueForm compatibility runtime with one state record per registered input.
pub opaque type Runtime
Values
pub fn blur(
runtime: Runtime,
input: String,
at_ms: Int,
) -> #(Runtime, Dispatch)
Handle one blur event used by phx-debounce="blur".
pub fn change(
runtime: Runtime,
input: String,
payload: String,
at_ms: Int,
) -> #(Runtime, Dispatch)
Handle one phx-change-style event.
Semantics:
- debounce stores pending payload
- debounce blur stores pending payload until blur
- throttle emits immediately then suppresses inside window
- change for one input resets timers for all other inputs
pub fn dispatch_label(dispatch: Dispatch) -> String
Stable dispatch label for tests and logs.
pub fn has_pending(runtime: Runtime, input: String) -> Bool
Return pending status for one input.
pub fn mode(
runtime: Runtime,
input: String,
) -> option.Option(ChangeMode)
Return the current mode for one input.