refactor(examples): use targets across v0 handlers

Move remaining v0 example updates from raw slot constants/free functions to generated target objects for the partial/swap happy path.

req: dx/006

req: examples/003
This commit is contained in:
slhx agent
2026-06-02 07:44:41 +02:00
parent 339ca769fb
commit eb6086616c
+14 -14
View File
@@ -10,12 +10,12 @@ use slhx_axum::{
};
use slhx_v0_examples::ui;
use slhx_v0_examples::ui::{auth, counter, notifications, page_swap, todos, wizard};
use slhx_v0_examples::ui::auth::{handles as auth_handles, slots as auth_slots};
use slhx_v0_examples::ui::counter::{handles as counter_handles, slots as counter_slots};
use slhx_v0_examples::ui::notifications::slots as notification_slots;
use slhx_v0_examples::ui::page_swap::{handles as page_handles, slots as page_slots};
use slhx_v0_examples::ui::todos::{forms as todo_forms, handles as todo_handles, slots as todo_slots};
use slhx_v0_examples::ui::wizard::{handles as wizard_handles, slots as wizard_slots};
use slhx_v0_examples::ui::auth::{handles as auth_handles, targets as auth_targets};
use slhx_v0_examples::ui::counter::{handles as counter_handles, targets as counter_targets};
use slhx_v0_examples::ui::notifications::targets as notification_targets;
use slhx_v0_examples::ui::page_swap::{handles as page_handles, targets as page_targets};
use slhx_v0_examples::ui::todos::{forms as todo_forms, handles as todo_handles, targets as todo_targets};
use slhx_v0_examples::ui::wizard::{handles as wizard_handles, targets as wizard_targets};
use std::collections::BTreeMap;
use std::convert::Infallible;
use std::net::SocketAddr;
@@ -110,13 +110,13 @@ async fn runtime() -> impl IntoResponse {
// req: push/001, req: push/003, req: examples/001
async fn events(Query(params): Query<BTreeMap<String, String>>) -> impl IntoResponse {
if params.contains_key("once") {
let effect = notification_slots::notifications.text("Server event #1");
let effect = notification_targets::notifications.text("Server event #1");
return sse(stream::iter([Ok::<_, Infallible>(effect.into_batch(ui::BUILD_FINGERPRINT))]).boxed());
}
let batches = stream::unfold(1_u64, |count| async move {
tokio::time::sleep(Duration::from_secs(3)).await;
let effect = notification_slots::notifications.text(format!("Server event #{count}"));
let effect = notification_targets::notifications.text(format!("Server event #{count}"));
Some((Ok::<_, Infallible>(effect.into_batch(ui::BUILD_FINGERPRINT)), count + 1))
})
.boxed();
@@ -131,7 +131,7 @@ fn registry(state: Arc<ExampleState>) -> impl DispatchRegistry {
// req: examples/001
let mut counter = state.counter.lock().unwrap();
*counter += 1;
counter_slots::counter_value.text(*counter)
counter_targets::counter_value.text(*counter)
}
})
.on(todo_handles::add_todo, {
@@ -145,7 +145,7 @@ fn registry(state: Arc<ExampleState>) -> impl DispatchRegistry {
todos.push(Todo { id, title: title.into() });
}
(
todos::put(todo_slots::todo_list, &todos_view(&todos)),
todo_targets::todo_list.put(&todos_view(&todos)),
todo_forms::new_todo.clear("title"),
)
}
@@ -156,14 +156,14 @@ fn registry(state: Arc<ExampleState>) -> impl DispatchRegistry {
// req: examples/001
let mut step = state.wizard_step.lock().unwrap();
*step += 1;
wizard_slots::wizard_step.text(format!("Step {}", *step + 1))
wizard_targets::wizard_step.text(format!("Step {}", *step + 1))
}
})
.on(auth_handles::login, |form| {
// req: examples/001
let ok = form.value("email") == Some("demo@example.com")
&& form.value("password").is_some_and(|password| !password.is_empty());
auth_slots::login_status.text(if ok {
auth_targets::login_status.text(if ok {
"Signed in as demo@example.com"
} else {
"Try demo@example.com with any password"
@@ -172,10 +172,10 @@ fn registry(state: Arc<ExampleState>) -> impl DispatchRegistry {
.on(page_handles::load_docs, |_| {
// req: page_swap/002, req: examples/001
(
page_swap::put(page_slots::content, &DocsContent {
page_targets::content.put(&DocsContent {
message: "This content came from a generated update response.",
}),
page_slots::title.text("Docs"),
page_targets::title.text("Docs"),
push("/docs"),
)
})