refactor(v0): shorten generated resource paths
Import component-scoped generated modules at the example boundary so handlers and tests read as local slots/forms/handles without hiding ownership or adding framework machinery. req: component/003 req: dx/006
This commit is contained in:
+27
-20
@@ -7,6 +7,13 @@ use hemplate::Hemplate;
|
||||
use slhx::{push, IntoEffect, RenderSlotExt, SafeHtml};
|
||||
use slhx_axum::{runtime_js, sse, EffectResponse, HandlerRegistry, InteractionForm, PageRequest};
|
||||
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 std::collections::BTreeMap;
|
||||
use std::convert::Infallible;
|
||||
use std::net::SocketAddr;
|
||||
@@ -101,13 +108,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 = ui::notifications::slots::notifications.text("Server event #1");
|
||||
let effect = notification_slots::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 = ui::notifications::slots::notifications.text(format!("Server event #{count}"));
|
||||
let effect = notification_slots::notifications.text(format!("Server event #{count}"));
|
||||
Some((Ok::<_, Infallible>(effect.into_batch(ui::BUILD_FINGERPRINT)), count + 1))
|
||||
})
|
||||
.boxed();
|
||||
@@ -116,16 +123,16 @@ async fn events(Query(params): Query<BTreeMap<String, String>>) -> impl IntoResp
|
||||
|
||||
fn registry(state: Arc<ExampleState>) -> HandlerRegistry {
|
||||
HandlerRegistry::new(ui::BUILD_FINGERPRINT)
|
||||
.register_handle(ui::counter::handles::increment, {
|
||||
.register_handle(counter_handles::increment, {
|
||||
let state = state.clone();
|
||||
move |_| {
|
||||
// req: examples/001
|
||||
let mut counter = state.counter.lock().unwrap();
|
||||
*counter += 1;
|
||||
ui::counter::slots::counter_value.text(*counter)
|
||||
counter_slots::counter_value.text(*counter)
|
||||
}
|
||||
})
|
||||
.register_handle(ui::todos::handles::add_todo, {
|
||||
.register_handle(todo_handles::add_todo, {
|
||||
let state = state.clone();
|
||||
move |form| {
|
||||
// req: examples/001
|
||||
@@ -136,37 +143,37 @@ fn registry(state: Arc<ExampleState>) -> HandlerRegistry {
|
||||
todos.push(Todo { id, title: title.into() });
|
||||
}
|
||||
(
|
||||
ui::todos::slots::todo_list.render(&todos_view(&todos)),
|
||||
ui::todos::forms::new_todo.clear("title"),
|
||||
todo_slots::todo_list.render(&todos_view(&todos)),
|
||||
todo_forms::new_todo.clear("title"),
|
||||
)
|
||||
}
|
||||
})
|
||||
.register_handle(ui::wizard::handles::next_step, {
|
||||
.register_handle(wizard_handles::next_step, {
|
||||
let state = state.clone();
|
||||
move |_| {
|
||||
// req: examples/001
|
||||
let mut step = state.wizard_step.lock().unwrap();
|
||||
*step += 1;
|
||||
ui::wizard::slots::wizard_step.text(format!("Step {}", *step + 1))
|
||||
wizard_slots::wizard_step.text(format!("Step {}", *step + 1))
|
||||
}
|
||||
})
|
||||
.register_handle(ui::auth::handles::login, |form| {
|
||||
.register_handle(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());
|
||||
ui::auth::slots::login_status.text(if ok {
|
||||
auth_slots::login_status.text(if ok {
|
||||
"Signed in as demo@example.com"
|
||||
} else {
|
||||
"Try demo@example.com with any password"
|
||||
})
|
||||
})
|
||||
.register_handle(ui::page_swap::handles::load_docs, |_| {
|
||||
.register_handle(page_handles::load_docs, |_| {
|
||||
// req: page_swap/002, req: examples/001
|
||||
(
|
||||
ui::page_swap::slots::content.render(&DocsContent {
|
||||
page_slots::content.render(&DocsContent {
|
||||
message: "This content came from an EffectBatch.",
|
||||
}),
|
||||
ui::page_swap::slots::title.text("Docs"),
|
||||
page_slots::title.text("Docs"),
|
||||
push("/docs"),
|
||||
)
|
||||
})
|
||||
@@ -174,12 +181,12 @@ fn registry(state: Arc<ExampleState>) -> HandlerRegistry {
|
||||
|
||||
fn all_examples() -> String {
|
||||
[
|
||||
ui::counter::lower_html(include_str!("../templates/counter.heml")),
|
||||
ui::todos::lower_html(include_str!("../templates/todos.heml")),
|
||||
ui::wizard::lower_html(include_str!("../templates/wizard.heml")),
|
||||
ui::auth::lower_html(include_str!("../templates/auth.heml")),
|
||||
counter::lower_html(include_str!("../templates/counter.heml")),
|
||||
todos::lower_html(include_str!("../templates/todos.heml")),
|
||||
wizard::lower_html(include_str!("../templates/wizard.heml")),
|
||||
auth::lower_html(include_str!("../templates/auth.heml")),
|
||||
render_page_swap("Welcome", "Welcome"),
|
||||
ui::notifications::lower_html(include_str!("../templates/notifications.heml")),
|
||||
notifications::lower_html(include_str!("../templates/notifications.heml")),
|
||||
]
|
||||
.join("\n")
|
||||
}
|
||||
@@ -208,7 +215,7 @@ fn todos_view(todos: &[Todo]) -> TodoItems {
|
||||
|
||||
fn render_page_swap(title: &'static str, message: &'static str) -> String {
|
||||
// req: html_safety/002 req: view/001 req: component/003
|
||||
ui::page_swap::render_html(&PageSwap {
|
||||
page_swap::render_html(&PageSwap {
|
||||
content: render_docs_content(message),
|
||||
title,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user