feat(axum): add interaction registry alias

Add an interactions()/on() registration path and move canonical examples off explicit register_handle naming while keeping low-level registry types available underneath.

req: axum_integration/003

req: ceremony/001

req: dx/003

req: examples/003
This commit is contained in:
slhx agent
2026-06-02 00:24:32 +02:00
parent f388fa7d91
commit df4b4cc649
7 changed files with 41 additions and 25 deletions
+15
View File
@@ -266,6 +266,10 @@ pub const fn handlers(fingerprint: BuildFingerprint) -> HandlerRegistry {
HandlerRegistry::new(fingerprint)
}
pub const fn interactions(fingerprint: BuildFingerprint) -> HandlerRegistry {
HandlerRegistry::new(fingerprint)
}
impl InteractionRequest {
pub fn dispatch(
self,
@@ -320,6 +324,17 @@ impl HandlerRegistry {
self.register(handle.id().id, handler)
}
pub fn on<I, E>(
self,
handle: Handle<I>,
handler: impl Fn(InteractionForm) -> E + Send + Sync + 'static,
) -> Self
where
E: IntoEffect,
{
self.register_handle(handle, handler)
}
pub fn dispatch(&self, form: InteractionForm) -> Result<EffectResponse, DispatchRejection> {
let handle_id = form.handle_id;
let Some(handler) = self.handlers.get(&handle_id) else {
+2 -2
View File
@@ -2,7 +2,7 @@ use axum::http::{header, HeaderMap};
use axum::response::IntoResponse;
use scraper::{Html, Selector};
use slhx_axum::{
handlers, runtime_js, DispatchRejection, EffectResponse, HandlerRegistry, InteractionForm,
interactions, runtime_js, DispatchRejection, EffectResponse, HandlerRegistry, InteractionForm,
InteractionFormRejection, InteractionRequest, PageMode, PageRequest, PageResponse,
SLHX_CONTENT_TYPE, SLHX_FINGERPRINT_HEADER, SLHX_PARTIAL_HEADER, SLHX_RUNTIME_CONTENT_TYPE,
SLHX_TITLE_HEADER,
@@ -148,7 +148,7 @@ fn interaction_request_dispatches_with_concise_handlers_helper() {
Vec::new(),
));
let response = request
.dispatch(handlers(BuildFingerprint(4)).register_handle(Handle::<()>::new(7), |_| {
.dispatch(interactions(BuildFingerprint(4)).on(Handle::<()>::new(7), |_| {
Slot::<String>::new(3).text("ok")
}))
.unwrap();