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:
slhx agent
2026-06-01 22:44:19 +02:00
parent e9c717844d
commit 749ecb1778
2 changed files with 48 additions and 41 deletions
+21 -21
View File
@@ -3,7 +3,7 @@ pub mod ui {}
#[cfg(test)]
mod tests {
use super::ui;
use super::ui::{auth, counter, notifications, page_swap, todos, wizard};
use hemplate::Hemplate;
use slhx::{push, Effect, IntoEffect, NavigateMode, Payload, RenderKeyedSlotExt, RenderSlotExt};
use slhx_test::inspect;
@@ -49,12 +49,12 @@ mod tests {
#[test]
fn counter_updates_a_generated_slot() {
fn increment(count: u64) -> impl IntoEffect {
ui::counter::slots::counter_value.text(count + 1)
counter::slots::counter_value.text(count + 1)
}
let effect = inspect(increment(1));
assert!(effect.has_slot(ui::counter::slots::counter_value));
assert!(effect.has_slot(counter::slots::counter_value));
assert!(matches!(effect.ops(), [Effect::Put { .. }]));
}
@@ -63,12 +63,12 @@ mod tests {
fn form_handler_is_checked_against_hemplate_form() {
#[slhx::handler]
fn add_todo(_form: slhx::Form<TodoInput>) -> impl IntoEffect {
ui::todos::slots::todo_list.text("queued")
todos::slots::todo_list.text("queued")
}
let effect = inspect(add_todo(TodoInput::FORM));
assert!(effect.has_slot(ui::todos::slots::todo_list));
assert!(effect.has_slot(todos::slots::todo_list));
assert!(matches!(effect.ops(), [Effect::Put { payload: Payload::Text(_), .. }]));
}
@@ -77,7 +77,7 @@ mod tests {
fn todos_append_keyed_rows_from_form_input() {
fn add_todo(input: TodoInput) -> impl IntoEffect {
let todo = Todo { id: 7, title: input.title };
ui::todos::slots::todo_row.append(
todos::slots::todo_row.append(
todo.id.to_string(),
&TodoRow { title: todo.title },
)
@@ -85,7 +85,7 @@ mod tests {
let effect = inspect(add_todo(TodoInput { title: "Ship v0".into() }));
assert!(effect.has_resource(ui::todos::slots::todo_row.id()));
assert!(effect.has_resource(todos::slots::todo_row.id()));
assert!(matches!(effect.ops(), [Effect::Insert { key, payload, .. }] if key == "7" && matches!(payload, Payload::Html(_))));
}
@@ -94,12 +94,12 @@ mod tests {
fn wizard_form_handler_is_checked_against_hemplate_form() {
#[slhx::handler]
fn next_step(_form: slhx::Form<WizardInput>) -> impl IntoEffect {
ui::wizard::slots::wizard_step.text("queued")
wizard::slots::wizard_step.text("queued")
}
let effect = inspect(next_step(WizardInput::FORM));
assert!(effect.has_slot(ui::wizard::slots::wizard_step));
assert!(effect.has_slot(wizard::slots::wizard_step));
assert!(matches!(effect.ops(), [Effect::Put { payload: Payload::Text(_), .. }]));
}
@@ -107,12 +107,12 @@ mod tests {
#[test]
fn wizard_form_swaps_the_current_step() {
fn next_step(input: WizardInput) -> impl IntoEffect {
ui::wizard::slots::wizard_step.text(format!("Step {}", input.step + 1))
wizard::slots::wizard_step.text(format!("Step {}", input.step + 1))
}
let effect = inspect(next_step(WizardInput { step: 1 }));
assert!(effect.has_slot(ui::wizard::slots::wizard_step));
assert!(effect.has_slot(wizard::slots::wizard_step));
assert!(matches!(effect.ops(), [Effect::Put { .. }]));
}
@@ -121,18 +121,18 @@ mod tests {
fn page_swap_updates_content_and_history() {
fn load_docs() -> impl IntoEffect {
(
ui::page_swap::slots::content.render(&DocsContent {
page_swap::slots::content.render(&DocsContent {
message: "This page was swapped.",
}),
ui::page_swap::slots::title.text("Docs"),
page_swap::slots::title.text("Docs"),
push("/docs"),
)
}
let effect = inspect(load_docs());
assert!(effect.has_slot(ui::page_swap::slots::content));
assert!(effect.has_slot(ui::page_swap::slots::title));
assert!(effect.has_slot(page_swap::slots::content));
assert!(effect.has_slot(page_swap::slots::title));
assert!(matches!(effect.ops().first(), Some(Effect::Put { payload: Payload::Html(_), .. })));
assert!(matches!(effect.ops().last(), Some(Effect::Navigate { url, mode: NavigateMode::Push, .. }) if url == "/docs"));
}
@@ -142,12 +142,12 @@ mod tests {
fn auth_form_handler_is_checked_against_hemplate_form() {
#[slhx::handler]
fn login(_form: slhx::Form<Credentials>) -> impl IntoEffect {
ui::auth::slots::login_status.text("queued")
auth::slots::login_status.text("queued")
}
let effect = inspect(login(Credentials::FORM));
assert!(effect.has_slot(ui::auth::slots::login_status));
assert!(effect.has_slot(auth::slots::login_status));
assert!(matches!(effect.ops(), [Effect::Put { payload: Payload::Text(_), .. }]));
}
@@ -161,12 +161,12 @@ mod tests {
"Try again"
};
ui::auth::slots::login_status.text(status)
auth::slots::login_status.text(status)
}
let effect = inspect(login(Credentials { email: "demo@example.com".into(), password: "secret".into() }));
assert!(effect.has_slot(ui::auth::slots::login_status));
assert!(effect.has_slot(auth::slots::login_status));
assert!(matches!(effect.ops(), [Effect::Put { .. }]));
}
@@ -174,12 +174,12 @@ mod tests {
#[test]
fn sse_notifications_update_a_generated_slot() {
fn notification(message: &str) -> impl IntoEffect {
ui::notifications::slots::notifications.text(message)
notifications::slots::notifications.text(message)
}
let effect = inspect(notification("Build finished"));
assert!(effect.has_slot(ui::notifications::slots::notifications));
assert!(effect.has_slot(notifications::slots::notifications));
assert!(matches!(effect.ops(), [Effect::Put { .. }]));
}
}