Fix <For/> to work with new format for children

This commit is contained in:
Greg Johnston 2022-09-17 17:08:52 -04:00
parent 5eb2364b2c
commit 91cfef3c80
1 changed files with 4 additions and 6 deletions

View File

@ -9,18 +9,17 @@ use crate::map::map_keyed;
/// Properties for the [For](crate::For) component.
#[derive(Props)]
pub struct ForProps<E, T, G, H, I, K>
pub struct ForProps<E, T, G, I, K>
where
E: Fn() -> Vec<T>,
G: Fn(Scope, &T) -> Element,
H: Fn() -> G,
I: Fn(&T) -> K,
K: Eq + Hash,
T: Eq + Clone + 'static,
{
pub each: E,
pub key: I,
pub children: H,
pub children: Box<dyn Fn() -> Vec<G>>,
}
/// Iterates over children and displays them, keyed by `PartialEq`. If you want to provide your
@ -29,16 +28,15 @@ where
/// This is much more efficient than naively iterating over nodes with `.iter().map(|n| view! { ... })...`,
/// as it avoids re-creating DOM nodes that are not being changed.
#[allow(non_snake_case)]
pub fn For<E, T, G, H, I, K>(cx: Scope, props: ForProps<E, T, G, H, I, K>) -> Memo<Vec<Element>>
pub fn For<E, T, G, I, K>(cx: Scope, props: ForProps<E, T, G, I, K>) -> Memo<Vec<Element>>
//-> impl FnMut() -> Vec<Element>
where
E: Fn() -> Vec<T> + 'static,
G: Fn(Scope, &T) -> Element + 'static,
H: Fn() -> G,
I: Fn(&T) -> K + 'static,
K: Eq + Hash,
T: Eq + Clone + Debug + 'static,
{
let map_fn = (props.children)();
let map_fn = (props.children)().swap_remove(0);
map_keyed(cx, props.each, map_fn, props.key)
}