refactor(v0): render keyed row with hemplate
Move the v0 keyed todo row effect payload from Rust format! HTML into a hemplate partial and require the generated slot append to carry an HTML payload. req: html_safety/002 req: view/001
This commit is contained in:
+19
-3
@@ -4,7 +4,8 @@ pub mod ui {}
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::ui;
|
use super::ui;
|
||||||
use slhx::{push, Effect, IntoEffect, NavigateMode};
|
use hemplate::Hemplate;
|
||||||
|
use slhx::{push, Effect, IntoEffect, NavigateMode, Payload, SafeHtml};
|
||||||
use slhx_test::inspect;
|
use slhx_test::inspect;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -29,6 +30,12 @@ mod tests {
|
|||||||
password: String,
|
password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Hemplate)]
|
||||||
|
#[hemplate = "partials"]
|
||||||
|
struct TodoRow {
|
||||||
|
title: String,
|
||||||
|
}
|
||||||
|
|
||||||
// req: examples/001 req: ceremony/001 req: build/001 req: build/005 req: codegen/002
|
// req: examples/001 req: ceremony/001 req: build/001 req: build/005 req: codegen/002
|
||||||
#[test]
|
#[test]
|
||||||
fn counter_updates_a_generated_slot() {
|
fn counter_updates_a_generated_slot() {
|
||||||
@@ -47,13 +54,22 @@ mod tests {
|
|||||||
fn todos_append_keyed_rows_from_form_input() {
|
fn todos_append_keyed_rows_from_form_input() {
|
||||||
fn add_todo(input: TodoInput) -> impl IntoEffect {
|
fn add_todo(input: TodoInput) -> impl IntoEffect {
|
||||||
let todo = Todo { id: 7, title: input.title };
|
let todo = Todo { id: 7, title: input.title };
|
||||||
ui::slots::todo_row.append(todo.id.to_string(), format!("<li>{}</li>", todo.title))
|
ui::slots::todo_row.append_html(todo.id.to_string(), render_todo_row(&todo))
|
||||||
}
|
}
|
||||||
|
|
||||||
let effect = inspect(add_todo(TodoInput { title: "Ship v0".into() }));
|
let effect = inspect(add_todo(TodoInput { title: "Ship v0".into() }));
|
||||||
|
|
||||||
assert!(effect.has_resource(ui::slots::todo_row.id()));
|
assert!(effect.has_resource(ui::slots::todo_row.id()));
|
||||||
assert!(matches!(effect.ops(), [Effect::Insert { key, .. }] if key == "7"));
|
assert!(matches!(effect.ops(), [Effect::Insert { key, payload, .. }] if key == "7" && matches!(payload, Payload::Html(_))));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_todo_row(todo: &Todo) -> SafeHtml {
|
||||||
|
// req: html_safety/002 req: view/001
|
||||||
|
SafeHtml::trusted(
|
||||||
|
TodoRow { title: todo.title.clone() }
|
||||||
|
.render()
|
||||||
|
.expect("v0 todo row renders"),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// req: examples/001 req: progressive_disclosure/001 req: build/001 req: build/005 req: codegen/004
|
// req: examples/001 req: progressive_disclosure/001 req: build/001 req: build/005 req: codegen/004
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<li>{+ self.title +}</li>
|
||||||
Reference in New Issue
Block a user