fix(core): type slot render payloads
Tighten typed Slot::render and KeyedSlot append/prepend/replace helpers so callers pass the generated slot payload type, keeping explicit html/text escape hatches for deliberate conversions. req: codegen/002 req: typed_id/001
This commit is contained in:
+16
-4
@@ -713,7 +713,10 @@ impl<T> Slot<T> {
|
|||||||
self.id
|
self.id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(self, value: impl ToString) -> Effect {
|
pub fn render(self, value: T) -> Effect
|
||||||
|
where
|
||||||
|
T: ToString,
|
||||||
|
{
|
||||||
self.text(value)
|
self.text(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -761,7 +764,10 @@ where
|
|||||||
self.id
|
self.id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append(self, key: K, value: impl ToString) -> Effect {
|
pub fn append(self, key: K, value: T) -> Effect
|
||||||
|
where
|
||||||
|
T: ToString,
|
||||||
|
{
|
||||||
Effect::Insert {
|
Effect::Insert {
|
||||||
target: ResourceRef::unscoped(self.id),
|
target: ResourceRef::unscoped(self.id),
|
||||||
key: key.to_string(),
|
key: key.to_string(),
|
||||||
@@ -769,7 +775,10 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prepend(self, key: K, value: impl ToString) -> Effect {
|
pub fn prepend(self, key: K, value: T) -> Effect
|
||||||
|
where
|
||||||
|
T: ToString,
|
||||||
|
{
|
||||||
Effect::Prepend {
|
Effect::Prepend {
|
||||||
target: ResourceRef::unscoped(self.id),
|
target: ResourceRef::unscoped(self.id),
|
||||||
key: key.to_string(),
|
key: key.to_string(),
|
||||||
@@ -777,7 +786,10 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn replace(self, key: K, value: impl ToString) -> Effect {
|
pub fn replace(self, key: K, value: T) -> Effect
|
||||||
|
where
|
||||||
|
T: ToString,
|
||||||
|
{
|
||||||
let key = key.to_string();
|
let key = key.to_string();
|
||||||
Effect::Put {
|
Effect::Put {
|
||||||
target: ResourceRef {
|
target: ResourceRef {
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ fn effect_batch_wire_round_trips() {
|
|||||||
let user = Atom::<String>::new(3);
|
let user = Atom::<String>::new(3);
|
||||||
|
|
||||||
let batch = (
|
let batch = (
|
||||||
count.text(2),
|
count.render(2),
|
||||||
todos.append(7, "Buy milk"),
|
todos.append(7, String::from("Buy milk")),
|
||||||
todos.replace(7, "Buy oat milk"),
|
todos.replace(7, String::from("Buy oat milk")),
|
||||||
user.set("Ada"),
|
user.set("Ada"),
|
||||||
navigate("/todos"),
|
navigate("/todos"),
|
||||||
event("toast", "Saved"),
|
event("toast", "Saved"),
|
||||||
@@ -31,7 +31,8 @@ fn effect_batch_wire_round_trips() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn keyed_slot_replace_uses_scoped_resource_ref() {
|
fn keyed_slot_replace_uses_scoped_resource_ref() {
|
||||||
let todos = KeyedSlot::<u64, String>::new(9);
|
let todos = KeyedSlot::<u64, String>::new(9);
|
||||||
let effect = todos.replace(12, "done");
|
// req: codegen/002
|
||||||
|
let effect = todos.replace(12, String::from("done"));
|
||||||
|
|
||||||
let Effect::Put { target, payload } = effect else {
|
let Effect::Put { target, payload } = effect else {
|
||||||
panic!("expected Put");
|
panic!("expected Put");
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ fn inspects_tuple_effects() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn finds_keyed_slot_targets() {
|
fn finds_keyed_slot_targets() {
|
||||||
let rows = KeyedSlot::<u32, String>::new(9);
|
let rows = KeyedSlot::<u32, String>::new(9);
|
||||||
let inspected = slhx_test::inspect(rows.append(7, "row"));
|
let inspected = slhx_test::inspect(rows.append(7, String::from("row")));
|
||||||
|
|
||||||
assert!(inspected.has_keyed_slot(rows));
|
assert!(inspected.has_keyed_slot(rows));
|
||||||
assert_eq!(inspected.ops().len(), 1);
|
assert_eq!(inspected.ops().len(), 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user