feat(build): generate slot target objects

Add generated targets::<slot> wrapper objects so partial swaps read as target.put/append/replace while preserving existing lower-aware commands and IntoEffect wiring.

req: dx/006

req: codegen/001

req: codegen/002

req: component/003
This commit is contained in:
slhx agent
2026-06-02 07:21:23 +02:00
parent 20d1159e39
commit a138f92b33
11 changed files with 84 additions and 37 deletions
+6 -6
View File
@@ -90,9 +90,9 @@ FormSurface {
slhx reads this from hemplate Surface facts and generates scoped typed resources:
```rust
use ui::board::{forms, slots};
use ui::board::{forms, targets};
ui::board::replace(slots::card, card.id, &CardView::from(card));
targets::card.replace(card.id, &CardView::from(card));
forms::create_card.clear("title");
ui::render(&BoardView::from(board));
```
@@ -135,7 +135,7 @@ pub fn create_card(
app.board.update(|board| board.insert_card(form.column, card.clone()));
(
ui::board::append(slots::card, card.id, &CardView::from(card)),
targets::card.append(card.id, &CardView::from(card)),
forms::create_card.clear("title"),
// slhx-sync: queue atomic board state diff for sync
SyncEffect::send_patch(atoms::board, Patch::insert_card(form.column, card)),
@@ -233,14 +233,14 @@ pub fn apply_board_patch(
Effect::broadcast(
Channel::Board(app.board.id()),
Effect::batch(changed_cards.into_iter().map(|c|
ui::board::replace(slots::card, c.id, &CardView::from(c))
targets::card.replace(c.id, &CardView::from(c))
)),
),
)),
PatchResult::Conflict { canonical_board } => Effect::batch((
Effect::set(atoms::BOARD, canonical_board.clone()),
ui::put(slots::board, &BoardView::from(canonical_board)),
targets::board.put(&BoardView::from(canonical_board)),
)),
}
}
@@ -255,7 +255,7 @@ Server-authoritative on conflict. No Redux sagas. No React Query cache fades.
```rust
#[slhx_sync::presence]
pub fn user_joined(user: UserPresence) -> impl IntoEffect {
ui::board::append(slots::presence_user, user.id, &PresenceBadge::from(user))
targets::presence_user.append(user.id, &PresenceBadge::from(user))
}
```
+1 -1
View File
@@ -11,7 +11,7 @@ The example is a server-first Kanban board with:
- add-card form
- move-left / move-right card controls
- delete-card controls
- generated resource commands for checked slot updates
- generated target objects for checked slot updates
- tuple-composed `IntoEffect` / `application/slhx` responses
- SSE presence updates
+1 -1
View File
@@ -27,7 +27,7 @@ mod tests {
#[test]
fn kanban_board_updates_generated_slot() {
fn render_board() -> impl IntoEffect {
super::ui::put(board::slots::board, &empty_board())
board::targets::board.put(&empty_board())
}
let effect = inspect(render_board());
+4 -4
View File
@@ -10,7 +10,7 @@ use slhx_axum::{
InteractionRequest, PageRequest,
};
use slhx_kanban_example::ui::{self, board as board_ui};
use slhx_kanban_example::ui::board::{forms, handles, slots};
use slhx_kanban_example::ui::board::{forms, handles, slots, targets};
use slhx_kanban_example::ui::board_card::handles as card_handles;
use std::collections::BTreeMap;
use std::convert::Infallible;
@@ -138,13 +138,13 @@ async fn interact(
// 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::put(slots::presence, &Presence { count: 1 });
let effect = targets::presence.put(&Presence { count: 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(4)).await;
let effect = ui::put(slots::presence, &Presence { count });
let effect = targets::presence.put(&Presence { count });
Some((Ok::<_, Infallible>(effect.into_batch(ui::BUILD_FINGERPRINT)), count + 1))
})
.boxed();
@@ -206,7 +206,7 @@ fn registry(state: Arc<AppState>) -> impl DispatchRegistry {
fn board_effects(board: &BoardState, notice: &'static str) -> impl IntoEffect {
(
ui::put(slots::board, &board_view(board)),
targets::board.put(&board_view(board)),
slots::notice.text(notice),
forms::create_card.clear("title"),
)
+2 -2
View File
@@ -3,7 +3,7 @@ pub mod ui {}
#[cfg(test)]
mod tests {
use super::ui::control_center::{forms, handles, slots};
use super::ui::control_center::{forms, handles, slots, targets};
use super::ui::issue_card::handles as card_handles;
use super::ui::issue_lane::events as lane_events;
use hemplate::Hemplate;
@@ -30,7 +30,7 @@ mod tests {
fn techdemo_uses_generated_slots_for_multi_target_updates() {
fn update() -> impl IntoEffect {
(
super::ui::put(slots::hero_metrics, &FastMetric { label: "fast" }),
targets::hero_metrics.put(&FastMetric { label: "fast" }),
slots::notice.text("typed"),
)
}
+9 -9
View File
@@ -10,7 +10,7 @@ use slhx_axum::{
InteractionRequest, PageRequest,
};
use slhx_techdemo::ui;
use slhx_techdemo::ui::control_center::{classes, forms, handles, slots};
use slhx_techdemo::ui::control_center::{classes, forms, handles, slots, targets};
use slhx_techdemo::ui::issue_card::handles as card_handles;
use slhx_techdemo::ui::issue_lane::handles as lane_handles;
use std::collections::{BTreeMap, VecDeque};
@@ -269,13 +269,13 @@ async fn interact(
// 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::put(slots::live_feed, &LiveFeed { tick: 1 });
let effect = targets::live_feed.put(&LiveFeed { tick: 1 });
return sse(stream::iter([Ok::<_, Infallible>(effect.into_batch(ui::BUILD_FINGERPRINT))]).boxed());
}
let batches = stream::unfold(1_u64, |tick| async move {
tokio::time::sleep(Duration::from_secs(4)).await;
let effect = ui::put(slots::live_feed, &LiveFeed { tick });
let effect = targets::live_feed.put(&LiveFeed { tick });
Some((Ok::<_, Infallible>(effect.into_batch(ui::BUILD_FINGERPRINT)), tick + 1))
})
.boxed();
@@ -384,10 +384,10 @@ fn registry(shared: Arc<Shared>) -> impl DispatchRegistry {
let mut demo = shared.demo.lock().unwrap();
demo.log("Simulated push event produced the same generated update shape");
(
ui::put(slots::live_feed, &LiveFeed {
targets::live_feed.put(&LiveFeed {
tick: demo.activity.len() as u64,
}),
ui::put(slots::activity, &activity_view(&demo)),
targets::activity.put(&activity_view(&demo)),
slots::notice.text("Push simulated · no client app code"),
slhx::event("slhx:island-orbit", island_snapshot(&demo)),
)
@@ -414,10 +414,10 @@ fn update_work(demo: &mut DemoState, id: Option<u64>, update: impl FnOnce(&mut W
fn demo_effects(demo: &DemoState, notice: &'static str) -> impl IntoEffect {
(
ui::put(slots::hero_metrics, &hero_view(demo)),
ui::put(slots::board, &board_view(demo)),
ui::put(slots::activity, &activity_view(demo)),
ui::put(slots::inspector, &inspector_view(demo)),
targets::hero_metrics.put(&hero_view(demo)),
targets::board.put(&board_view(demo)),
targets::activity.put(&activity_view(demo)),
targets::inspector.put(&inspector_view(demo)),
slots::notice.text(notice),
forms::launch_work.clear("title"),
slhx::event("slhx:island-orbit", island_snapshot(demo)),
+1 -1
View File
@@ -8,7 +8,7 @@ cargo run -p slhx-v0-examples
Open <http://127.0.0.1:3000>.
The page includes working examples for generated-resource, server-first UI commands:
The page includes working examples for generated target objects and server-first UI commands:
- counter updates
- todo form submission
+2 -6
View File
@@ -49,7 +49,7 @@ mod tests {
#[test]
fn counter_updates_a_generated_slot() {
fn increment(count: u64) -> impl IntoEffect {
counter::slots::counter_value.text(count + 1)
counter::targets::counter_value.text(count + 1)
}
let effect = inspect(increment(1));
@@ -77,11 +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 };
todos::append(
todos::slots::todo_row,
todo.id.to_string(),
&TodoRow { title: todo.title },
)
todos::targets::todo_row.append(todo.id.to_string(), &TodoRow { title: todo.title })
}
let effect = inspect(add_todo(TodoInput { title: "Ship v0".into() }));