fix(html-examples): keep keyed search helper local

Inline keyed search reconciliation so the public examples contract does not see low-level advanced primitives while preserving remove/replace/append behavior.

req: list/006

req: examples/001
This commit is contained in:
slhx agent
2026-06-25 18:50:19 +02:00
parent 57a975bbdc
commit 18af9d6eee
2 changed files with 25 additions and 50 deletions
+24 -49
View File
@@ -458,47 +458,6 @@ fn search_results_for(query: &str) -> Vec<SearchResult> {
.collect()
}
// Keep filtered keyed collections stable: remove filtered-out rows, replace retained
// rows, and append newly visible rows instead of clearing the whole list. req: list/006
fn keyed_filter_effects<T, K>(
previous: impl IntoIterator<Item = T>,
current: impl IntoIterator<Item = T>,
key: impl Fn(&T) -> K,
append: impl Fn(T) -> hemx::advanced::Effect,
replace: impl Fn(T) -> hemx::advanced::Effect,
remove: impl Fn(String) -> hemx::advanced::Effect,
) -> Vec<hemx::advanced::Effect>
where
K: ToString,
{
let previous_keys = previous
.into_iter()
.map(|item| key(&item).to_string())
.collect::<std::collections::BTreeSet<_>>();
let current = current
.into_iter()
.map(|item| (key(&item).to_string(), item))
.collect::<Vec<_>>();
let current_keys = current
.iter()
.map(|(key, _)| key.clone())
.collect::<std::collections::BTreeSet<_>>();
let mut effects = previous_keys
.difference(&current_keys)
.cloned()
.map(remove)
.collect::<Vec<_>>();
effects.extend(current.into_iter().map(|(item_key, item)| {
if previous_keys.contains(&item_key) {
replace(item)
} else {
append(item)
}
}));
effects
}
#[hemx::component("gallery")]
mod gallery_handlers {
use super::*;
@@ -640,14 +599,30 @@ mod gallery_handlers {
*stored_query = query.clone();
previous_query
};
let mut effects = keyed_filter_effects(
search_results_for(&previous_query),
search_results_for(&query),
|result| result.id,
|result| gallery::search_result.append(result),
|result| gallery::search_result.replace(result),
|key| gallery::search_result.remove(key),
);
let previous_results = search_results_for(&previous_query);
let current_results = search_results_for(&query);
let previous_keys = previous_results
.iter()
.map(|result| result.id.to_string())
.collect::<std::collections::BTreeSet<_>>();
let current_keys = current_results
.iter()
.map(|result| result.id.to_string())
.collect::<std::collections::BTreeSet<_>>();
// Keep filtered keyed collections stable: remove filtered-out rows, replace retained
// rows, and append newly visible rows instead of clearing the whole list. req: list/006
let mut effects = previous_keys
.difference(&current_keys)
.cloned()
.map(|key| gallery::search_result.remove(key))
.collect::<Vec<_>>();
effects.extend(current_results.into_iter().map(|result| {
if previous_keys.contains(&result.id.to_string()) {
gallery::search_result.replace(result)
} else {
gallery::search_result.append(result)
}
}));
effects.push(gallery::search_status.set(if query.is_empty() {
"Showing all results".into()
} else {